slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
| 2 | * This class file was automatically generated by jASN1 v1.8.0 (http://www.openmuc.org) |
| 3 | */ |
| 4 | |
| 5 | package org.onosproject.xran.codecs.pdu; |
| 6 | |
| 7 | import org.onosproject.xran.codecs.api.CRNTI; |
| 8 | import org.onosproject.xran.codecs.api.ECGI; |
| 9 | import org.onosproject.xran.codecs.api.XICICPA; |
| 10 | import org.openmuc.jasn1.ber.BerByteArrayOutputStream; |
| 11 | import org.openmuc.jasn1.ber.BerLength; |
| 12 | import org.openmuc.jasn1.ber.BerTag; |
| 13 | import org.openmuc.jasn1.ber.types.BerBitString; |
| 14 | import org.openmuc.jasn1.ber.types.BerInteger; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 15 | import org.openmuc.jasn1.ber.types.string.BerUTF8String; |
| 16 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 17 | import java.io.IOException; |
| 18 | import java.io.InputStream; |
| 19 | import java.io.Serializable; |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 20 | import java.io.UnsupportedEncodingException; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 21 | import java.util.ArrayList; |
| 22 | import java.util.Iterator; |
| 23 | import java.util.List; |
| 24 | |
| 25 | public class RRMConfig implements Serializable { |
| 26 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 27 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 28 | private static final long serialVersionUID = 1L; |
| 29 | public byte[] code = null; |
| 30 | private ECGI ecgi = null; |
| 31 | private Crnti crnti = null; |
| 32 | private Pa pa = null; |
| 33 | private StartPrbDl startPrbDl = null; |
| 34 | private EndPrbDl endPrbDl = null; |
| 35 | private SubframeBitmaskDl subframeBitmaskDl = null; |
| 36 | private P0UePusch p0UePusch = null; |
| 37 | private StartPrbUl startPrbUl = null; |
| 38 | private EndPrbUl endPrbUl = null; |
| 39 | private SubframeBitmaskUl subframeBitmaskUl = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 41 | public RRMConfig() { |
| 42 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 43 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 44 | public RRMConfig(byte[] code) { |
| 45 | this.code = code; |
| 46 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 47 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 48 | public ECGI getEcgi() { |
| 49 | return ecgi; |
| 50 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 51 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -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 | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 56 | public Crnti getCrnti() { |
| 57 | return crnti; |
| 58 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 59 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 60 | public void setCrnti(Crnti crnti) { |
| 61 | this.crnti = crnti; |
| 62 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 63 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 64 | public Pa getPa() { |
| 65 | return pa; |
| 66 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 67 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 68 | public void setPa(Pa pa) { |
| 69 | this.pa = pa; |
| 70 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 71 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 72 | public StartPrbDl getStartPrbDl() { |
| 73 | return startPrbDl; |
| 74 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 75 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 76 | public void setStartPrbDl(StartPrbDl startPrbDl) { |
| 77 | this.startPrbDl = startPrbDl; |
| 78 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 79 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 80 | public EndPrbDl getEndPrbDl() { |
| 81 | return endPrbDl; |
| 82 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 83 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 84 | public void setEndPrbDl(EndPrbDl endPrbDl) { |
| 85 | this.endPrbDl = endPrbDl; |
| 86 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 87 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 88 | public SubframeBitmaskDl getSubframeBitmaskDl() { |
| 89 | return subframeBitmaskDl; |
| 90 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 91 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 92 | public void setSubframeBitmaskDl(SubframeBitmaskDl subframeBitmaskDl) { |
| 93 | this.subframeBitmaskDl = subframeBitmaskDl; |
| 94 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 95 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 96 | public P0UePusch getP0UePusch() { |
| 97 | return p0UePusch; |
| 98 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 99 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 100 | public void setP0UePusch(P0UePusch p0UePusch) { |
| 101 | this.p0UePusch = p0UePusch; |
| 102 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 103 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 104 | public StartPrbUl getStartPrbUl() { |
| 105 | return startPrbUl; |
| 106 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 107 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 108 | public void setStartPrbUl(StartPrbUl startPrbUl) { |
| 109 | this.startPrbUl = startPrbUl; |
| 110 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 111 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 112 | public EndPrbUl getEndPrbUl() { |
| 113 | return endPrbUl; |
| 114 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 115 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 116 | public void setEndPrbUl(EndPrbUl endPrbUl) { |
| 117 | this.endPrbUl = endPrbUl; |
| 118 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 119 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 120 | public SubframeBitmaskUl getSubframeBitmaskUl() { |
| 121 | return subframeBitmaskUl; |
| 122 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 123 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 124 | public void setSubframeBitmaskUl(SubframeBitmaskUl subframeBitmaskUl) { |
| 125 | this.subframeBitmaskUl = subframeBitmaskUl; |
| 126 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 127 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 128 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 129 | return encode(os, true); |
| 130 | } |
| 131 | |
| 132 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 133 | |
| 134 | if (code != null) { |
| 135 | for (int i = code.length - 1; i >= 0; i--) { |
| 136 | os.write(code[i]); |
| 137 | } |
| 138 | if (withTag) { |
| 139 | return tag.encode(os) + code.length; |
| 140 | } |
| 141 | return code.length; |
| 142 | } |
| 143 | |
| 144 | int codeLength = 0; |
| 145 | if (subframeBitmaskUl != null) { |
| 146 | codeLength += subframeBitmaskUl.encode(os, false); |
| 147 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 9 |
| 148 | os.write(0xA9); |
| 149 | codeLength += 1; |
| 150 | } |
| 151 | |
| 152 | if (endPrbUl != null) { |
| 153 | codeLength += endPrbUl.encode(os, false); |
| 154 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 8 |
| 155 | os.write(0xA8); |
| 156 | codeLength += 1; |
| 157 | } |
| 158 | |
| 159 | if (startPrbUl != null) { |
| 160 | codeLength += startPrbUl.encode(os, false); |
| 161 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 7 |
| 162 | os.write(0xA7); |
| 163 | codeLength += 1; |
| 164 | } |
| 165 | |
| 166 | if (p0UePusch != null) { |
| 167 | codeLength += p0UePusch.encode(os, false); |
| 168 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 6 |
| 169 | os.write(0xA6); |
| 170 | codeLength += 1; |
| 171 | } |
| 172 | |
| 173 | if (subframeBitmaskDl != null) { |
| 174 | codeLength += subframeBitmaskDl.encode(os, false); |
| 175 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 5 |
| 176 | os.write(0xA5); |
| 177 | codeLength += 1; |
| 178 | } |
| 179 | |
| 180 | if (endPrbDl != null) { |
| 181 | codeLength += endPrbDl.encode(os, false); |
| 182 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 4 |
| 183 | os.write(0xA4); |
| 184 | codeLength += 1; |
| 185 | } |
| 186 | |
| 187 | if (startPrbDl != null) { |
| 188 | codeLength += startPrbDl.encode(os, false); |
| 189 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 3 |
| 190 | os.write(0xA3); |
| 191 | codeLength += 1; |
| 192 | } |
| 193 | |
| 194 | if (pa != null) { |
| 195 | codeLength += pa.encode(os, false); |
| 196 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 2 |
| 197 | os.write(0xA2); |
| 198 | codeLength += 1; |
| 199 | } |
| 200 | |
| 201 | if (crnti != null) { |
| 202 | codeLength += crnti.encode(os, false); |
| 203 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 204 | os.write(0xA1); |
| 205 | codeLength += 1; |
| 206 | } |
| 207 | |
| 208 | codeLength += ecgi.encode(os, false); |
| 209 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 0 |
| 210 | os.write(0xA0); |
| 211 | codeLength += 1; |
| 212 | |
| 213 | codeLength += BerLength.encodeLength(os, codeLength); |
| 214 | |
| 215 | if (withTag) { |
| 216 | codeLength += tag.encode(os); |
| 217 | } |
| 218 | |
| 219 | return codeLength; |
| 220 | |
| 221 | } |
| 222 | |
| 223 | public int decode(InputStream is) throws IOException { |
| 224 | return decode(is, true); |
| 225 | } |
| 226 | |
| 227 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 228 | int codeLength = 0; |
| 229 | int subCodeLength = 0; |
| 230 | BerTag berTag = new BerTag(); |
| 231 | |
| 232 | if (withTag) { |
| 233 | codeLength += tag.decodeAndCheck(is); |
| 234 | } |
| 235 | |
| 236 | BerLength length = new BerLength(); |
| 237 | codeLength += length.decode(is); |
| 238 | |
| 239 | int totalLength = length.val; |
| 240 | codeLength += totalLength; |
| 241 | |
| 242 | subCodeLength += berTag.decode(is); |
| 243 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { |
| 244 | ecgi = new ECGI(); |
| 245 | subCodeLength += ecgi.decode(is, false); |
| 246 | if (subCodeLength == totalLength) { |
| 247 | return codeLength; |
| 248 | } |
| 249 | subCodeLength += berTag.decode(is); |
| 250 | } else { |
| 251 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 252 | } |
| 253 | |
| 254 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 255 | crnti = new Crnti(); |
| 256 | subCodeLength += crnti.decode(is, false); |
| 257 | if (subCodeLength == totalLength) { |
| 258 | return codeLength; |
| 259 | } |
| 260 | subCodeLength += berTag.decode(is); |
| 261 | } |
| 262 | |
| 263 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { |
| 264 | pa = new Pa(); |
| 265 | subCodeLength += pa.decode(is, false); |
| 266 | if (subCodeLength == totalLength) { |
| 267 | return codeLength; |
| 268 | } |
| 269 | subCodeLength += berTag.decode(is); |
| 270 | } |
| 271 | |
| 272 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 3)) { |
| 273 | startPrbDl = new StartPrbDl(); |
| 274 | subCodeLength += startPrbDl.decode(is, false); |
| 275 | if (subCodeLength == totalLength) { |
| 276 | return codeLength; |
| 277 | } |
| 278 | subCodeLength += berTag.decode(is); |
| 279 | } |
| 280 | |
| 281 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 4)) { |
| 282 | endPrbDl = new EndPrbDl(); |
| 283 | subCodeLength += endPrbDl.decode(is, false); |
| 284 | if (subCodeLength == totalLength) { |
| 285 | return codeLength; |
| 286 | } |
| 287 | subCodeLength += berTag.decode(is); |
| 288 | } |
| 289 | |
| 290 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 5)) { |
| 291 | subframeBitmaskDl = new SubframeBitmaskDl(); |
| 292 | subCodeLength += subframeBitmaskDl.decode(is, false); |
| 293 | if (subCodeLength == totalLength) { |
| 294 | return codeLength; |
| 295 | } |
| 296 | subCodeLength += berTag.decode(is); |
| 297 | } |
| 298 | |
| 299 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 6)) { |
| 300 | p0UePusch = new P0UePusch(); |
| 301 | subCodeLength += p0UePusch.decode(is, false); |
| 302 | if (subCodeLength == totalLength) { |
| 303 | return codeLength; |
| 304 | } |
| 305 | subCodeLength += berTag.decode(is); |
| 306 | } |
| 307 | |
| 308 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 7)) { |
| 309 | startPrbUl = new StartPrbUl(); |
| 310 | subCodeLength += startPrbUl.decode(is, false); |
| 311 | if (subCodeLength == totalLength) { |
| 312 | return codeLength; |
| 313 | } |
| 314 | subCodeLength += berTag.decode(is); |
| 315 | } |
| 316 | |
| 317 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 8)) { |
| 318 | endPrbUl = new EndPrbUl(); |
| 319 | subCodeLength += endPrbUl.decode(is, false); |
| 320 | if (subCodeLength == totalLength) { |
| 321 | return codeLength; |
| 322 | } |
| 323 | subCodeLength += berTag.decode(is); |
| 324 | } |
| 325 | |
| 326 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 9)) { |
| 327 | subframeBitmaskUl = new SubframeBitmaskUl(); |
| 328 | subCodeLength += subframeBitmaskUl.decode(is, false); |
| 329 | if (subCodeLength == totalLength) { |
| 330 | return codeLength; |
| 331 | } |
| 332 | } |
| 333 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 334 | |
| 335 | |
| 336 | } |
| 337 | |
| 338 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 339 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 340 | encode(os, false); |
| 341 | code = os.getArray(); |
| 342 | } |
| 343 | |
| 344 | public String toString() { |
| 345 | StringBuilder sb = new StringBuilder(); |
| 346 | appendAsString(sb, 0); |
| 347 | return sb.toString(); |
| 348 | } |
| 349 | |
| 350 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 351 | |
| 352 | sb.append("{"); |
| 353 | sb.append("\n"); |
| 354 | for (int i = 0; i < indentLevel + 1; i++) { |
| 355 | sb.append("\t"); |
| 356 | } |
| 357 | if (ecgi != null) { |
| 358 | sb.append("\"ecgi\": "); |
| 359 | ecgi.appendAsString(sb, indentLevel + 1); |
| 360 | } |
| 361 | |
| 362 | if (crnti != null) { |
| 363 | sb.append(",\n"); |
| 364 | for (int i = 0; i < indentLevel + 1; i++) { |
| 365 | sb.append("\t"); |
| 366 | } |
| 367 | sb.append("\"crnti\": "); |
| 368 | crnti.appendAsString(sb, indentLevel + 1); |
| 369 | } |
| 370 | |
| 371 | if (pa != null) { |
| 372 | sb.append(",\n"); |
| 373 | for (int i = 0; i < indentLevel + 1; i++) { |
| 374 | sb.append("\t"); |
| 375 | } |
| 376 | sb.append("\"pa\": "); |
| 377 | pa.appendAsString(sb, indentLevel + 1); |
| 378 | } |
| 379 | |
| 380 | if (startPrbDl != null) { |
| 381 | sb.append(",\n"); |
| 382 | for (int i = 0; i < indentLevel + 1; i++) { |
| 383 | sb.append("\t"); |
| 384 | } |
| 385 | sb.append("\"startPrbDl\": "); |
| 386 | startPrbDl.appendAsString(sb, indentLevel + 1); |
| 387 | } |
| 388 | |
| 389 | if (endPrbDl != null) { |
| 390 | sb.append(",\n"); |
| 391 | for (int i = 0; i < indentLevel + 1; i++) { |
| 392 | sb.append("\t"); |
| 393 | } |
| 394 | sb.append("\"endPrbDl\": "); |
| 395 | endPrbDl.appendAsString(sb, indentLevel + 1); |
| 396 | } |
| 397 | |
| 398 | if (subframeBitmaskDl != null) { |
| 399 | sb.append(",\n"); |
| 400 | for (int i = 0; i < indentLevel + 1; i++) { |
| 401 | sb.append("\t"); |
| 402 | } |
| 403 | sb.append("\"subframeBitmaskDl\": "); |
| 404 | subframeBitmaskDl.appendAsString(sb, indentLevel + 1); |
| 405 | } |
| 406 | |
| 407 | if (p0UePusch != null) { |
| 408 | sb.append(",\n"); |
| 409 | for (int i = 0; i < indentLevel + 1; i++) { |
| 410 | sb.append("\t"); |
| 411 | } |
| 412 | sb.append("\"p0UePusch\": "); |
| 413 | p0UePusch.appendAsString(sb, indentLevel + 1); |
| 414 | } |
| 415 | |
| 416 | if (startPrbUl != null) { |
| 417 | sb.append(",\n"); |
| 418 | for (int i = 0; i < indentLevel + 1; i++) { |
| 419 | sb.append("\t"); |
| 420 | } |
| 421 | sb.append("\"startPrbUl\": "); |
| 422 | startPrbUl.appendAsString(sb, indentLevel + 1); |
| 423 | } |
| 424 | |
| 425 | if (endPrbUl != null) { |
| 426 | sb.append(",\n"); |
| 427 | for (int i = 0; i < indentLevel + 1; i++) { |
| 428 | sb.append("\t"); |
| 429 | } |
| 430 | sb.append("\"endPrbUl\": "); |
| 431 | endPrbUl.appendAsString(sb, indentLevel + 1); |
| 432 | } |
| 433 | |
| 434 | if (subframeBitmaskUl != null) { |
| 435 | sb.append(",\n"); |
| 436 | for (int i = 0; i < indentLevel + 1; i++) { |
| 437 | sb.append("\t"); |
| 438 | } |
| 439 | sb.append("\"subframeBitmaskUl\": "); |
| 440 | subframeBitmaskUl.appendAsString(sb, indentLevel + 1); |
| 441 | } |
| 442 | |
| 443 | sb.append("\n"); |
| 444 | for (int i = 0; i < indentLevel; i++) { |
| 445 | sb.append("\t"); |
| 446 | } |
| 447 | sb.append("}"); |
| 448 | } |
| 449 | |
| 450 | public static class Crnti implements Serializable { |
| 451 | |
| 452 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 453 | private static final long serialVersionUID = 1L; |
| 454 | public byte[] code = null; |
| 455 | private List<CRNTI> seqOf = null; |
| 456 | |
| 457 | public Crnti() { |
| 458 | seqOf = new ArrayList<CRNTI>(); |
| 459 | } |
| 460 | |
| 461 | public Crnti(byte[] code) { |
| 462 | this.code = code; |
| 463 | } |
| 464 | |
| 465 | public List<CRNTI> getCRNTI() { |
| 466 | if (seqOf == null) { |
| 467 | seqOf = new ArrayList<CRNTI>(); |
| 468 | } |
| 469 | return seqOf; |
| 470 | } |
| 471 | |
| 472 | public void addCRNTI(CRNTI crnti) { |
| 473 | seqOf.add(crnti); |
| 474 | } |
| 475 | |
| 476 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 477 | return encode(os, true); |
| 478 | } |
| 479 | |
| 480 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 481 | |
| 482 | if (code != null) { |
| 483 | for (int i = code.length - 1; i >= 0; i--) { |
| 484 | os.write(code[i]); |
| 485 | } |
| 486 | if (withTag) { |
| 487 | return tag.encode(os) + code.length; |
| 488 | } |
| 489 | return code.length; |
| 490 | } |
| 491 | |
| 492 | int codeLength = 0; |
| 493 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 494 | codeLength += seqOf.get(i).encode(os, true); |
| 495 | } |
| 496 | |
| 497 | codeLength += BerLength.encodeLength(os, codeLength); |
| 498 | |
| 499 | if (withTag) { |
| 500 | codeLength += tag.encode(os); |
| 501 | } |
| 502 | |
| 503 | return codeLength; |
| 504 | } |
| 505 | |
| 506 | public int decode(InputStream is) throws IOException { |
| 507 | return decode(is, true); |
| 508 | } |
| 509 | |
| 510 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 511 | int codeLength = 0; |
| 512 | int subCodeLength = 0; |
| 513 | if (withTag) { |
| 514 | codeLength += tag.decodeAndCheck(is); |
| 515 | } |
| 516 | |
| 517 | BerLength length = new BerLength(); |
| 518 | codeLength += length.decode(is); |
| 519 | int totalLength = length.val; |
| 520 | |
| 521 | while (subCodeLength < totalLength) { |
| 522 | CRNTI element = new CRNTI(); |
| 523 | subCodeLength += element.decode(is, true); |
| 524 | seqOf.add(element); |
| 525 | } |
| 526 | if (subCodeLength != totalLength) { |
| 527 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
| 528 | |
| 529 | } |
| 530 | codeLength += subCodeLength; |
| 531 | |
| 532 | return codeLength; |
| 533 | } |
| 534 | |
| 535 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 536 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 537 | encode(os, false); |
| 538 | code = os.getArray(); |
| 539 | } |
| 540 | |
| 541 | public String toString() { |
| 542 | StringBuilder sb = new StringBuilder(); |
| 543 | appendAsString(sb, 0); |
| 544 | return sb.toString(); |
| 545 | } |
| 546 | |
| 547 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 548 | |
| 549 | sb.append("[\n"); |
| 550 | for (int i = 0; i < indentLevel + 1; i++) { |
| 551 | sb.append("\t"); |
| 552 | } |
| 553 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 554 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 555 | } else { |
| 556 | Iterator<CRNTI> it = seqOf.iterator(); |
| 557 | if (it.hasNext()) { |
| 558 | sb.append(it.next()); |
| 559 | while (it.hasNext()) { |
| 560 | sb.append(",\n"); |
| 561 | for (int i = 0; i < indentLevel + 1; i++) { |
| 562 | sb.append("\t"); |
| 563 | } |
| 564 | sb.append(it.next()); |
| 565 | } |
| 566 | } |
| 567 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 568 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 569 | sb.append("\n"); |
| 570 | for (int i = 0; i < indentLevel; i++) { |
| 571 | sb.append("\t"); |
| 572 | } |
| 573 | sb.append("]"); |
| 574 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 575 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 576 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 577 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 578 | public static class Pa implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 579 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 580 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 581 | private static final long serialVersionUID = 1L; |
| 582 | public byte[] code = null; |
| 583 | private List<XICICPA> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 584 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 585 | public Pa() { |
| 586 | seqOf = new ArrayList<XICICPA>(); |
| 587 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 588 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 589 | public Pa(byte[] code) { |
| 590 | this.code = code; |
| 591 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 592 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 593 | public List<XICICPA> getXICICPA() { |
| 594 | if (seqOf == null) { |
| 595 | seqOf = new ArrayList<XICICPA>(); |
| 596 | } |
| 597 | return seqOf; |
| 598 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 599 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 600 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 601 | return encode(os, true); |
| 602 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 603 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 604 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 605 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 606 | if (code != null) { |
| 607 | for (int i = code.length - 1; i >= 0; i--) { |
| 608 | os.write(code[i]); |
| 609 | } |
| 610 | if (withTag) { |
| 611 | return tag.encode(os) + code.length; |
| 612 | } |
| 613 | return code.length; |
| 614 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 615 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 616 | int codeLength = 0; |
| 617 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 618 | codeLength += seqOf.get(i).encode(os, true); |
| 619 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 620 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 621 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 622 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 623 | if (withTag) { |
| 624 | codeLength += tag.encode(os); |
| 625 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 626 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 627 | return codeLength; |
| 628 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 629 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 630 | public int decode(InputStream is) throws IOException { |
| 631 | return decode(is, true); |
| 632 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 633 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 634 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 635 | int codeLength = 0; |
| 636 | int subCodeLength = 0; |
| 637 | if (withTag) { |
| 638 | codeLength += tag.decodeAndCheck(is); |
| 639 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 640 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 641 | BerLength length = new BerLength(); |
| 642 | codeLength += length.decode(is); |
| 643 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 644 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 645 | while (subCodeLength < totalLength) { |
| 646 | XICICPA element = new XICICPA(); |
| 647 | subCodeLength += element.decode(is, true); |
| 648 | seqOf.add(element); |
| 649 | } |
| 650 | if (subCodeLength != totalLength) { |
| 651 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 652 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 653 | } |
| 654 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 655 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 656 | return codeLength; |
| 657 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 658 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 659 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 660 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 661 | encode(os, false); |
| 662 | code = os.getArray(); |
| 663 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 664 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 665 | public String toString() { |
| 666 | StringBuilder sb = new StringBuilder(); |
| 667 | appendAsString(sb, 0); |
| 668 | return sb.toString(); |
| 669 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 670 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 671 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 672 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 673 | sb.append("[\n"); |
| 674 | for (int i = 0; i < indentLevel + 1; i++) { |
| 675 | sb.append("\t"); |
| 676 | } |
| 677 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 678 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 679 | } else { |
| 680 | Iterator<XICICPA> it = seqOf.iterator(); |
| 681 | if (it.hasNext()) { |
| 682 | sb.append(it.next()); |
| 683 | while (it.hasNext()) { |
| 684 | sb.append(",\n"); |
| 685 | for (int i = 0; i < indentLevel + 1; i++) { |
| 686 | sb.append("\t"); |
| 687 | } |
| 688 | sb.append(it.next()); |
| 689 | } |
| 690 | } |
| 691 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 692 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 693 | sb.append("\n"); |
| 694 | for (int i = 0; i < indentLevel; i++) { |
| 695 | sb.append("\t"); |
| 696 | } |
| 697 | sb.append("]"); |
| 698 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 699 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 700 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 701 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 702 | public static class StartPrbDl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 703 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 704 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 705 | private static final long serialVersionUID = 1L; |
| 706 | public byte[] code = null; |
| 707 | private List<BerInteger> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 708 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 709 | public StartPrbDl() { |
| 710 | seqOf = new ArrayList<BerInteger>(); |
| 711 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 712 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 713 | public StartPrbDl(byte[] code) { |
| 714 | this.code = code; |
| 715 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 716 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 717 | public List<BerInteger> getSeqOf() { |
| 718 | return seqOf; |
| 719 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 720 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 721 | public void setSeqOf(List<BerInteger> seqOf) { |
| 722 | this.seqOf = seqOf; |
| 723 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 724 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 725 | public List<BerInteger> getBerInteger() { |
| 726 | if (seqOf == null) { |
| 727 | seqOf = new ArrayList<BerInteger>(); |
| 728 | } |
| 729 | return seqOf; |
| 730 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 731 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 732 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 733 | return encode(os, true); |
| 734 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 735 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 736 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 737 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 738 | if (code != null) { |
| 739 | for (int i = code.length - 1; i >= 0; i--) { |
| 740 | os.write(code[i]); |
| 741 | } |
| 742 | if (withTag) { |
| 743 | return tag.encode(os) + code.length; |
| 744 | } |
| 745 | return code.length; |
| 746 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 747 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 748 | int codeLength = 0; |
| 749 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 750 | codeLength += seqOf.get(i).encode(os, true); |
| 751 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 752 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 753 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 754 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 755 | if (withTag) { |
| 756 | codeLength += tag.encode(os); |
| 757 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 758 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 759 | return codeLength; |
| 760 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 761 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 762 | public int decode(InputStream is) throws IOException { |
| 763 | return decode(is, true); |
| 764 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 765 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 766 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 767 | int codeLength = 0; |
| 768 | int subCodeLength = 0; |
| 769 | if (withTag) { |
| 770 | codeLength += tag.decodeAndCheck(is); |
| 771 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 772 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 773 | BerLength length = new BerLength(); |
| 774 | codeLength += length.decode(is); |
| 775 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 776 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 777 | while (subCodeLength < totalLength) { |
| 778 | BerInteger element = new BerInteger(); |
| 779 | subCodeLength += element.decode(is, true); |
| 780 | seqOf.add(element); |
| 781 | } |
| 782 | if (subCodeLength != totalLength) { |
| 783 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 784 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 785 | } |
| 786 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 787 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 788 | return codeLength; |
| 789 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 790 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 791 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 792 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 793 | encode(os, false); |
| 794 | code = os.getArray(); |
| 795 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 796 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 797 | public String toString() { |
| 798 | StringBuilder sb = new StringBuilder(); |
| 799 | appendAsString(sb, 0); |
| 800 | return sb.toString(); |
| 801 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 802 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 803 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 804 | |
| 805 | sb.append("[\n"); |
| 806 | for (int i = 0; i < indentLevel + 1; i++) { |
| 807 | sb.append("\t"); |
| 808 | } |
| 809 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 810 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 811 | } else { |
| 812 | Iterator<BerInteger> it = seqOf.iterator(); |
| 813 | if (it.hasNext()) { |
| 814 | sb.append(it.next()); |
| 815 | while (it.hasNext()) { |
| 816 | sb.append(",\n"); |
| 817 | for (int i = 0; i < indentLevel + 1; i++) { |
| 818 | sb.append("\t"); |
| 819 | } |
| 820 | sb.append(it.next()); |
| 821 | } |
| 822 | } |
| 823 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 824 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 825 | sb.append("\n"); |
| 826 | for (int i = 0; i < indentLevel; i++) { |
| 827 | sb.append("\t"); |
| 828 | } |
| 829 | sb.append("]"); |
| 830 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 831 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 832 | public void addBerInteger(BerInteger berInteger) { |
| 833 | seqOf.add(berInteger); |
| 834 | } |
| 835 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 836 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 837 | public static class EndPrbDl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 838 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 839 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 840 | private static final long serialVersionUID = 1L; |
| 841 | public byte[] code = null; |
| 842 | private List<BerInteger> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 843 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 844 | public EndPrbDl() { |
| 845 | seqOf = new ArrayList<BerInteger>(); |
| 846 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 847 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 848 | public EndPrbDl(byte[] code) { |
| 849 | this.code = code; |
| 850 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 851 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 852 | public List<BerInteger> getBerInteger() { |
| 853 | if (seqOf == null) { |
| 854 | seqOf = new ArrayList<BerInteger>(); |
| 855 | } |
| 856 | return seqOf; |
| 857 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 858 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 859 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 860 | return encode(os, true); |
| 861 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 862 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 863 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 864 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 865 | if (code != null) { |
| 866 | for (int i = code.length - 1; i >= 0; i--) { |
| 867 | os.write(code[i]); |
| 868 | } |
| 869 | if (withTag) { |
| 870 | return tag.encode(os) + code.length; |
| 871 | } |
| 872 | return code.length; |
| 873 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 874 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 875 | int codeLength = 0; |
| 876 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 877 | codeLength += seqOf.get(i).encode(os, true); |
| 878 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 879 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 880 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 881 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 882 | if (withTag) { |
| 883 | codeLength += tag.encode(os); |
| 884 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 885 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 886 | return codeLength; |
| 887 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 888 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 889 | public int decode(InputStream is) throws IOException { |
| 890 | return decode(is, true); |
| 891 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 892 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 893 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 894 | int codeLength = 0; |
| 895 | int subCodeLength = 0; |
| 896 | if (withTag) { |
| 897 | codeLength += tag.decodeAndCheck(is); |
| 898 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 899 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 900 | BerLength length = new BerLength(); |
| 901 | codeLength += length.decode(is); |
| 902 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 903 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 904 | while (subCodeLength < totalLength) { |
| 905 | BerInteger element = new BerInteger(); |
| 906 | subCodeLength += element.decode(is, true); |
| 907 | seqOf.add(element); |
| 908 | } |
| 909 | if (subCodeLength != totalLength) { |
| 910 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 911 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 912 | } |
| 913 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 914 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 915 | return codeLength; |
| 916 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 917 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 918 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 919 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 920 | encode(os, false); |
| 921 | code = os.getArray(); |
| 922 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 923 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 924 | public String toString() { |
| 925 | StringBuilder sb = new StringBuilder(); |
| 926 | appendAsString(sb, 0); |
| 927 | return sb.toString(); |
| 928 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 929 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 930 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 931 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 932 | sb.append("[\n"); |
| 933 | for (int i = 0; i < indentLevel + 1; i++) { |
| 934 | sb.append("\t"); |
| 935 | } |
| 936 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 937 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 938 | } else { |
| 939 | Iterator<BerInteger> it = seqOf.iterator(); |
| 940 | if (it.hasNext()) { |
| 941 | sb.append(it.next()); |
| 942 | while (it.hasNext()) { |
| 943 | sb.append(",\n"); |
| 944 | for (int i = 0; i < indentLevel + 1; i++) { |
| 945 | sb.append("\t"); |
| 946 | } |
| 947 | sb.append(it.next()); |
| 948 | } |
| 949 | } |
| 950 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 951 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 952 | sb.append("\n"); |
| 953 | for (int i = 0; i < indentLevel; i++) { |
| 954 | sb.append("\t"); |
| 955 | } |
| 956 | sb.append("]"); |
| 957 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 958 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 959 | public void addBerInteger(BerInteger berInteger) { |
| 960 | seqOf.add(berInteger); |
| 961 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 962 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 963 | public List<BerInteger> getSeqOf() { |
| 964 | return seqOf; |
| 965 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 966 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 967 | public void setSeqOf(List<BerInteger> seqOf) { |
| 968 | this.seqOf = seqOf; |
| 969 | } |
| 970 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 971 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 972 | public static class SubframeBitmaskDl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 973 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 974 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 975 | private static final long serialVersionUID = 1L; |
| 976 | public byte[] code = null; |
| 977 | private List<BerBitString> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 978 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 979 | public SubframeBitmaskDl() { |
| 980 | seqOf = new ArrayList<BerBitString>(); |
| 981 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 982 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 983 | public SubframeBitmaskDl(byte[] code) { |
| 984 | this.code = code; |
| 985 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 986 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 987 | public List<BerBitString> getBerBitString() { |
| 988 | if (seqOf == null) { |
| 989 | seqOf = new ArrayList<BerBitString>(); |
| 990 | } |
| 991 | return seqOf; |
| 992 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 993 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 994 | public void addBerBitString(BerBitString berBitString) { |
| 995 | seqOf.add(berBitString); |
| 996 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 997 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 998 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 999 | return encode(os, true); |
| 1000 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1001 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1002 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1003 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1004 | if (code != null) { |
| 1005 | for (int i = code.length - 1; i >= 0; i--) { |
| 1006 | os.write(code[i]); |
| 1007 | } |
| 1008 | if (withTag) { |
| 1009 | return tag.encode(os) + code.length; |
| 1010 | } |
| 1011 | return code.length; |
| 1012 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1013 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1014 | int codeLength = 0; |
| 1015 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 1016 | codeLength += seqOf.get(i).encode(os, true); |
| 1017 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1018 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1019 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1020 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1021 | if (withTag) { |
| 1022 | codeLength += tag.encode(os); |
| 1023 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1024 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1025 | return codeLength; |
| 1026 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1027 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1028 | public int decode(InputStream is) throws IOException { |
| 1029 | return decode(is, true); |
| 1030 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1031 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1032 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 1033 | int codeLength = 0; |
| 1034 | int subCodeLength = 0; |
| 1035 | if (withTag) { |
| 1036 | codeLength += tag.decodeAndCheck(is); |
| 1037 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1038 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1039 | BerLength length = new BerLength(); |
| 1040 | codeLength += length.decode(is); |
| 1041 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1042 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1043 | while (subCodeLength < totalLength) { |
| 1044 | BerBitString element = new BerBitString(); |
| 1045 | subCodeLength += element.decode(is, true); |
| 1046 | seqOf.add(element); |
| 1047 | } |
| 1048 | if (subCodeLength != totalLength) { |
| 1049 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1050 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1051 | } |
| 1052 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1053 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1054 | return codeLength; |
| 1055 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1056 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1057 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 1058 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 1059 | encode(os, false); |
| 1060 | code = os.getArray(); |
| 1061 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1062 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1063 | public String toString() { |
| 1064 | StringBuilder sb = new StringBuilder(); |
| 1065 | appendAsString(sb, 0); |
| 1066 | return sb.toString(); |
| 1067 | } |
| 1068 | |
| 1069 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 1070 | |
| 1071 | sb.append("[\n"); |
| 1072 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1073 | sb.append("\t"); |
| 1074 | } |
| 1075 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1076 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1077 | } else { |
| 1078 | Iterator<BerBitString> it = seqOf.iterator(); |
| 1079 | if (it.hasNext()) { |
| 1080 | sb.append("\"" + it.next() + "\""); |
| 1081 | while (it.hasNext()) { |
| 1082 | sb.append(",\n"); |
| 1083 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1084 | sb.append("\t"); |
| 1085 | } |
| 1086 | sb.append("\"" + it.next() + "\""); |
| 1087 | } |
| 1088 | } |
| 1089 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1090 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1091 | sb.append("\n"); |
| 1092 | for (int i = 0; i < indentLevel; i++) { |
| 1093 | sb.append("\t"); |
| 1094 | } |
| 1095 | sb.append("]"); |
| 1096 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1097 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1098 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1099 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1100 | public static class P0UePusch implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1101 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1102 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 1103 | private static final long serialVersionUID = 1L; |
| 1104 | public byte[] code = null; |
| 1105 | private List<BerInteger> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1106 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1107 | public P0UePusch() { |
| 1108 | seqOf = new ArrayList<BerInteger>(); |
| 1109 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1110 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1111 | public P0UePusch(byte[] code) { |
| 1112 | this.code = code; |
| 1113 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1114 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1115 | public List<BerInteger> getBerInteger() { |
| 1116 | if (seqOf == null) { |
| 1117 | seqOf = new ArrayList<BerInteger>(); |
| 1118 | } |
| 1119 | return seqOf; |
| 1120 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1121 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1122 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 1123 | return encode(os, true); |
| 1124 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1125 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1126 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1127 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1128 | if (code != null) { |
| 1129 | for (int i = code.length - 1; i >= 0; i--) { |
| 1130 | os.write(code[i]); |
| 1131 | } |
| 1132 | if (withTag) { |
| 1133 | return tag.encode(os) + code.length; |
| 1134 | } |
| 1135 | return code.length; |
| 1136 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1137 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1138 | int codeLength = 0; |
| 1139 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 1140 | codeLength += seqOf.get(i).encode(os, true); |
| 1141 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1142 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1143 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1144 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1145 | if (withTag) { |
| 1146 | codeLength += tag.encode(os); |
| 1147 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1148 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1149 | return codeLength; |
| 1150 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1151 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1152 | public int decode(InputStream is) throws IOException { |
| 1153 | return decode(is, true); |
| 1154 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1155 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1156 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 1157 | int codeLength = 0; |
| 1158 | int subCodeLength = 0; |
| 1159 | if (withTag) { |
| 1160 | codeLength += tag.decodeAndCheck(is); |
| 1161 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1162 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1163 | BerLength length = new BerLength(); |
| 1164 | codeLength += length.decode(is); |
| 1165 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1166 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1167 | while (subCodeLength < totalLength) { |
| 1168 | BerInteger element = new BerInteger(); |
| 1169 | subCodeLength += element.decode(is, true); |
| 1170 | seqOf.add(element); |
| 1171 | } |
| 1172 | if (subCodeLength != totalLength) { |
| 1173 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1174 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1175 | } |
| 1176 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1177 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1178 | return codeLength; |
| 1179 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1180 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1181 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 1182 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 1183 | encode(os, false); |
| 1184 | code = os.getArray(); |
| 1185 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1186 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1187 | public String toString() { |
| 1188 | StringBuilder sb = new StringBuilder(); |
| 1189 | appendAsString(sb, 0); |
| 1190 | return sb.toString(); |
| 1191 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1192 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1193 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1194 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1195 | sb.append("[\n"); |
| 1196 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1197 | sb.append("\t"); |
| 1198 | } |
| 1199 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1200 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1201 | } else { |
| 1202 | Iterator<BerInteger> it = seqOf.iterator(); |
| 1203 | if (it.hasNext()) { |
| 1204 | sb.append(it.next()); |
| 1205 | while (it.hasNext()) { |
| 1206 | sb.append(",\n"); |
| 1207 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1208 | sb.append("\t"); |
| 1209 | } |
| 1210 | sb.append(it.next()); |
| 1211 | } |
| 1212 | } |
| 1213 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1214 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1215 | sb.append("\n"); |
| 1216 | for (int i = 0; i < indentLevel; i++) { |
| 1217 | sb.append("\t"); |
| 1218 | } |
| 1219 | sb.append("]"); |
| 1220 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1221 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1222 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1223 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1224 | public static class StartPrbUl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1225 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1226 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 1227 | private static final long serialVersionUID = 1L; |
| 1228 | public byte[] code = null; |
| 1229 | private List<BerInteger> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1230 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1231 | public StartPrbUl() { |
| 1232 | seqOf = new ArrayList<BerInteger>(); |
| 1233 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1234 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1235 | public StartPrbUl(byte[] code) { |
| 1236 | this.code = code; |
| 1237 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1238 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1239 | public List<BerInteger> getBerInteger() { |
| 1240 | if (seqOf == null) { |
| 1241 | seqOf = new ArrayList<BerInteger>(); |
| 1242 | } |
| 1243 | return seqOf; |
| 1244 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1245 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1246 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 1247 | return encode(os, true); |
| 1248 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1249 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1250 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1251 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1252 | if (code != null) { |
| 1253 | for (int i = code.length - 1; i >= 0; i--) { |
| 1254 | os.write(code[i]); |
| 1255 | } |
| 1256 | if (withTag) { |
| 1257 | return tag.encode(os) + code.length; |
| 1258 | } |
| 1259 | return code.length; |
| 1260 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1261 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1262 | int codeLength = 0; |
| 1263 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 1264 | codeLength += seqOf.get(i).encode(os, true); |
| 1265 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1266 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1267 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1268 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1269 | if (withTag) { |
| 1270 | codeLength += tag.encode(os); |
| 1271 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1272 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1273 | return codeLength; |
| 1274 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1275 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1276 | public int decode(InputStream is) throws IOException { |
| 1277 | return decode(is, true); |
| 1278 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1279 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1280 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 1281 | int codeLength = 0; |
| 1282 | int subCodeLength = 0; |
| 1283 | if (withTag) { |
| 1284 | codeLength += tag.decodeAndCheck(is); |
| 1285 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1286 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1287 | BerLength length = new BerLength(); |
| 1288 | codeLength += length.decode(is); |
| 1289 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1290 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1291 | while (subCodeLength < totalLength) { |
| 1292 | BerInteger element = new BerInteger(); |
| 1293 | subCodeLength += element.decode(is, true); |
| 1294 | seqOf.add(element); |
| 1295 | } |
| 1296 | if (subCodeLength != totalLength) { |
| 1297 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1298 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1299 | } |
| 1300 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1301 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1302 | return codeLength; |
| 1303 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1304 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1305 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 1306 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 1307 | encode(os, false); |
| 1308 | code = os.getArray(); |
| 1309 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1310 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1311 | public String toString() { |
| 1312 | StringBuilder sb = new StringBuilder(); |
| 1313 | appendAsString(sb, 0); |
| 1314 | return sb.toString(); |
| 1315 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1316 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1317 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1318 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1319 | sb.append("[\n"); |
| 1320 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1321 | sb.append("\t"); |
| 1322 | } |
| 1323 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1324 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | Iterator<BerInteger> it = seqOf.iterator(); |
| 1327 | if (it.hasNext()) { |
| 1328 | sb.append(it.next()); |
| 1329 | while (it.hasNext()) { |
| 1330 | sb.append(",\n"); |
| 1331 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1332 | sb.append("\t"); |
| 1333 | } |
| 1334 | sb.append(it.next()); |
| 1335 | } |
| 1336 | } |
| 1337 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1338 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1339 | sb.append("\n"); |
| 1340 | for (int i = 0; i < indentLevel; i++) { |
| 1341 | sb.append("\t"); |
| 1342 | } |
| 1343 | sb.append("]"); |
| 1344 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1345 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1346 | public void addBerInteger(BerInteger berInteger) { |
| 1347 | seqOf.add(berInteger); |
| 1348 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1349 | |
| 1350 | public List<BerInteger> getSeqOf() { |
| 1351 | return seqOf; |
| 1352 | } |
| 1353 | |
| 1354 | public void setSeqOf(List<BerInteger> seqOf) { |
| 1355 | this.seqOf = seqOf; |
| 1356 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1357 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1358 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1359 | public static class EndPrbUl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1360 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1361 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 1362 | private static final long serialVersionUID = 1L; |
| 1363 | public byte[] code = null; |
| 1364 | private List<BerInteger> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1365 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1366 | public EndPrbUl() { |
| 1367 | seqOf = new ArrayList<BerInteger>(); |
| 1368 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1369 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1370 | public EndPrbUl(byte[] code) { |
| 1371 | this.code = code; |
| 1372 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1373 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1374 | public List<BerInteger> getBerInteger() { |
| 1375 | if (seqOf == null) { |
| 1376 | seqOf = new ArrayList<BerInteger>(); |
| 1377 | } |
| 1378 | return seqOf; |
| 1379 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1380 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1381 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 1382 | return encode(os, true); |
| 1383 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1384 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1385 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1386 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1387 | if (code != null) { |
| 1388 | for (int i = code.length - 1; i >= 0; i--) { |
| 1389 | os.write(code[i]); |
| 1390 | } |
| 1391 | if (withTag) { |
| 1392 | return tag.encode(os) + code.length; |
| 1393 | } |
| 1394 | return code.length; |
| 1395 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1396 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1397 | int codeLength = 0; |
| 1398 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 1399 | codeLength += seqOf.get(i).encode(os, true); |
| 1400 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1401 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1402 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1403 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1404 | if (withTag) { |
| 1405 | codeLength += tag.encode(os); |
| 1406 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1407 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1408 | return codeLength; |
| 1409 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1410 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1411 | public int decode(InputStream is) throws IOException { |
| 1412 | return decode(is, true); |
| 1413 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1414 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1415 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 1416 | int codeLength = 0; |
| 1417 | int subCodeLength = 0; |
| 1418 | if (withTag) { |
| 1419 | codeLength += tag.decodeAndCheck(is); |
| 1420 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1421 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1422 | BerLength length = new BerLength(); |
| 1423 | codeLength += length.decode(is); |
| 1424 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1425 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1426 | while (subCodeLength < totalLength) { |
| 1427 | BerInteger element = new BerInteger(); |
| 1428 | subCodeLength += element.decode(is, true); |
| 1429 | seqOf.add(element); |
| 1430 | } |
| 1431 | if (subCodeLength != totalLength) { |
| 1432 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1433 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1434 | } |
| 1435 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1436 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1437 | return codeLength; |
| 1438 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1439 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1440 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 1441 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 1442 | encode(os, false); |
| 1443 | code = os.getArray(); |
| 1444 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1445 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1446 | public String toString() { |
| 1447 | StringBuilder sb = new StringBuilder(); |
| 1448 | appendAsString(sb, 0); |
| 1449 | return sb.toString(); |
| 1450 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1451 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1452 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1453 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1454 | sb.append("[\n"); |
| 1455 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1456 | sb.append("\t"); |
| 1457 | } |
| 1458 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1459 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1460 | } else { |
| 1461 | Iterator<BerInteger> it = seqOf.iterator(); |
| 1462 | if (it.hasNext()) { |
| 1463 | sb.append(it.next()); |
| 1464 | while (it.hasNext()) { |
| 1465 | sb.append(",\n"); |
| 1466 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1467 | sb.append("\t"); |
| 1468 | } |
| 1469 | sb.append(it.next()); |
| 1470 | } |
| 1471 | } |
| 1472 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1473 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1474 | sb.append("\n"); |
| 1475 | for (int i = 0; i < indentLevel; i++) { |
| 1476 | sb.append("\t"); |
| 1477 | } |
| 1478 | sb.append("]"); |
| 1479 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1480 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1481 | public void addBerInteger(BerInteger berInteger) { |
| 1482 | seqOf.add(berInteger); |
| 1483 | } |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1484 | |
| 1485 | public List<BerInteger> getSeqOf() { |
| 1486 | return seqOf; |
| 1487 | } |
| 1488 | |
| 1489 | public void setSeqOf(List<BerInteger> seqOf) { |
| 1490 | this.seqOf = seqOf; |
| 1491 | } |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1492 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1493 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1494 | public static class SubframeBitmaskUl implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1495 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1496 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 1497 | private static final long serialVersionUID = 1L; |
| 1498 | public byte[] code = null; |
| 1499 | private List<BerBitString> seqOf = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1500 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1501 | public SubframeBitmaskUl() { |
| 1502 | seqOf = new ArrayList<BerBitString>(); |
| 1503 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1504 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1505 | public SubframeBitmaskUl(byte[] code) { |
| 1506 | this.code = code; |
| 1507 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1508 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1509 | public List<BerBitString> getBerBitString() { |
| 1510 | if (seqOf == null) { |
| 1511 | seqOf = new ArrayList<BerBitString>(); |
| 1512 | } |
| 1513 | return seqOf; |
| 1514 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1515 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1516 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 1517 | return encode(os, true); |
| 1518 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1519 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1520 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1521 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1522 | if (code != null) { |
| 1523 | for (int i = code.length - 1; i >= 0; i--) { |
| 1524 | os.write(code[i]); |
| 1525 | } |
| 1526 | if (withTag) { |
| 1527 | return tag.encode(os) + code.length; |
| 1528 | } |
| 1529 | return code.length; |
| 1530 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1531 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1532 | int codeLength = 0; |
| 1533 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 1534 | codeLength += seqOf.get(i).encode(os, true); |
| 1535 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1536 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1537 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1538 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1539 | if (withTag) { |
| 1540 | codeLength += tag.encode(os); |
| 1541 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1542 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1543 | return codeLength; |
| 1544 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1545 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1546 | public int decode(InputStream is) throws IOException { |
| 1547 | return decode(is, true); |
| 1548 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1549 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1550 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 1551 | int codeLength = 0; |
| 1552 | int subCodeLength = 0; |
| 1553 | if (withTag) { |
| 1554 | codeLength += tag.decodeAndCheck(is); |
| 1555 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1556 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1557 | BerLength length = new BerLength(); |
| 1558 | codeLength += length.decode(is); |
| 1559 | int totalLength = length.val; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1560 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1561 | while (subCodeLength < totalLength) { |
| 1562 | BerBitString element = new BerBitString(); |
| 1563 | subCodeLength += element.decode(is, true); |
| 1564 | seqOf.add(element); |
| 1565 | } |
| 1566 | if (subCodeLength != totalLength) { |
| 1567 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1568 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1569 | } |
| 1570 | codeLength += subCodeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1571 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1572 | return codeLength; |
| 1573 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1574 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1575 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 1576 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 1577 | encode(os, false); |
| 1578 | code = os.getArray(); |
| 1579 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1580 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1581 | public String toString() { |
| 1582 | StringBuilder sb = new StringBuilder(); |
| 1583 | appendAsString(sb, 0); |
| 1584 | return sb.toString(); |
| 1585 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1586 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1587 | public void appendAsString(StringBuilder sb, int indentLevel) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1588 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1589 | sb.append("[\n"); |
| 1590 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1591 | sb.append("\t"); |
| 1592 | } |
| 1593 | if (seqOf == null) { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1594 | // sb.append("null"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1595 | } else { |
| 1596 | Iterator<BerBitString> it = seqOf.iterator(); |
| 1597 | if (it.hasNext()) { |
| 1598 | sb.append(it.next()); |
| 1599 | while (it.hasNext()) { |
| 1600 | sb.append(",\n"); |
| 1601 | for (int i = 0; i < indentLevel + 1; i++) { |
| 1602 | sb.append("\t"); |
| 1603 | } |
| 1604 | sb.append(it.next()); |
| 1605 | } |
| 1606 | } |
| 1607 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1608 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1609 | sb.append("\n"); |
| 1610 | for (int i = 0; i < indentLevel; i++) { |
| 1611 | sb.append("\t"); |
| 1612 | } |
| 1613 | sb.append("]"); |
| 1614 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1615 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1616 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1617 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1618 | public static XrancPdu constructPacket(RRMConfig config) { |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1619 | XrancPduBody body = new XrancPduBody(); |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1620 | body.setRRMConfig(config); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1621 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1622 | BerUTF8String ver = null; |
| 1623 | try { |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1624 | ver = new BerUTF8String("3"); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1625 | } catch (UnsupportedEncodingException e) { |
| 1626 | e.printStackTrace(); |
| 1627 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1628 | |
slowr | 8ddc2b1 | 2017-08-14 14:13:38 -0700 | [diff] [blame] | 1629 | XrancApiID apiID = new XrancApiID(29); |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1630 | XrancPduHdr hdr = new XrancPduHdr(); |
| 1631 | hdr.setVer(ver); |
| 1632 | hdr.setApiId(apiID); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1633 | |
slowr | 67d05e4 | 2017-08-11 20:37:22 -0700 | [diff] [blame] | 1634 | XrancPdu pdu = new XrancPdu(); |
| 1635 | pdu.setHdr(hdr); |
| 1636 | pdu.setBody(body); |
| 1637 | return pdu; |
| 1638 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1639 | |
| 1640 | } |
| 1641 | |