blob: 5f1d1fac13682bb0d903f1f167d58f65d3128a67 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/**
2 * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org)
3 */
4package org.onosproject.xran.codecs.pdu;
5
slowr60d4d102017-08-16 18:33:58 -07006import com.fasterxml.jackson.annotation.JsonIgnore;
slowr13fa5b02017-08-08 16:32:31 -07007import org.onosproject.xran.codecs.api.CRNTI;
8import org.onosproject.xran.codecs.api.ECGI;
slowr60d4d102017-08-16 18:33:58 -07009import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
10import org.onosproject.xran.codecs.ber.BerLength;
11import org.onosproject.xran.codecs.ber.BerTag;
slowr13fa5b02017-08-08 16:32:31 -070012import java.io.IOException;
13import java.io.InputStream;
14import java.io.Serializable;
15
16
17public class SeNBAdd implements Serializable {
18
19 private static final long serialVersionUID = 1L;
20
21 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
22
slowr60d4d102017-08-16 18:33:58 -070023 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070024 public byte[] code = null;
25 private CRNTI crnti = null;
26 private ECGI mEcgi = null;
27 private ECGI sEcgi = null;
28
29 public SeNBAdd() {
30 }
31
32 public SeNBAdd(byte[] code) {
33 this.code = code;
34 }
35
36 public void setCrnti(CRNTI crnti) {
37 this.crnti = crnti;
38 }
39
40 public CRNTI getCrnti() {
41 return crnti;
42 }
43
44 public void setMEcgi(ECGI mEcgi) {
45 this.mEcgi = mEcgi;
46 }
47
48 public ECGI getMEcgi() {
49 return mEcgi;
50 }
51
52 public void setSEcgi(ECGI sEcgi) {
53 this.sEcgi = sEcgi;
54 }
55
56 public ECGI getSEcgi() {
57 return sEcgi;
58 }
59
60 public int encode(BerByteArrayOutputStream os) throws IOException {
61 return encode(os, true);
62 }
63
64 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
65
66 if (code != null) {
67 for (int i = code.length - 1; i >= 0; i--) {
68 os.write(code[i]);
69 }
70 if (withTag) {
71 return tag.encode(os) + code.length;
72 }
73 return code.length;
74 }
75
76 int codeLength = 0;
77 codeLength += sEcgi.encode(os, false);
78 // write tag: CONTEXT_CLASS, CONSTRUCTED, 2
79 os.write(0xA2);
80 codeLength += 1;
81
82 codeLength += mEcgi.encode(os, false);
83 // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
84 os.write(0xA1);
85 codeLength += 1;
86
87 codeLength += crnti.encode(os, false);
88 // write tag: CONTEXT_CLASS, PRIMITIVE, 0
89 os.write(0x80);
90 codeLength += 1;
91
92 codeLength += BerLength.encodeLength(os, codeLength);
93
94 if (withTag) {
95 codeLength += tag.encode(os);
96 }
97
98 return codeLength;
99
100 }
101
102 public int decode(InputStream is) throws IOException {
103 return decode(is, true);
104 }
105
106 public int decode(InputStream is, boolean withTag) throws IOException {
107 int codeLength = 0;
108 int subCodeLength = 0;
109 BerTag berTag = new BerTag();
110
111 if (withTag) {
112 codeLength += tag.decodeAndCheck(is);
113 }
114
115 BerLength length = new BerLength();
116 codeLength += length.decode(is);
117
118 int totalLength = length.val;
119 codeLength += totalLength;
120
121 subCodeLength += berTag.decode(is);
122 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
123 crnti = new CRNTI();
124 subCodeLength += crnti.decode(is, false);
125 subCodeLength += berTag.decode(is);
126 }
127 else {
128 throw new IOException("Tag does not match the mandatory sequence element tag.");
129 }
130
131 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
132 mEcgi = new ECGI();
133 subCodeLength += mEcgi.decode(is, false);
134 subCodeLength += berTag.decode(is);
135 }
136 else {
137 throw new IOException("Tag does not match the mandatory sequence element tag.");
138 }
139
140 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) {
141 sEcgi = new ECGI();
142 subCodeLength += sEcgi.decode(is, false);
143 if (subCodeLength == totalLength) {
144 return codeLength;
145 }
146 }
147 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
148
149
150 }
151
152 public void encodeAndSave(int encodingSizeGuess) throws IOException {
153 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
154 encode(os, false);
155 code = os.getArray();
156 }
157
158 public String toString() {
159 StringBuilder sb = new StringBuilder();
160 appendAsString(sb, 0);
161 return sb.toString();
162 }
163
164 public void appendAsString(StringBuilder sb, int indentLevel) {
165
166 sb.append("{");
167 sb.append("\n");
168 for (int i = 0; i < indentLevel + 1; i++) {
169 sb.append("\t");
170 }
171 if (crnti != null) {
slowr60d4d102017-08-16 18:33:58 -0700172 sb.append("crnti: ").append(crnti);
slowr13fa5b02017-08-08 16:32:31 -0700173 }
174
175 sb.append(",\n");
176 for (int i = 0; i < indentLevel + 1; i++) {
177 sb.append("\t");
178 }
179 if (mEcgi != null) {
slowr60d4d102017-08-16 18:33:58 -0700180 sb.append("mEcgi: ");
slowr13fa5b02017-08-08 16:32:31 -0700181 mEcgi.appendAsString(sb, indentLevel + 1);
182 }
183
184 sb.append(",\n");
185 for (int i = 0; i < indentLevel + 1; i++) {
186 sb.append("\t");
187 }
188 if (sEcgi != null) {
slowr60d4d102017-08-16 18:33:58 -0700189 sb.append("sEcgi: ");
slowr13fa5b02017-08-08 16:32:31 -0700190 sEcgi.appendAsString(sb, indentLevel + 1);
191 }
192
193 sb.append("\n");
194 for (int i = 0; i < indentLevel; i++) {
195 sb.append("\t");
196 }
197 sb.append("}");
198 }
199
200}
201