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