blob: 35b4fa6afb95ad4671d9620bf89b5f984bc28cd3 [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.api;
6
7import com.fasterxml.jackson.annotation.JsonIgnore;
8import com.fasterxml.jackson.annotation.JsonValue;
9import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
10import org.onosproject.xran.asn1lib.ber.BerLength;
11import org.onosproject.xran.asn1lib.ber.BerTag;
12
13import java.io.IOException;
14import java.io.InputStream;
15import java.io.Serializable;
16import java.util.ArrayList;
17import java.util.Iterator;
18import java.util.List;
19
20
21public class ERABResponse implements Serializable {
22
23 public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16);
24 private static final long serialVersionUID = 1L;
25 @JsonIgnore
26 public byte[] code = null;
27 private List<ERABResponseItem> seqOf = null;
28
29 public ERABResponse() {
30 seqOf = new ArrayList<ERABResponseItem>();
31 }
32
33 public ERABResponse(byte[] code) {
34 this.code = code;
35 }
36
37 @JsonValue
38 public List<ERABResponseItem> getERABResponseItem() {
39 if (seqOf == null) {
40 seqOf = new ArrayList<ERABResponseItem>();
41 }
42 return seqOf;
43 }
44
45 public int encode(BerByteArrayOutputStream os) throws IOException {
46 return encode(os, true);
47 }
48
49 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
50
51 if (code != null) {
52 for (int i = code.length - 1; i >= 0; i--) {
53 os.write(code[i]);
54 }
55 if (withTag) {
56 return tag.encode(os) + code.length;
57 }
58 return code.length;
59 }
60
61 int codeLength = 0;
62 for (int i = (seqOf.size() - 1); i >= 0; i--) {
63 codeLength += seqOf.get(i).encode(os, true);
64 }
65
66 codeLength += BerLength.encodeLength(os, codeLength);
67
68 if (withTag) {
69 codeLength += tag.encode(os);
70 }
71
72 return codeLength;
73 }
74
75 public int decode(InputStream is) throws IOException {
76 return decode(is, true);
77 }
78
79 public int decode(InputStream is, boolean withTag) throws IOException {
80 int codeLength = 0;
81 int subCodeLength = 0;
82 if (withTag) {
83 codeLength += tag.decodeAndCheck(is);
84 }
85
86 BerLength length = new BerLength();
87 codeLength += length.decode(is);
88 int totalLength = length.val;
89
90 while (subCodeLength < totalLength) {
91 ERABResponseItem element = new ERABResponseItem();
92 subCodeLength += element.decode(is, true);
93 seqOf.add(element);
94 }
95 if (subCodeLength != totalLength) {
96 throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
97
98 }
99 codeLength += subCodeLength;
100
101 return codeLength;
102 }
103
104 public void encodeAndSave(int encodingSizeGuess) throws IOException {
105 BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess);
106 encode(os, false);
107 code = os.getArray();
108 }
109
110 public String toString() {
111 StringBuilder sb = new StringBuilder();
112 appendAsString(sb, 0);
113 return sb.toString();
114 }
115
116 public void appendAsString(StringBuilder sb, int indentLevel) {
117
118 sb.append("{\n");
119 for (int i = 0; i < indentLevel + 1; i++) {
120 sb.append("\t");
121 }
122 if (seqOf == null) {
123 sb.append("null");
124 } else {
125 Iterator<ERABResponseItem> it = seqOf.iterator();
126 if (it.hasNext()) {
127 it.next().appendAsString(sb, indentLevel + 1);
128 while (it.hasNext()) {
129 sb.append(",\n");
130 for (int i = 0; i < indentLevel + 1; i++) {
131 sb.append("\t");
132 }
133 it.next().appendAsString(sb, indentLevel + 1);
134 }
135 }
136 }
137
138 sb.append("\n");
139 for (int i = 0; i < indentLevel; i++) {
140 sb.append("\t");
141 }
142 sb.append("}");
143 }
144
145}
146