blob: 49390fe854eb4cbbc946f8dfe9906bc07b67b3e7 [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;
11import org.onosproject.xran.asn1lib.ber.types.string.BerUTF8String;
slowr13fa5b02017-08-08 16:32:31 -070012
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.Serializable;
16
17public class XrancPduHdr 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
23 public byte[] code = null;
24 private BerUTF8String ver = null;
25 private XrancApiID apiId = null;
26
27 public XrancPduHdr() {
28 }
29
30 public XrancPduHdr(byte[] code) {
31 this.code = code;
32 }
33
34 public void setVer(BerUTF8String ver) {
35 this.ver = ver;
36 }
37
38 public BerUTF8String getVer() {
39 return ver;
40 }
41
42 public void setApiId(XrancApiID apiId) {
43 this.apiId = apiId;
44 }
45
46 public XrancApiID getApiId() {
47 return apiId;
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 codeLength += apiId.encode(os, false);
68 // write tag: CONTEXT_CLASS, PRIMITIVE, 1
69 os.write(0x81);
70 codeLength += 1;
71
72 codeLength += ver.encode(os, false);
73 // write tag: CONTEXT_CLASS, PRIMITIVE, 0
74 os.write(0x80);
75 codeLength += 1;
76
77 codeLength += BerLength.encodeLength(os, codeLength);
78
79 if (withTag) {
80 codeLength += tag.encode(os);
81 }
82
83 return codeLength;
84
85 }
86
87 public int decode(InputStream is) throws IOException {
88 return decode(is, true);
89 }
90
91 public int decode(InputStream is, boolean withTag) throws IOException {
92 int codeLength = 0;
93 int subCodeLength = 0;
94 BerTag berTag = new BerTag();
95
96 if (withTag) {
97 codeLength += tag.decodeAndCheck(is);
98 }
99
100 BerLength length = new BerLength();
101 codeLength += length.decode(is);
102
103 int totalLength = length.val;
104 codeLength += totalLength;
105
106 subCodeLength += berTag.decode(is);
107 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) {
108 ver = new BerUTF8String();
109 subCodeLength += ver.decode(is, false);
110 subCodeLength += berTag.decode(is);
111 }
112 else {
113 throw new IOException("Tag does not match the mandatory sequence element tag.");
114 }
115
116 if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) {
117 apiId = new XrancApiID();
118 subCodeLength += apiId.decode(is, false);
119 if (subCodeLength == totalLength) {
120 return codeLength;
121 }
122 }
123 throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength);
124
125
126 }
127
128 public void encodeAndSave(int encodingSizeGuess) throws IOException {
129 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
130 encode(os, false);
131 code = os.getArray();
132 }
133
134 public String toString() {
135 StringBuilder sb = new StringBuilder();
136 appendAsString(sb, 0);
137 return sb.toString();
138 }
139
140 public void appendAsString(StringBuilder sb, int indentLevel) {
141
142 sb.append("{");
143 sb.append("\n");
144 for (int i = 0; i < indentLevel + 1; i++) {
145 sb.append("\t");
146 }
147 if (ver != null) {
slowr60d4d102017-08-16 18:33:58 -0700148 sb.append("ver: ").append(ver);
slowr13fa5b02017-08-08 16:32:31 -0700149 }
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800150 else {
151 sb.append("ver: <empty-required-field>");
152 }
slowr13fa5b02017-08-08 16:32:31 -0700153
154 sb.append(",\n");
155 for (int i = 0; i < indentLevel + 1; i++) {
156 sb.append("\t");
157 }
158 if (apiId != null) {
slowr60d4d102017-08-16 18:33:58 -0700159 sb.append("apiId: ").append(apiId);
slowr13fa5b02017-08-08 16:32:31 -0700160 }
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800161 else {
162 sb.append("apiId: <empty-required-field>");
163 }
slowr13fa5b02017-08-08 16:32:31 -0700164
165 sb.append("\n");
166 for (int i = 0; i < indentLevel; i++) {
167 sb.append("\t");
168 }
169 sb.append("}");
170 }
171
172}
173