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 org.onosproject.xran.codecs.ber.*; |
| 19 | import org.onosproject.xran.codecs.ber.types.*; |
| 20 | import org.onosproject.xran.codecs.ber.types.string.*; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 21 | |
| 22 | |
| 23 | public class ERABResponseItem implements Serializable { |
| 24 | |
| 25 | private static final long serialVersionUID = 1L; |
| 26 | |
| 27 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 28 | |
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 ERABID id = null; |
| 32 | private ERABDecision decision = null; |
| 33 | |
| 34 | public ERABResponseItem() { |
| 35 | } |
| 36 | |
| 37 | public ERABResponseItem(byte[] code) { |
| 38 | this.code = code; |
| 39 | } |
| 40 | |
| 41 | public void setId(ERABID id) { |
| 42 | this.id = id; |
| 43 | } |
| 44 | |
| 45 | public ERABID getId() { |
| 46 | return id; |
| 47 | } |
| 48 | |
| 49 | public void setDecision(ERABDecision decision) { |
| 50 | this.decision = decision; |
| 51 | } |
| 52 | |
| 53 | public ERABDecision getDecision() { |
| 54 | return decision; |
| 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 | codeLength += decision.encode(os, false); |
| 75 | // write tag: CONTEXT_CLASS, PRIMITIVE, 1 |
| 76 | os.write(0x81); |
| 77 | codeLength += 1; |
| 78 | |
| 79 | codeLength += id.encode(os, false); |
| 80 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 81 | os.write(0x80); |
| 82 | codeLength += 1; |
| 83 | |
| 84 | codeLength += BerLength.encodeLength(os, codeLength); |
| 85 | |
| 86 | if (withTag) { |
| 87 | codeLength += tag.encode(os); |
| 88 | } |
| 89 | |
| 90 | return codeLength; |
| 91 | |
| 92 | } |
| 93 | |
| 94 | public int decode(InputStream is) throws IOException { |
| 95 | return decode(is, true); |
| 96 | } |
| 97 | |
| 98 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 99 | int codeLength = 0; |
| 100 | int subCodeLength = 0; |
| 101 | BerTag berTag = new BerTag(); |
| 102 | |
| 103 | if (withTag) { |
| 104 | codeLength += tag.decodeAndCheck(is); |
| 105 | } |
| 106 | |
| 107 | BerLength length = new BerLength(); |
| 108 | codeLength += length.decode(is); |
| 109 | |
| 110 | int totalLength = length.val; |
| 111 | codeLength += totalLength; |
| 112 | |
| 113 | subCodeLength += berTag.decode(is); |
| 114 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 115 | id = new ERABID(); |
| 116 | subCodeLength += id.decode(is, false); |
| 117 | subCodeLength += berTag.decode(is); |
| 118 | } |
| 119 | else { |
| 120 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 121 | } |
| 122 | |
| 123 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { |
| 124 | decision = new ERABDecision(); |
| 125 | subCodeLength += decision.decode(is, false); |
| 126 | if (subCodeLength == totalLength) { |
| 127 | return codeLength; |
| 128 | } |
| 129 | } |
| 130 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 131 | |
| 132 | |
| 133 | } |
| 134 | |
| 135 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 136 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 137 | encode(os, false); |
| 138 | code = os.getArray(); |
| 139 | } |
| 140 | |
| 141 | public String toString() { |
| 142 | StringBuilder sb = new StringBuilder(); |
| 143 | appendAsString(sb, 0); |
| 144 | return sb.toString(); |
| 145 | } |
| 146 | |
| 147 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 148 | |
| 149 | sb.append("{"); |
| 150 | sb.append("\n"); |
| 151 | for (int i = 0; i < indentLevel + 1; i++) { |
| 152 | sb.append("\t"); |
| 153 | } |
| 154 | if (id != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 155 | sb.append("id: ").append(id); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | sb.append(",\n"); |
| 159 | for (int i = 0; i < indentLevel + 1; i++) { |
| 160 | sb.append("\t"); |
| 161 | } |
| 162 | if (decision != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 163 | sb.append("decision: ").append(decision); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | sb.append("\n"); |
| 167 | for (int i = 0; i < indentLevel; i++) { |
| 168 | sb.append("\t"); |
| 169 | } |
| 170 | sb.append("}"); |
| 171 | } |
| 172 | |
| 173 | } |
| 174 | |