blob: d983713f1af547f4285a58deb3a717656e24e476 [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 */
4
5package org.onosproject.xran.codecs.pdu;
6
slowr60d4d102017-08-16 18:33:58 -07007import com.fasterxml.jackson.annotation.JsonIgnore;
8import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
9import org.onosproject.xran.codecs.ber.BerLength;
10import org.onosproject.xran.codecs.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
slowr60d4d102017-08-16 18:33:58 -070022 @JsonIgnore
slowr13fa5b02017-08-08 16:32:31 -070023 public byte[] code = null;
24 private XrancPduHdr hdr = null;
25 private XrancPduBody body = null;
26
27 public XrancPdu() {
28 }
29
30 public XrancPdu(byte[] code) {
31 this.code = code;
32 }
33
34 public void setHdr(XrancPduHdr hdr) {
35 this.hdr = hdr;
36 }
37
38 public XrancPduHdr getHdr() {
39 return hdr;
40 }
41
42 public void setBody(XrancPduBody body) {
43 this.body = body;
44 }
45
46 public XrancPduBody getBody() {
47 return body;
48 }
49
50 public int encode(BerByteArrayOutputStream os) throws IOException {
51 return encode(os, true);
52 }
53
54 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
55
56 if (code != null) {
57 for (int i = code.length - 1; i >= 0; i--) {
58 os.write(code[i]);
59 }
60 if (withTag) {
61 return tag.encode(os) + code.length;
62 }
63 return code.length;
64 }
65
66 int codeLength = 0;
67 int sublength;
68
69 sublength = body.encode(os);
70 codeLength += sublength;
71 codeLength += BerLength.encodeLength(os, sublength);
72 // write tag: CONTEXT_CLASS, CONSTRUCTED, 1
73 os.write(0xA1);
74 codeLength += 1;
75
76 codeLength += hdr.encode(os, false);
77 // write tag: CONTEXT_CLASS, CONSTRUCTED, 0
78 os.write(0xA0);
79 codeLength += 1;
80
81 codeLength += BerLength.encodeLength(os, codeLength);
82
83 if (withTag) {
84 codeLength += tag.encode(os);
85 }
86
87 return codeLength;
88
89 }
90
91 public int decode(InputStream is) throws IOException {
92 return decode(is, true);
93 }
94
95 public int decode(InputStream is, boolean withTag) throws IOException {
96 int codeLength = 0;
97 int subCodeLength = 0;
98 BerTag berTag = new BerTag();
99
100 if (withTag) {
101 codeLength += tag.decodeAndCheck(is);
102 }
103
104 BerLength length = new BerLength();
105 codeLength += length.decode(is);
106
107 int totalLength = length.val;
108 codeLength += totalLength;
109
110 subCodeLength += berTag.decode(is);
111 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) {
112 hdr = new XrancPduHdr();
113 subCodeLength += hdr.decode(is, false);
114 subCodeLength += berTag.decode(is);
115 }
116 else {
117 throw new IOException("Tag does not match the mandatory sequence element tag.");
118 }
119
120 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) {
121 subCodeLength += length.decode(is);
122 body = new XrancPduBody();
123 subCodeLength += body.decode(is, null);
124 if (subCodeLength == totalLength) {
125 return codeLength;
126 }
127 }
128 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
129
130
131 }
132
133 public void encodeAndSave(int encodingSizeGuess) throws IOException {
134 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
135 encode(os, false);
136 code = os.getArray();
137 }
138
139 public String toString() {
140 StringBuilder sb = new StringBuilder();
141 appendAsString(sb, 0);
142 return sb.toString();
143 }
144
145 public void appendAsString(StringBuilder sb, int indentLevel) {
146
147 sb.append("{");
148 sb.append("\n");
149 for (int i = 0; i < indentLevel + 1; i++) {
150 sb.append("\t");
151 }
152 if (hdr != null) {
slowr60d4d102017-08-16 18:33:58 -0700153 sb.append("hdr: ");
slowr13fa5b02017-08-08 16:32:31 -0700154 hdr.appendAsString(sb, indentLevel + 1);
155 }
156
157 sb.append(",\n");
158 for (int i = 0; i < indentLevel + 1; i++) {
159 sb.append("\t");
160 }
161 if (body != null) {
slowr60d4d102017-08-16 18:33:58 -0700162 sb.append("body: ");
slowr13fa5b02017-08-08 16:32:31 -0700163 body.appendAsString(sb, indentLevel + 1);
164 }
165
166 sb.append("\n");
167 for (int i = 0; i < indentLevel; i++) {
168 sb.append("\t");
169 }
170 sb.append("}");
171 }
172
173}
174