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