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 | package org.onosproject.xran.codecs.pdu; |
| 5 | |
| 6 | import org.onosproject.xran.codecs.api.CRNTI; |
| 7 | import org.onosproject.xran.codecs.api.ECGI; |
| 8 | import org.onosproject.xran.codecs.api.TrafficSplitPercentage; |
| 9 | import org.openmuc.jasn1.ber.BerByteArrayOutputStream; |
| 10 | import org.openmuc.jasn1.ber.BerLength; |
| 11 | import org.openmuc.jasn1.ber.BerTag; |
| 12 | |
| 13 | import java.io.IOException; |
| 14 | import java.io.InputStream; |
| 15 | import java.io.Serializable; |
| 16 | import java.util.ArrayList; |
| 17 | import java.util.Iterator; |
| 18 | import java.util.List; |
| 19 | |
| 20 | public class TrafficSplitConfig implements Serializable { |
| 21 | |
| 22 | private static final long serialVersionUID = 1L; |
| 23 | |
| 24 | public static class TrafficSplitPercent implements Serializable { |
| 25 | |
| 26 | private static final long serialVersionUID = 1L; |
| 27 | |
| 28 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 29 | public byte[] code = null; |
| 30 | private List<TrafficSplitPercentage> seqOf = null; |
| 31 | |
| 32 | public TrafficSplitPercent() { |
| 33 | seqOf = new ArrayList<TrafficSplitPercentage>(); |
| 34 | } |
| 35 | |
| 36 | public TrafficSplitPercent(byte[] code) { |
| 37 | this.code = code; |
| 38 | } |
| 39 | |
| 40 | public List<TrafficSplitPercentage> getTrafficSplitPercentage() { |
| 41 | if (seqOf == null) { |
| 42 | seqOf = new ArrayList<TrafficSplitPercentage>(); |
| 43 | } |
| 44 | return seqOf; |
| 45 | } |
| 46 | |
| 47 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 48 | return encode(os, true); |
| 49 | } |
| 50 | |
| 51 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 52 | |
| 53 | if (code != null) { |
| 54 | for (int i = code.length - 1; i >= 0; i--) { |
| 55 | os.write(code[i]); |
| 56 | } |
| 57 | if (withTag) { |
| 58 | return tag.encode(os) + code.length; |
| 59 | } |
| 60 | return code.length; |
| 61 | } |
| 62 | |
| 63 | int codeLength = 0; |
| 64 | for (int i = (seqOf.size() - 1); i >= 0; i--) { |
| 65 | codeLength += seqOf.get(i).encode(os, true); |
| 66 | } |
| 67 | |
| 68 | codeLength += BerLength.encodeLength(os, codeLength); |
| 69 | |
| 70 | if (withTag) { |
| 71 | codeLength += tag.encode(os); |
| 72 | } |
| 73 | |
| 74 | return codeLength; |
| 75 | } |
| 76 | |
| 77 | public int decode(InputStream is) throws IOException { |
| 78 | return decode(is, true); |
| 79 | } |
| 80 | |
| 81 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 82 | int codeLength = 0; |
| 83 | int subCodeLength = 0; |
| 84 | if (withTag) { |
| 85 | codeLength += tag.decodeAndCheck(is); |
| 86 | } |
| 87 | |
| 88 | BerLength length = new BerLength(); |
| 89 | codeLength += length.decode(is); |
| 90 | int totalLength = length.val; |
| 91 | |
| 92 | while (subCodeLength < totalLength) { |
| 93 | TrafficSplitPercentage element = new TrafficSplitPercentage(); |
| 94 | subCodeLength += element.decode(is, true); |
| 95 | seqOf.add(element); |
| 96 | } |
| 97 | if (subCodeLength != totalLength) { |
| 98 | throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength); |
| 99 | |
| 100 | } |
| 101 | codeLength += subCodeLength; |
| 102 | |
| 103 | return codeLength; |
| 104 | } |
| 105 | |
| 106 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 107 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 108 | encode(os, false); |
| 109 | code = os.getArray(); |
| 110 | } |
| 111 | |
| 112 | public String toString() { |
| 113 | StringBuilder sb = new StringBuilder(); |
| 114 | appendAsString(sb, 0); |
| 115 | return sb.toString(); |
| 116 | } |
| 117 | |
| 118 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 119 | |
| 120 | sb.append("[\n"); |
| 121 | for (int i = 0; i < indentLevel + 1; i++) { |
| 122 | sb.append("\t"); |
| 123 | } |
| 124 | if (seqOf == null) { |
| 125 | // sb.append("null"); |
| 126 | } |
| 127 | else { |
| 128 | Iterator<TrafficSplitPercentage> it = seqOf.iterator(); |
| 129 | if (it.hasNext()) { |
| 130 | it.next().appendAsString(sb, indentLevel + 1); |
| 131 | while (it.hasNext()) { |
| 132 | sb.append(",\n"); |
| 133 | for (int i = 0; i < indentLevel + 1; i++) { |
| 134 | sb.append("\t"); |
| 135 | } |
| 136 | it.next().appendAsString(sb, indentLevel + 1); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | sb.append("\n"); |
| 142 | for (int i = 0; i < indentLevel; i++) { |
| 143 | sb.append("\t"); |
| 144 | } |
| 145 | sb.append("]"); |
| 146 | } |
| 147 | |
| 148 | } |
| 149 | |
| 150 | public static final BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.CONSTRUCTED, 16); |
| 151 | |
| 152 | public byte[] code = null; |
| 153 | private CRNTI crnti = null; |
| 154 | private ECGI ecgi = null; |
| 155 | private TrafficSplitPercent trafficSplitPercent = null; |
| 156 | |
| 157 | public TrafficSplitConfig() { |
| 158 | } |
| 159 | |
| 160 | public TrafficSplitConfig(byte[] code) { |
| 161 | this.code = code; |
| 162 | } |
| 163 | |
| 164 | public void setCrnti(CRNTI crnti) { |
| 165 | this.crnti = crnti; |
| 166 | } |
| 167 | |
| 168 | public CRNTI getCrnti() { |
| 169 | return crnti; |
| 170 | } |
| 171 | |
| 172 | public void setEcgi(ECGI ecgi) { |
| 173 | this.ecgi = ecgi; |
| 174 | } |
| 175 | |
| 176 | public ECGI getEcgi() { |
| 177 | return ecgi; |
| 178 | } |
| 179 | |
| 180 | public void setTrafficSplitPercent(TrafficSplitPercent trafficSplitPercent) { |
| 181 | this.trafficSplitPercent = trafficSplitPercent; |
| 182 | } |
| 183 | |
| 184 | public TrafficSplitPercent getTrafficSplitPercent() { |
| 185 | return trafficSplitPercent; |
| 186 | } |
| 187 | |
| 188 | public int encode(BerByteArrayOutputStream os) throws IOException { |
| 189 | return encode(os, true); |
| 190 | } |
| 191 | |
| 192 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 193 | |
| 194 | if (code != null) { |
| 195 | for (int i = code.length - 1; i >= 0; i--) { |
| 196 | os.write(code[i]); |
| 197 | } |
| 198 | if (withTag) { |
| 199 | return tag.encode(os) + code.length; |
| 200 | } |
| 201 | return code.length; |
| 202 | } |
| 203 | |
| 204 | int codeLength = 0; |
| 205 | codeLength += trafficSplitPercent.encode(os, false); |
| 206 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 2 |
| 207 | os.write(0xA2); |
| 208 | codeLength += 1; |
| 209 | |
| 210 | codeLength += ecgi.encode(os, false); |
| 211 | // write tag: CONTEXT_CLASS, CONSTRUCTED, 1 |
| 212 | os.write(0xA1); |
| 213 | codeLength += 1; |
| 214 | |
| 215 | codeLength += crnti.encode(os, false); |
| 216 | // write tag: CONTEXT_CLASS, PRIMITIVE, 0 |
| 217 | os.write(0x80); |
| 218 | codeLength += 1; |
| 219 | |
| 220 | codeLength += BerLength.encodeLength(os, codeLength); |
| 221 | |
| 222 | if (withTag) { |
| 223 | codeLength += tag.encode(os); |
| 224 | } |
| 225 | |
| 226 | return codeLength; |
| 227 | |
| 228 | } |
| 229 | |
| 230 | public int decode(InputStream is) throws IOException { |
| 231 | return decode(is, true); |
| 232 | } |
| 233 | |
| 234 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 235 | int codeLength = 0; |
| 236 | int subCodeLength = 0; |
| 237 | BerTag berTag = new BerTag(); |
| 238 | |
| 239 | if (withTag) { |
| 240 | codeLength += tag.decodeAndCheck(is); |
| 241 | } |
| 242 | |
| 243 | BerLength length = new BerLength(); |
| 244 | codeLength += length.decode(is); |
| 245 | |
| 246 | int totalLength = length.val; |
| 247 | codeLength += totalLength; |
| 248 | |
| 249 | subCodeLength += berTag.decode(is); |
| 250 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { |
| 251 | crnti = new CRNTI(); |
| 252 | subCodeLength += crnti.decode(is, false); |
| 253 | subCodeLength += berTag.decode(is); |
| 254 | } |
| 255 | else { |
| 256 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 257 | } |
| 258 | |
| 259 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 1)) { |
| 260 | ecgi = new ECGI(); |
| 261 | subCodeLength += ecgi.decode(is, false); |
| 262 | subCodeLength += berTag.decode(is); |
| 263 | } |
| 264 | else { |
| 265 | throw new IOException("Tag does not match the mandatory sequence element tag."); |
| 266 | } |
| 267 | |
| 268 | if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.CONSTRUCTED, 2)) { |
| 269 | trafficSplitPercent = new TrafficSplitPercent(); |
| 270 | subCodeLength += trafficSplitPercent.decode(is, false); |
| 271 | if (subCodeLength == totalLength) { |
| 272 | return codeLength; |
| 273 | } |
| 274 | } |
| 275 | throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); |
| 276 | |
| 277 | |
| 278 | } |
| 279 | |
| 280 | public void encodeAndSave(int encodingSizeGuess) throws IOException { |
| 281 | BerByteArrayOutputStream os = new BerByteArrayOutputStream(encodingSizeGuess); |
| 282 | encode(os, false); |
| 283 | code = os.getArray(); |
| 284 | } |
| 285 | |
| 286 | public String toString() { |
| 287 | StringBuilder sb = new StringBuilder(); |
| 288 | appendAsString(sb, 0); |
| 289 | return sb.toString(); |
| 290 | } |
| 291 | |
| 292 | public void appendAsString(StringBuilder sb, int indentLevel) { |
| 293 | |
| 294 | sb.append("{"); |
| 295 | sb.append("\n"); |
| 296 | for (int i = 0; i < indentLevel + 1; i++) { |
| 297 | sb.append("\t"); |
| 298 | } |
| 299 | if (crnti != null) { |
| 300 | sb.append("\"crnti\": ").append(crnti); |
| 301 | } |
| 302 | |
| 303 | sb.append(",\n"); |
| 304 | for (int i = 0; i < indentLevel + 1; i++) { |
| 305 | sb.append("\t"); |
| 306 | } |
| 307 | if (ecgi != null) { |
| 308 | sb.append("\"ecgi\": "); |
| 309 | ecgi.appendAsString(sb, indentLevel + 1); |
| 310 | } |
| 311 | |
| 312 | sb.append(",\n"); |
| 313 | for (int i = 0; i < indentLevel + 1; i++) { |
| 314 | sb.append("\t"); |
| 315 | } |
| 316 | if (trafficSplitPercent != null) { |
| 317 | sb.append("\"trafficSplitPercent\": "); |
| 318 | trafficSplitPercent.appendAsString(sb, indentLevel + 1); |
| 319 | } |
| 320 | |
| 321 | sb.append("\n"); |
| 322 | for (int i = 0; i < indentLevel; i++) { |
| 323 | sb.append("\t"); |
| 324 | } |
| 325 | sb.append("}"); |
| 326 | } |
| 327 | |
| 328 | } |
| 329 | |