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.openmuc.jasn1.ber.BerByteArrayOutputStream; |
| 8 | import org.openmuc.jasn1.ber.BerLength; |
| 9 | import org.openmuc.jasn1.ber.BerTag; |
| 10 | |
| 11 | import java.io.IOException; |
| 12 | import java.io.InputStream; |
| 13 | import java.io.Serializable; |
| 14 | |
| 15 | public class XrancPdu implements Serializable { |
| 16 | |
| 17 | private static final long serialVersionUID = 1L; |
| 18 | |
| 19 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 20 | |
| 21 | public byte[] code = null; |
| 22 | private XrancPduHdr hdr = null; |
| 23 | private XrancPduBody body = null; |
| 24 | |
| 25 | public XrancPdu() { |
| 26 | } |
| 27 | |
| 28 | public XrancPdu(byte[] code) { |
| 29 | this.code = code; |
| 30 | } |
| 31 | |
| 32 | public void setHdr(XrancPduHdr hdr) { |
| 33 | this.hdr = hdr; |
| 34 | } |
| 35 | |
| 36 | public XrancPduHdr getHdr() { |
| 37 | return hdr; |
| 38 | } |
| 39 | |
| 40 | public void setBody(XrancPduBody body) { |
| 41 | this.body = body; |
| 42 | } |
| 43 | |
| 44 | public XrancPduBody getBody() { |
| 45 | return body; |
| 46 | } |
| 47 | |
| 48 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 49 | return encode(os, true); |
| 50 | } |
| 51 | |
| 52 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 53 | |
| 54 | if (code != null) { |
| 55 | for (int i = code.length - 1; i >= 0; i--) { |
| 56 | os.write(code[i]); |
| 57 | } |
| 58 | if (withTag) { |
| 59 | return tag.encode(os) + code.length; |
| 60 | } |
| 61 | return code.length; |
| 62 | } |
| 63 | |
| 64 | int codeLength = 0; |
| 65 | int sublength; |
| 66 | |
| 67 | sublength = body.encode(os); |
| 68 | codeLength += sublength; |
| 69 | codeLength += BerLength.encodeLength(os, sublength); |
| 70 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 71 | os.write(0xA1); |
| 72 | codeLength += 1; |
| 73 | |
| 74 | codeLength += hdr.encode(os, false); |
| 75 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 0 |
| 76 | os.write(0xA0); |
| 77 | codeLength += 1; |
| 78 | |
| 79 | codeLength += BerLength.encodeLength(os, codeLength); |
| 80 | |
| 81 | if (withTag) { |
| 82 | codeLength += tag.encode(os); |
| 83 | } |
| 84 | |
| 85 | return codeLength; |
| 86 | |
| 87 | } |
| 88 | |
| 89 | public int decode(InputStream is) throws IOException { |
| 90 | return decode(is, true); |
| 91 | } |
| 92 | |
| 93 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 94 | int codeLength = 0; |
| 95 | int subCodeLength = 0; |
| 96 | BerTag berTag = new BerTag(); |
| 97 | |
| 98 | if (withTag) { |
| 99 | codeLength += tag.decodeAndCheck(is); |
| 100 | } |
| 101 | |
| 102 | BerLength length = new BerLength(); |
| 103 | codeLength += length.decode(is); |
| 104 | |
| 105 | int totalLength = length.val; |
| 106 | codeLength += totalLength; |
| 107 | |
| 108 | subCodeLength += berTag.decode(is); |
| 109 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 0)) { |
| 110 | hdr = new XrancPduHdr(); |
| 111 | subCodeLength += hdr.decode(is, false); |
| 112 | subCodeLength += berTag.decode(is); |
| 113 | } |
| 114 | else { |
| 115 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 116 | } |
| 117 | |
| 118 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 119 | subCodeLength += length.decode(is); |
| 120 | body = new XrancPduBody(); |
| 121 | subCodeLength += body.decode(is, null); |
| 122 | if (subCodeLength == totalLength) { |
| 123 | return codeLength; |
| 124 | } |
| 125 | } |
| 126 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 127 | |
| 128 | |
| 129 | } |
| 130 | |
| 131 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 132 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 133 | encode(os, false); |
| 134 | code = os.getArray(); |
| 135 | } |
| 136 | |
| 137 | public String toString() { |
| 138 | StringBuilder sb = new StringBuilder(); |
| 139 | appendAsString(sb, 0); |
| 140 | return sb.toString(); |
| 141 | } |
| 142 | |
| 143 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 144 | |
| 145 | sb.append("{"); |
| 146 | sb.append("\n"); |
| 147 | for (int i = 0; i < indentLevel + 1; i++) { |
| 148 | sb.append("\t"); |
| 149 | } |
| 150 | if (hdr != null) { |
| 151 | sb.append("\"hdr\": "); |
| 152 | hdr.appendAsString(sb, indentLevel + 1); |
| 153 | } |
| 154 | |
| 155 | sb.append(",\n"); |
| 156 | for (int i = 0; i < indentLevel + 1; i++) { |
| 157 | sb.append("\t"); |
| 158 | } |
| 159 | if (body != null) { |
| 160 | sb.append("\"body\": "); |
| 161 | body.appendAsString(sb, indentLevel + 1); |
| 162 | } |
| 163 | |
| 164 | sb.append("\n"); |
| 165 | for (int i = 0; i < indentLevel; i++) { |
| 166 | sb.append("\t"); |
| 167 | } |
| 168 | sb.append("}"); |
| 169 | } |
| 170 | |
| 171 | } |
| 172 | |