slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 2 | * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 3 | */ |
| 4 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 5 | package org.onosproject.xran.asn1lib.pdu; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 6 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 8 | import com.fasterxml.jackson.annotation.JsonValue; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 9 | import org.onosproject.xran.asn1lib.api.CRNTI; |
| 10 | import org.onosproject.xran.asn1lib.api.ECGI; |
| 11 | import org.onosproject.xran.asn1lib.api.PCIARFCN; |
| 12 | import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream; |
| 13 | import org.onosproject.xran.asn1lib.ber.BerLength; |
| 14 | import org.onosproject.xran.asn1lib.ber.BerTag; |
| 15 | import org.onosproject.xran.asn1lib.ber.types.BerEnum; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 16 | |
| 17 | import java.io.IOException; |
| 18 | import java.io.InputStream; |
| 19 | import java.io.Serializable; |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.Iterator; |
| 22 | import java.util.List; |
| 23 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 24 | public class ScellAddStatus implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 25 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 26 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 27 | private static final long serialVersionUID = 1L; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 28 | @JsonIgnore |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 29 | public byte[] code = null; |
| 30 | private CRNTI crnti = null; |
| 31 | private ECGI ecgi = null; |
| 32 | private ScellsInd scellsInd = null; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 33 | private Status status = null; |
| 34 | public ScellAddStatus() { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 35 | } |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 36 | public ScellAddStatus(byte[] code) { |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 37 | this.code = code; |
| 38 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 39 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 40 | public CRNTI getCrnti() { |
| 41 | return crnti; |
| 42 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 43 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 44 | public void setCrnti(CRNTI crnti) { |
| 45 | this.crnti = crnti; |
| 46 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 47 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 48 | public ECGI getEcgi() { |
| 49 | return ecgi; |
| 50 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 51 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 52 | public void setEcgi(ECGI ecgi) { |
| 53 | this.ecgi = ecgi; |
| 54 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 55 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 56 | public ScellsInd getScellsInd() { |
| 57 | return scellsInd; |
| 58 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 59 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 60 | public void setScellsInd(ScellsInd scellsInd) { |
| 61 | this.scellsInd = scellsInd; |
| 62 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 63 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 64 | public Status getStatus() { |
| 65 | return status; |
| 66 | } |
| 67 | |
| 68 | public void setStatus(Status status) { |
| 69 | this.status = status; |
| 70 | } |
| 71 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 72 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 73 | return encode(os, true); |
| 74 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 75 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 76 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 77 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 78 | if (code != null) { |
| 79 | for (int i = code.length - 1; i >= 0; i--) { |
| 80 | os.write(code[i]); |
| 81 | } |
| 82 | if (withTag) { |
| 83 | return tag.encode(os) + code.length; |
| 84 | } |
| 85 | return code.length; |
| 86 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 88 | int codeLength = 0; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 89 | codeLength += status.encode(os, false); |
| 90 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 3 |
| 91 | os.write(0xA3); |
| 92 | codeLength += 1; |
| 93 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 94 | codeLength += scellsInd.encode(os, false); |
| 95 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 2 |
| 96 | os.write(0xA2); |
| 97 | codeLength += 1; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 98 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 99 | codeLength += ecgi.encode(os, false); |
| 100 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 101 | os.write(0xA1); |
| 102 | codeLength += 1; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 104 | codeLength += crnti.encode(os, false); |
| 105 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 106 | os.write(0x80); |
| 107 | codeLength += 1; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 108 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 109 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 110 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 111 | if (withTag) { |
| 112 | codeLength += tag.encode(os); |
| 113 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 114 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 115 | return codeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 116 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | public int decode(InputStream is) throws IOException { |
| 120 | return decode(is, true); |
| 121 | } |
| 122 | |
| 123 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 124 | int codeLength = 0; |
| 125 | int subCodeLength = 0; |
| 126 | BerTag berTag = new BerTag(); |
| 127 | |
| 128 | if (withTag) { |
| 129 | codeLength += tag.decodeAndCheck(is); |
| 130 | } |
| 131 | |
| 132 | BerLength length = new BerLength(); |
| 133 | codeLength += length.decode(is); |
| 134 | |
| 135 | int totalLength = length.val; |
| 136 | codeLength += totalLength; |
| 137 | |
| 138 | subCodeLength += berTag.decode(is); |
| 139 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 140 | crnti = new CRNTI(); |
| 141 | subCodeLength += crnti.decode(is, false); |
| 142 | subCodeLength += berTag.decode(is); |
| 143 | } else { |
| 144 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 145 | } |
| 146 | |
| 147 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 148 | ecgi = new ECGI(); |
| 149 | subCodeLength += ecgi.decode(is, false); |
| 150 | subCodeLength += berTag.decode(is); |
| 151 | } else { |
| 152 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 153 | } |
| 154 | |
| 155 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { |
| 156 | scellsInd = new ScellsInd(); |
| 157 | subCodeLength += scellsInd.decode(is, false); |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 158 | subCodeLength += berTag.decode(is); |
| 159 | } else { |
| 160 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 161 | } |
| 162 | |
| 163 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { |
| 164 | status = new Status(); |
| 165 | subCodeLength += status.decode(is, false); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 166 | if (subCodeLength == totalLength) { |
| 167 | return codeLength; |
| 168 | } |
| 169 | } |
| 170 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 171 | |
| 172 | |
| 173 | } |
| 174 | |
| 175 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 176 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 177 | encode(os, false); |
| 178 | code = os.getArray(); |
| 179 | } |
| 180 | |
| 181 | public String toString() { |
| 182 | StringBuilder sb = new StringBuilder(); |
| 183 | appendAsString(sb, 0); |
| 184 | return sb.toString(); |
| 185 | } |
| 186 | |
| 187 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 188 | |
| 189 | sb.append("{"); |
| 190 | sb.append("\n"); |
| 191 | for (int i = 0; i < indentLevel + 1; i++) { |
| 192 | sb.append("\t"); |
| 193 | } |
| 194 | if (crnti != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 195 | sb.append("crnti: ").append(crnti); |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 196 | } else { |
| 197 | sb.append("crnti: <empty-required-field>"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | sb.append(",\n"); |
| 201 | for (int i = 0; i < indentLevel + 1; i++) { |
| 202 | sb.append("\t"); |
| 203 | } |
| 204 | if (ecgi != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 205 | sb.append("ecgi: "); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 206 | ecgi.appendAsString(sb, indentLevel + 1); |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 207 | } else { |
| 208 | sb.append("ecgi: <empty-required-field>"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | sb.append(",\n"); |
| 212 | for (int i = 0; i < indentLevel + 1; i++) { |
| 213 | sb.append("\t"); |
| 214 | } |
| 215 | if (scellsInd != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 216 | sb.append("scellsInd: "); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 217 | scellsInd.appendAsString(sb, indentLevel + 1); |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 218 | } else { |
| 219 | sb.append("scellsInd: <empty-required-field>"); |
| 220 | } |
| 221 | |
| 222 | sb.append(",\n"); |
| 223 | for (int i = 0; i < indentLevel + 1; i++) { |
| 224 | sb.append("\t"); |
| 225 | } |
| 226 | if (status != null) { |
| 227 | sb.append("status: "); |
| 228 | status.appendAsString(sb, indentLevel + 1); |
| 229 | } else { |
| 230 | sb.append("status: <empty-required-field>"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | sb.append("\n"); |
| 234 | for (int i = 0; i < indentLevel; i++) { |
| 235 | sb.append("\t"); |
| 236 | } |
| 237 | sb.append("}"); |
| 238 | } |
| 239 | |
| 240 | public static class ScellsInd implements Serializable { |
| 241 | |
| 242 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 243 | private static final long serialVersionUID = 1L; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 244 | @JsonIgnore |
| 245 | public byte[] code = null; |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 246 | private List<PCIARFCN> seqOf = null; |
| 247 | |
| 248 | public ScellsInd() { |
| 249 | seqOf = new ArrayList<PCIARFCN>(); |
| 250 | } |
| 251 | |
| 252 | public ScellsInd(byte[] code) { |
| 253 | this.code = code; |
| 254 | } |
| 255 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 256 | @JsonValue |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 257 | public List<PCIARFCN> getPCIARFCN() { |
| 258 | if (seqOf == null) { |
| 259 | seqOf = new ArrayList<PCIARFCN>(); |
| 260 | } |
| 261 | return seqOf; |
| 262 | } |
| 263 | |
| 264 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 265 | return encode(os, true); |
| 266 | } |
| 267 | |
| 268 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 269 | |
| 270 | if (code != null) { |
| 271 | for (int i = code.length - 1; i >= 0; i--) { |
| 272 | os.write(code[i]); |
| 273 | } |
| 274 | if (withTag) { |
| 275 | return tag.encode(os) + code.length; |
| 276 | } |
| 277 | return code.length; |
| 278 | } |
| 279 | |
| 280 | int codeLength = 0; |
| 281 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 282 | codeLength += seqOf.get(i).encode(os, true); |
| 283 | } |
| 284 | |
| 285 | codeLength += BerLength.encodeLength(os, codeLength); |
| 286 | |
| 287 | if (withTag) { |
| 288 | codeLength += tag.encode(os); |
| 289 | } |
| 290 | |
| 291 | return codeLength; |
| 292 | } |
| 293 | |
| 294 | public int decode(InputStream is) throws IOException { |
| 295 | return decode(is, true); |
| 296 | } |
| 297 | |
| 298 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 299 | int codeLength = 0; |
| 300 | int subCodeLength = 0; |
| 301 | if (withTag) { |
| 302 | codeLength += tag.decodeAndCheck(is); |
| 303 | } |
| 304 | |
| 305 | BerLength length = new BerLength(); |
| 306 | codeLength += length.decode(is); |
| 307 | int totalLength = length.val; |
| 308 | |
| 309 | while (subCodeLength < totalLength) { |
| 310 | PCIARFCN element = new PCIARFCN(); |
| 311 | subCodeLength += element.decode(is, true); |
| 312 | seqOf.add(element); |
| 313 | } |
| 314 | if (subCodeLength != totalLength) { |
| 315 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
| 316 | |
| 317 | } |
| 318 | codeLength += subCodeLength; |
| 319 | |
| 320 | return codeLength; |
| 321 | } |
| 322 | |
| 323 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 324 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 325 | encode(os, false); |
| 326 | code = os.getArray(); |
| 327 | } |
| 328 | |
| 329 | public String toString() { |
| 330 | StringBuilder sb = new StringBuilder(); |
| 331 | appendAsString(sb, 0); |
| 332 | return sb.toString(); |
| 333 | } |
| 334 | |
| 335 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 336 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 337 | sb.append("{\n"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 338 | for (int i = 0; i < indentLevel + 1; i++) { |
| 339 | sb.append("\t"); |
| 340 | } |
| 341 | if (seqOf == null) { |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 342 | sb.append("null"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 343 | } else { |
| 344 | Iterator<PCIARFCN> it = seqOf.iterator(); |
| 345 | if (it.hasNext()) { |
| 346 | it.next().appendAsString(sb, indentLevel + 1); |
| 347 | while (it.hasNext()) { |
| 348 | sb.append(",\n"); |
| 349 | for (int i = 0; i < indentLevel + 1; i++) { |
| 350 | sb.append("\t"); |
| 351 | } |
| 352 | it.next().appendAsString(sb, indentLevel + 1); |
| 353 | } |
| 354 | } |
| 355 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 356 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 357 | sb.append("\n"); |
| 358 | for (int i = 0; i < indentLevel; i++) { |
| 359 | sb.append("\t"); |
| 360 | } |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 361 | sb.append("}"); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 362 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 363 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | public static class Status implements Serializable { |
| 367 | |
| 368 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 369 | private static final long serialVersionUID = 1L; |
| 370 | @JsonIgnore |
| 371 | public byte[] code = null; |
| 372 | private List<BerEnum> seqOf = null; |
| 373 | |
| 374 | public Status() { |
| 375 | seqOf = new ArrayList<BerEnum>(); |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 376 | } |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 377 | |
| 378 | public Status(byte[] code) { |
| 379 | this.code = code; |
| 380 | } |
| 381 | |
| 382 | @JsonValue |
| 383 | public List<BerEnum> getBerEnum() { |
| 384 | if (seqOf == null) { |
| 385 | seqOf = new ArrayList<BerEnum>(); |
| 386 | } |
| 387 | return seqOf; |
| 388 | } |
| 389 | |
| 390 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 391 | return encode(os, true); |
| 392 | } |
| 393 | |
| 394 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 395 | |
| 396 | if (code != null) { |
| 397 | for (int i = code.length - 1; i >= 0; i--) { |
| 398 | os.write(code[i]); |
| 399 | } |
| 400 | if (withTag) { |
| 401 | return tag.encode(os) + code.length; |
| 402 | } |
| 403 | return code.length; |
| 404 | } |
| 405 | |
| 406 | int codeLength = 0; |
| 407 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 408 | codeLength += seqOf.get(i).encode(os, true); |
| 409 | } |
| 410 | |
| 411 | codeLength += BerLength.encodeLength(os, codeLength); |
| 412 | |
| 413 | if (withTag) { |
| 414 | codeLength += tag.encode(os); |
| 415 | } |
| 416 | |
| 417 | return codeLength; |
| 418 | } |
| 419 | |
| 420 | public int decode(InputStream is) throws IOException { |
| 421 | return decode(is, true); |
| 422 | } |
| 423 | |
| 424 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 425 | int codeLength = 0; |
| 426 | int subCodeLength = 0; |
| 427 | if (withTag) { |
| 428 | codeLength += tag.decodeAndCheck(is); |
| 429 | } |
| 430 | |
| 431 | BerLength length = new BerLength(); |
| 432 | codeLength += length.decode(is); |
| 433 | int totalLength = length.val; |
| 434 | |
| 435 | while (subCodeLength < totalLength) { |
| 436 | BerEnum element = new BerEnum(); |
| 437 | subCodeLength += element.decode(is, true); |
| 438 | seqOf.add(element); |
| 439 | } |
| 440 | if (subCodeLength != totalLength) { |
| 441 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
| 442 | |
| 443 | } |
| 444 | codeLength += subCodeLength; |
| 445 | |
| 446 | return codeLength; |
| 447 | } |
| 448 | |
| 449 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 450 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 451 | encode(os, false); |
| 452 | code = os.getArray(); |
| 453 | } |
| 454 | |
| 455 | public String toString() { |
| 456 | StringBuilder sb = new StringBuilder(); |
| 457 | appendAsString(sb, 0); |
| 458 | return sb.toString(); |
| 459 | } |
| 460 | |
| 461 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 462 | |
| 463 | sb.append("{\n"); |
| 464 | for (int i = 0; i < indentLevel + 1; i++) { |
| 465 | sb.append("\t"); |
| 466 | } |
| 467 | if (seqOf == null) { |
| 468 | sb.append("null"); |
| 469 | } else { |
| 470 | Iterator<BerEnum> it = seqOf.iterator(); |
| 471 | if (it.hasNext()) { |
| 472 | sb.append(it.next()); |
| 473 | while (it.hasNext()) { |
| 474 | sb.append(",\n"); |
| 475 | for (int i = 0; i < indentLevel + 1; i++) { |
| 476 | sb.append("\t"); |
| 477 | } |
| 478 | sb.append(it.next()); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | sb.append("\n"); |
| 484 | for (int i = 0; i < indentLevel; i++) { |
| 485 | sb.append("\t"); |
| 486 | } |
| 487 | sb.append("}"); |
| 488 | } |
| 489 | |
slowr | 89c2ac1 | 2017-08-15 16:20:06 -0700 | [diff] [blame] | 490 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 491 | |
| 492 | } |
| 493 | |