slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 1 | /** |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 2 | * This class file was automatically generated by jASN1 v1.8.2 (http://www.openmuc.org) |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 3 | */ |
| 4 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 5 | package org.onosproject.xran.asn1lib.api; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 6 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 7 | import com.fasterxml.jackson.annotation.JsonIgnore; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 8 | import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream; |
| 9 | import org.onosproject.xran.asn1lib.ber.BerLength; |
| 10 | import org.onosproject.xran.asn1lib.ber.BerTag; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 11 | |
| 12 | import java.io.IOException; |
| 13 | import java.io.InputStream; |
| 14 | import java.io.Serializable; |
| 15 | |
| 16 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 17 | public class ECGI implements Serializable { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 18 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 19 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 20 | private static final long serialVersionUID = 1L; |
| 21 | @JsonIgnore |
| 22 | public byte[] code = null; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 23 | private PLMNIdentity pLMNIdentity = null; |
| 24 | private EUTRANCellIdentifier eUTRANcellIdentifier = null; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 25 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 26 | public ECGI() { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 27 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 28 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 29 | public ECGI(byte[] code) { |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 30 | this.code = code; |
| 31 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 32 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 33 | public PLMNIdentity getPLMNIdentity() { |
| 34 | return pLMNIdentity; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 35 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 36 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 37 | public void setPLMNIdentity(PLMNIdentity pLMNIdentity) { |
| 38 | this.pLMNIdentity = pLMNIdentity; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 39 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 40 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 41 | public EUTRANCellIdentifier getEUTRANcellIdentifier() { |
| 42 | return eUTRANcellIdentifier; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 43 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 44 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 45 | public void setEUTRANcellIdentifier(EUTRANCellIdentifier eUTRANcellIdentifier) { |
| 46 | this.eUTRANcellIdentifier = eUTRANcellIdentifier; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 47 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 48 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 49 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 50 | return encode(os, true); |
| 51 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 52 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 53 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 54 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 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 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 64 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 65 | int codeLength = 0; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 66 | codeLength += eUTRANcellIdentifier.encode(os, false); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 67 | // write tag: CONTEXT_CLASS, PRIMITIVE, 1 |
| 68 | os.write(0x81); |
| 69 | codeLength += 1; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 70 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 71 | codeLength += pLMNIdentity.encode(os, false); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 72 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 73 | os.write(0x80); |
| 74 | codeLength += 1; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 75 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 76 | codeLength += BerLength.encodeLength(os, codeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 77 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 78 | if (withTag) { |
| 79 | codeLength += tag.encode(os); |
| 80 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 81 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 82 | return codeLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 83 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 84 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 85 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 86 | public int decode(InputStream is) throws IOException { |
| 87 | return decode(is, true); |
| 88 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 89 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 90 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 91 | int codeLength = 0; |
| 92 | int subCodeLength = 0; |
| 93 | BerTag berTag = new BerTag(); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 94 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 95 | if (withTag) { |
| 96 | codeLength += tag.decodeAndCheck(is); |
| 97 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 98 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 99 | BerLength length = new BerLength(); |
| 100 | codeLength += length.decode(is); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 101 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 102 | int totalLength = length.val; |
| 103 | codeLength += totalLength; |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 104 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 105 | subCodeLength += berTag.decode(is); |
| 106 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 107 | pLMNIdentity = new PLMNIdentity(); |
| 108 | subCodeLength += pLMNIdentity.decode(is, false); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 109 | subCodeLength += berTag.decode(is); |
| 110 | } else { |
| 111 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 112 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 113 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 114 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 115 | eUTRANcellIdentifier = new EUTRANCellIdentifier(); |
| 116 | subCodeLength += eUTRANcellIdentifier.decode(is, false); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 117 | if (subCodeLength == totalLength) { |
| 118 | return codeLength; |
| 119 | } |
| 120 | } |
| 121 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 122 | |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 123 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 124 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 125 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 126 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 127 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 128 | encode(os, false); |
| 129 | code = os.getArray(); |
| 130 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 131 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 132 | public String toString() { |
| 133 | StringBuilder sb = new StringBuilder(); |
| 134 | appendAsString(sb, 0); |
| 135 | return sb.toString(); |
| 136 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 137 | |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 138 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 139 | |
| 140 | sb.append("{"); |
| 141 | sb.append("\n"); |
| 142 | for (int i = 0; i < indentLevel + 1; i++) { |
| 143 | sb.append("\t"); |
| 144 | } |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 145 | if (pLMNIdentity != null) { |
| 146 | sb.append("pLMNIdentity: ").append(pLMNIdentity); |
| 147 | } else { |
| 148 | sb.append("pLMNIdentity: <empty-required-field>"); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | sb.append(",\n"); |
| 152 | for (int i = 0; i < indentLevel + 1; i++) { |
| 153 | sb.append("\t"); |
| 154 | } |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 155 | if (eUTRANcellIdentifier != null) { |
| 156 | sb.append("eUTRANcellIdentifier: ").append(eUTRANcellIdentifier); |
| 157 | } else { |
| 158 | sb.append("eUTRANcellIdentifier: <empty-required-field>"); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | sb.append("\n"); |
| 162 | for (int i = 0; i < indentLevel; i++) { |
| 163 | sb.append("\t"); |
| 164 | } |
| 165 | sb.append("}"); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public boolean equals(Object o) { |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 170 | if (this == o) return true; |
| 171 | if (o == null || getClass() != o.getClass()) return false; |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 172 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 173 | ECGI ecgi = (ECGI) o; |
| 174 | |
| 175 | return eUTRANcellIdentifier.equals(ecgi.eUTRANcellIdentifier); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public int hashCode() { |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 180 | return eUTRANcellIdentifier.hashCode(); |
slowr | 577f322 | 2017-08-28 10:49:08 -0700 | [diff] [blame] | 181 | } |
slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame] | 182 | } |
| 183 | |