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