blob: 2253dd17839557b722580e4f51bafb3ef1751dd8 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/**
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08002 * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org)
slowr13fa5b02017-08-08 16:32:31 -07003 */
4
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08005package org.onosproject.xran.asn1lib.pdu;
slowr13fa5b02017-08-08 16:32:31 -07006
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08007
8import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
9import org.onosproject.xran.asn1lib.ber.BerLength;
10import org.onosproject.xran.asn1lib.ber.BerTag;
slowr13fa5b02017-08-08 16:32:31 -070011
12import java.io.IOException;
13import java.io.InputStream;
14import java.io.Serializable;
15
16public class XrancPdu implements Serializable {
17
18 private static final long serialVersionUID = 1L;
19
20 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
21
22 public byte[] code = null;
23 private XrancPduHdr hdr = null;
24 private XrancPduBody body = null;
25
26 public XrancPdu() {
27 }
28
29 public XrancPdu(byte[] code) {
30 this.code = code;
31 }
32
33 public void setHdr(XrancPduHdr hdr) {
34 this.hdr = hdr;
35 }
36
37 public XrancPduHdr getHdr() {
38 return hdr;
39 }
40
41 public void setBody(XrancPduBody body) {
42 this.body = body;
43 }
44
45 public XrancPduBody getBody() {
46 return body;
47 }
48
49 public int encode(BerByteArrayOutputStream os) throws IOException {
50 return encode(os, true);
51 }
52
53 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
54
55 if (code != null) {
56 for (int i = code.length - 1; i >= 0; i--) {
57 os.write(code[i]);
58 }
59 if (withTag) {
60 return tag.encode(os) + code.length;
61 }
62 return code.length;
63 }
64
65 int codeLength = 0;
66 int sublength;
67
68 sublength = body.encode(os);
69 codeLength += sublength;
70 codeLength += BerLength.encodeLength(os, sublength);
71 // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
72 os.write(0xA1);
73 codeLength += 1;
74
75 codeLength += hdr.encode(os, false);
76 // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
77 os.write(0xA0);
78 codeLength += 1;
79
80 codeLength += BerLength.encodeLength(os, codeLength);
81
82 if (withTag) {
83 codeLength += tag.encode(os);
84 }
85
86 return codeLength;
87
88 }
89
90 public int decode(InputStream is) throws IOException {
91 return decode(is, true);
92 }
93
94 public int decode(InputStream is, boolean withTag) throws IOException {
95 int codeLength = 0;
96 int subCodeLength = 0;
97 BerTag berTag = new BerTag();
98
99 if (withTag) {
100 codeLength += tag.decodeAndCheck(is);
101 }
102
103 BerLength length = new BerLength();
104 codeLength += length.decode(is);
105
106 int totalLength = length.val;
107 codeLength += totalLength;
108
109 subCodeLength += berTag.decode(is);
110 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
111 hdr = new XrancPduHdr();
112 subCodeLength += hdr.decode(is, false);
113 subCodeLength += berTag.decode(is);
114 }
115 else {
116 throw new IOException("Tag does not match the mandatory sequence element tag.");
117 }
118
119 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
120 subCodeLength += length.decode(is);
121 body = new XrancPduBody();
122 subCodeLength += body.decode(is, null);
123 if (subCodeLength == totalLength) {
124 return codeLength;
125 }
126 }
127 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
128
129
130 }
131
132 public void encodeAndSave(int encodingSizeGuess) throws IOException {
133 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
134 encode(os, false);
135 code = os.getArray();
136 }
137
138 public String toString() {
139 StringBuilder sb = new StringBuilder();
140 appendAsString(sb, 0);
141 return sb.toString();
142 }
143
144 public void appendAsString(StringBuilder sb, int indentLevel) {
145
146 sb.append("{");
147 sb.append("\n");
148 for (int i = 0; i < indentLevel + 1; i++) {
149 sb.append("\t");
150 }
151 if (hdr != null) {
slowr60d4d102017-08-16 18:33:58 -0700152 sb.append("hdr: ");
slowr13fa5b02017-08-08 16:32:31 -0700153 hdr.appendAsString(sb, indentLevel + 1);
154 }
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800155 else {
156 sb.append("hdr: <empty-required-field>");
157 }
slowr13fa5b02017-08-08 16:32:31 -0700158
159 sb.append(",\n");
160 for (int i = 0; i < indentLevel + 1; i++) {
161 sb.append("\t");
162 }
163 if (body != null) {
slowr60d4d102017-08-16 18:33:58 -0700164 sb.append("body: ");
slowr13fa5b02017-08-08 16:32:31 -0700165 body.appendAsString(sb, indentLevel + 1);
166 }
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800167 else {
168 sb.append("body: <empty-required-field>");
169 }
slowr13fa5b02017-08-08 16:32:31 -0700170
171 sb.append("\n");
172 for (int i = 0; i < indentLevel; i++) {
173 sb.append("\t");
174 }
175 sb.append("}");
176 }
177
178}
179