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 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 8 | import org.onosproject.xran.codecs.api.CRNTI; |
| 9 | import org.onosproject.xran.codecs.api.ECGI; |
| 10 | import org.onosproject.xran.codecs.api.HOFailureCause; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 11 | import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream; |
| 12 | import org.onosproject.xran.codecs.ber.BerLength; |
| 13 | import org.onosproject.xran.codecs.ber.BerTag; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 14 | |
| 15 | import java.io.IOException; |
| 16 | import java.io.InputStream; |
| 17 | import java.io.Serializable; |
| 18 | |
| 19 | public class HOFailure implements Serializable { |
| 20 | |
| 21 | private static final long serialVersionUID = 1L; |
| 22 | |
| 23 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 24 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 25 | @JsonIgnore |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 26 | public byte[] code = null; |
| 27 | private CRNTI crnti = null; |
| 28 | private ECGI ecgi = null; |
| 29 | private HOFailureCause cause = null; |
| 30 | |
| 31 | public HOFailure() { |
| 32 | } |
| 33 | |
| 34 | public HOFailure(byte[] code) { |
| 35 | this.code = code; |
| 36 | } |
| 37 | |
| 38 | public void setCrnti(CRNTI crnti) { |
| 39 | this.crnti = crnti; |
| 40 | } |
| 41 | |
| 42 | public CRNTI getCrnti() { |
| 43 | return crnti; |
| 44 | } |
| 45 | |
| 46 | public void setEcgi(ECGI ecgi) { |
| 47 | this.ecgi = ecgi; |
| 48 | } |
| 49 | |
| 50 | public ECGI getEcgi() { |
| 51 | return ecgi; |
| 52 | } |
| 53 | |
| 54 | public void setCause(HOFailureCause cause) { |
| 55 | this.cause = cause; |
| 56 | } |
| 57 | |
| 58 | public HOFailureCause getCause() { |
| 59 | return cause; |
| 60 | } |
| 61 | |
| 62 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 63 | return encode(os, true); |
| 64 | } |
| 65 | |
| 66 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 67 | |
| 68 | if (code != null) { |
| 69 | for (int i = code.length - 1; i >= 0; i--) { |
| 70 | os.write(code[i]); |
| 71 | } |
| 72 | if (withTag) { |
| 73 | return tag.encode(os) + code.length; |
| 74 | } |
| 75 | return code.length; |
| 76 | } |
| 77 | |
| 78 | int codeLength = 0; |
| 79 | codeLength += cause.encode(os, false); |
| 80 | // write tag: CONTEXT_CLASS, PRIMITIVE, 2 |
| 81 | os.write(0x82); |
| 82 | codeLength += 1; |
| 83 | |
| 84 | codeLength += ecgi.encode(os, false); |
| 85 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 86 | os.write(0xA1); |
| 87 | codeLength += 1; |
| 88 | |
| 89 | codeLength += crnti.encode(os, false); |
| 90 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 91 | os.write(0x80); |
| 92 | codeLength += 1; |
| 93 | |
| 94 | codeLength += BerLength.encodeLength(os, codeLength); |
| 95 | |
| 96 | if (withTag) { |
| 97 | codeLength += tag.encode(os); |
| 98 | } |
| 99 | |
| 100 | return codeLength; |
| 101 | |
| 102 | } |
| 103 | |
| 104 | public int decode(InputStream is) throws IOException { |
| 105 | return decode(is, true); |
| 106 | } |
| 107 | |
| 108 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 109 | int codeLength = 0; |
| 110 | int subCodeLength = 0; |
| 111 | BerTag berTag = new BerTag(); |
| 112 | |
| 113 | if (withTag) { |
| 114 | codeLength += tag.decodeAndCheck(is); |
| 115 | } |
| 116 | |
| 117 | BerLength length = new BerLength(); |
| 118 | codeLength += length.decode(is); |
| 119 | |
| 120 | int totalLength = length.val; |
| 121 | codeLength += totalLength; |
| 122 | |
| 123 | subCodeLength += berTag.decode(is); |
| 124 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 125 | crnti = new CRNTI(); |
| 126 | subCodeLength += crnti.decode(is, false); |
| 127 | subCodeLength += berTag.decode(is); |
| 128 | } |
| 129 | else { |
| 130 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 131 | } |
| 132 | |
| 133 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 134 | ecgi = new ECGI(); |
| 135 | subCodeLength += ecgi.decode(is, false); |
| 136 | subCodeLength += berTag.decode(is); |
| 137 | } |
| 138 | else { |
| 139 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 140 | } |
| 141 | |
| 142 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 2)) { |
| 143 | cause = new HOFailureCause(); |
| 144 | subCodeLength += cause.decode(is, false); |
| 145 | if (subCodeLength == totalLength) { |
| 146 | return codeLength; |
| 147 | } |
| 148 | } |
| 149 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 150 | |
| 151 | |
| 152 | } |
| 153 | |
| 154 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 155 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 156 | encode(os, false); |
| 157 | code = os.getArray(); |
| 158 | } |
| 159 | |
| 160 | public String toString() { |
| 161 | StringBuilder sb = new StringBuilder(); |
| 162 | appendAsString(sb, 0); |
| 163 | return sb.toString(); |
| 164 | } |
| 165 | |
| 166 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 167 | |
| 168 | sb.append("{"); |
| 169 | sb.append("\n"); |
| 170 | for (int i = 0; i < indentLevel + 1; i++) { |
| 171 | sb.append("\t"); |
| 172 | } |
| 173 | if (crnti != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 174 | sb.append("crnti: ").append(crnti); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | sb.append(",\n"); |
| 178 | for (int i = 0; i < indentLevel + 1; i++) { |
| 179 | sb.append("\t"); |
| 180 | } |
| 181 | if (ecgi != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 182 | sb.append("ecgi: "); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 183 | ecgi.appendAsString(sb, indentLevel + 1); |
| 184 | } |
| 185 | |
| 186 | sb.append(",\n"); |
| 187 | for (int i = 0; i < indentLevel + 1; i++) { |
| 188 | sb.append("\t"); |
| 189 | } |
| 190 | if (cause != null) { |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 191 | sb.append("cause: ").append(cause); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | sb.append("\n"); |
| 195 | for (int i = 0; i < indentLevel; i++) { |
| 196 | sb.append("\t"); |
| 197 | } |
| 198 | sb.append("}"); |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |