1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.location.cts.asn1.supl2.supl_pos;
18 
19 /*
20  */
21 
22 
23 //
24 //
25 import android.location.cts.asn1.base.Asn1Choice;
26 import android.location.cts.asn1.base.Asn1Null;
27 import android.location.cts.asn1.base.Asn1Object;
28 import android.location.cts.asn1.base.Asn1OctetString;
29 import android.location.cts.asn1.base.Asn1Tag;
30 import android.location.cts.asn1.base.BitStream;
31 import android.location.cts.asn1.base.BitStreamReader;
32 import android.location.cts.asn1.base.ChoiceComponent;
33 import android.location.cts.asn1.supl2.ulp_version_2_parameter_extensions.Ver2_PosPayLoad_extension;
34 import com.google.common.collect.ImmutableList;
35 import java.nio.ByteBuffer;
36 import java.util.Collection;
37 import java.util.HashMap;
38 import java.util.Map;
39 import javax.annotation.Nullable;
40 
41 
42 /**
43  */
44 public  class PosPayLoad extends Asn1Choice {
45   //
46 
47   private static final Asn1Tag TAG_PosPayLoad
48       = Asn1Tag.fromClassAndNumber(-1, -1);
49 
50   private static final Map<Asn1Tag, Select> tagToSelection = new HashMap<>();
51 
52   private boolean extension;
53   private ChoiceComponent selection;
54   private Asn1Object element;
55 
56   static {
57     for (Select select : Select.values()) {
58       for (Asn1Tag tag : select.getPossibleFirstTags()) {
59         Select select0;
60         if ((select0 = tagToSelection.put(tag, select)) != null) {
61           throw new IllegalStateException(
62             "PosPayLoad: " + tag + " maps to both " + select0 + " and " + select);
63         }
64       }
65     }
66   }
67 
PosPayLoad()68   public PosPayLoad() {
69     super();
70   }
71 
72   @Override
73   @Nullable
getTag()74   protected Asn1Tag getTag() {
75     return TAG_PosPayLoad;
76   }
77 
78   @Override
isTagImplicit()79   protected boolean isTagImplicit() {
80     return true;
81   }
82 
getPossibleFirstTags()83   public static Collection<Asn1Tag> getPossibleFirstTags() {
84     if (TAG_PosPayLoad != null) {
85       return ImmutableList.of(TAG_PosPayLoad);
86     } else {
87       return tagToSelection.keySet();
88     }
89   }
90 
91   /**
92    * Creates a new PosPayLoad from encoded stream.
93    */
fromPerUnaligned(byte[] encodedBytes)94   public static PosPayLoad fromPerUnaligned(byte[] encodedBytes) {
95     PosPayLoad result = new PosPayLoad();
96     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
97     return result;
98   }
99 
100   /**
101    * Creates a new PosPayLoad from encoded stream.
102    */
fromPerAligned(byte[] encodedBytes)103   public static PosPayLoad fromPerAligned(byte[] encodedBytes) {
104     PosPayLoad result = new PosPayLoad();
105     result.decodePerAligned(new BitStreamReader(encodedBytes));
106     return result;
107   }
108 
109 
110 
hasExtensionValue()111   @Override protected boolean hasExtensionValue() {
112     return extension;
113   }
114 
getSelectionOrdinal()115   @Override protected Integer getSelectionOrdinal() {
116     return selection.ordinal();
117   }
118 
119   @Nullable
120   @Override
getSelectedComponent()121   protected ChoiceComponent getSelectedComponent() {
122     return selection;
123   }
124 
getOptionCount()125   @Override protected int getOptionCount() {
126     if (hasExtensionValue()) {
127       return Extend.values().length;
128     }
129     return Select.values().length;
130   }
131 
createAndSetValue(boolean isExtensionValue, int ordinal)132   protected Asn1Object createAndSetValue(boolean isExtensionValue,
133                                          int ordinal) {
134     extension = isExtensionValue;
135     if (isExtensionValue) {
136       selection = Extend.values()[ordinal];
137     } else {
138       selection = Select.values()[ordinal];
139     }
140     element = selection.createElement();
141     return element;
142   }
143 
createAndSetValue(Asn1Tag tag)144   @Override protected ChoiceComponent createAndSetValue(Asn1Tag tag) {
145     Select select = tagToSelection.get(tag);
146     if (select == null) {
147       throw new IllegalArgumentException("Unknown selection tag: " + tag);
148     }
149     element = select.createElement();
150     selection = select;
151     extension = false;
152     return select;
153   }
154 
isExtensible()155   @Override protected boolean isExtensible() {
156     return true;
157   }
158 
getValue()159   @Override protected Asn1Object getValue() {
160     return element;
161   }
162 
163 
164   private static enum Select implements ChoiceComponent {
165 
166     $Tia801payload(Asn1Tag.fromClassAndNumber(2, 0),
167         true) {
168       @Override
createElement()169       public Asn1Object createElement() {
170         return new PosPayLoad.tia801payloadType();
171       }
172 
173       @Override
getPossibleFirstTags()174       Collection<Asn1Tag> getPossibleFirstTags() {
175         return tag == null ? PosPayLoad.tia801payloadType.getPossibleFirstTags() : ImmutableList.of(tag);
176       }
177 
178       @Override
elementIndentedString(Asn1Object element, String indent)179       String elementIndentedString(Asn1Object element, String indent) {
180         return toString() + " : " + element.toIndentedString(indent);
181       }
182     },
183 
184     $RrcPayload(Asn1Tag.fromClassAndNumber(2, 1),
185         true) {
186       @Override
createElement()187       public Asn1Object createElement() {
188         return new PosPayLoad.rrcPayloadType();
189       }
190 
191       @Override
getPossibleFirstTags()192       Collection<Asn1Tag> getPossibleFirstTags() {
193         return tag == null ? PosPayLoad.rrcPayloadType.getPossibleFirstTags() : ImmutableList.of(tag);
194       }
195 
196       @Override
elementIndentedString(Asn1Object element, String indent)197       String elementIndentedString(Asn1Object element, String indent) {
198         return toString() + " : " + element.toIndentedString(indent);
199       }
200     },
201 
202     $RrlpPayload(Asn1Tag.fromClassAndNumber(2, 2),
203         true) {
204       @Override
createElement()205       public Asn1Object createElement() {
206         return new PosPayLoad.rrlpPayloadType();
207       }
208 
209       @Override
getPossibleFirstTags()210       Collection<Asn1Tag> getPossibleFirstTags() {
211         return tag == null ? PosPayLoad.rrlpPayloadType.getPossibleFirstTags() : ImmutableList.of(tag);
212       }
213 
214       @Override
elementIndentedString(Asn1Object element, String indent)215       String elementIndentedString(Asn1Object element, String indent) {
216         return toString() + " : " + element.toIndentedString(indent);
217       }
218     },
219 
220     ;
221 
222     @Nullable final Asn1Tag tag;
223     final boolean isImplicitTagging;
224 
Select(@ullable Asn1Tag tag, boolean isImplicitTagging)225     Select(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
226       this.tag = tag;
227       this.isImplicitTagging = isImplicitTagging;
228     }
229 
230     @Override
createElement()231     public Asn1Object createElement() {
232       throw new IllegalStateException("Select template error");
233     }
234 
235     @Override
236     @Nullable
getTag()237     public Asn1Tag getTag() {
238       return tag;
239     }
240 
241     @Override
isImplicitTagging()242     public boolean isImplicitTagging() {
243       return isImplicitTagging;
244     }
245 
getPossibleFirstTags()246     abstract Collection<Asn1Tag> getPossibleFirstTags();
247 
elementIndentedString(Asn1Object element, String indent)248     abstract String elementIndentedString(Asn1Object element, String indent);
249   }
250 
251 /*
252  */
253 
254 
255 //
256 
257 /**
258  */
259 public static class tia801payloadType extends Asn1OctetString {
260   //
261 
262   private static final Asn1Tag TAG_tia801payloadType
263       = Asn1Tag.fromClassAndNumber(-1, -1);
264 
tia801payloadType()265   public tia801payloadType() {
266     super();
267     setMinSize(1);
268 setMaxSize(8192);
269 
270   }
271 
272   @Override
273   @Nullable
getTag()274   protected Asn1Tag getTag() {
275     return TAG_tia801payloadType;
276   }
277 
278   @Override
isTagImplicit()279   protected boolean isTagImplicit() {
280     return true;
281   }
282 
getPossibleFirstTags()283   public static Collection<Asn1Tag> getPossibleFirstTags() {
284     if (TAG_tia801payloadType != null) {
285       return ImmutableList.of(TAG_tia801payloadType);
286     } else {
287       return Asn1OctetString.getPossibleFirstTags();
288     }
289   }
290 
291   /**
292    * Creates a new tia801payloadType from encoded stream.
293    */
fromPerUnaligned(byte[] encodedBytes)294   public static tia801payloadType fromPerUnaligned(byte[] encodedBytes) {
295     tia801payloadType result = new tia801payloadType();
296     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
297     return result;
298   }
299 
300   /**
301    * Creates a new tia801payloadType from encoded stream.
302    */
fromPerAligned(byte[] encodedBytes)303   public static tia801payloadType fromPerAligned(byte[] encodedBytes) {
304     tia801payloadType result = new tia801payloadType();
305     result.decodePerAligned(new BitStreamReader(encodedBytes));
306     return result;
307   }
308 
encodePerUnaligned()309   @Override public Iterable<BitStream> encodePerUnaligned() {
310     return super.encodePerUnaligned();
311   }
312 
encodePerAligned()313   @Override public Iterable<BitStream> encodePerAligned() {
314     return super.encodePerAligned();
315   }
316 
decodePerUnaligned(BitStreamReader reader)317   @Override public void decodePerUnaligned(BitStreamReader reader) {
318     super.decodePerUnaligned(reader);
319   }
320 
decodePerAligned(BitStreamReader reader)321   @Override public void decodePerAligned(BitStreamReader reader) {
322     super.decodePerAligned(reader);
323   }
324 
getTypeName()325   @Override protected String getTypeName() {
326     return "tia801payloadType";
327   }
328 }
329 
330 
isTia801payload()331   public boolean isTia801payload() {
332     return !hasExtensionValue() && Select.$Tia801payload == selection;
333   }
334 
335   /**
336    * @throws {@code IllegalStateException} if {@code !isTia801payload}.
337    */
338   @SuppressWarnings("unchecked")
getTia801payload()339   public PosPayLoad.tia801payloadType getTia801payload() {
340     if (!isTia801payload()) {
341       throw new IllegalStateException("PosPayLoad value not a Tia801payload");
342     }
343     return (PosPayLoad.tia801payloadType) element;
344   }
345 
setTia801payload(PosPayLoad.tia801payloadType selected)346   public void setTia801payload(PosPayLoad.tia801payloadType selected) {
347     selection = Select.$Tia801payload;
348     extension = false;
349     element = selected;
350   }
351 
setTia801payloadToNewInstance()352   public PosPayLoad.tia801payloadType setTia801payloadToNewInstance() {
353       PosPayLoad.tia801payloadType element = new PosPayLoad.tia801payloadType();
354       setTia801payload(element);
355       return element;
356   }
357 
358 /*
359  */
360 
361 
362 //
363 
364 /**
365  */
366 public static class rrcPayloadType extends Asn1OctetString {
367   //
368 
369   private static final Asn1Tag TAG_rrcPayloadType
370       = Asn1Tag.fromClassAndNumber(-1, -1);
371 
rrcPayloadType()372   public rrcPayloadType() {
373     super();
374     setMinSize(1);
375 setMaxSize(8192);
376 
377   }
378 
379   @Override
380   @Nullable
getTag()381   protected Asn1Tag getTag() {
382     return TAG_rrcPayloadType;
383   }
384 
385   @Override
isTagImplicit()386   protected boolean isTagImplicit() {
387     return true;
388   }
389 
getPossibleFirstTags()390   public static Collection<Asn1Tag> getPossibleFirstTags() {
391     if (TAG_rrcPayloadType != null) {
392       return ImmutableList.of(TAG_rrcPayloadType);
393     } else {
394       return Asn1OctetString.getPossibleFirstTags();
395     }
396   }
397 
398   /**
399    * Creates a new rrcPayloadType from encoded stream.
400    */
fromPerUnaligned(byte[] encodedBytes)401   public static rrcPayloadType fromPerUnaligned(byte[] encodedBytes) {
402     rrcPayloadType result = new rrcPayloadType();
403     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
404     return result;
405   }
406 
407   /**
408    * Creates a new rrcPayloadType from encoded stream.
409    */
fromPerAligned(byte[] encodedBytes)410   public static rrcPayloadType fromPerAligned(byte[] encodedBytes) {
411     rrcPayloadType result = new rrcPayloadType();
412     result.decodePerAligned(new BitStreamReader(encodedBytes));
413     return result;
414   }
415 
encodePerUnaligned()416   @Override public Iterable<BitStream> encodePerUnaligned() {
417     return super.encodePerUnaligned();
418   }
419 
encodePerAligned()420   @Override public Iterable<BitStream> encodePerAligned() {
421     return super.encodePerAligned();
422   }
423 
decodePerUnaligned(BitStreamReader reader)424   @Override public void decodePerUnaligned(BitStreamReader reader) {
425     super.decodePerUnaligned(reader);
426   }
427 
decodePerAligned(BitStreamReader reader)428   @Override public void decodePerAligned(BitStreamReader reader) {
429     super.decodePerAligned(reader);
430   }
431 
getTypeName()432   @Override protected String getTypeName() {
433     return "rrcPayloadType";
434   }
435 }
436 
437 
isRrcPayload()438   public boolean isRrcPayload() {
439     return !hasExtensionValue() && Select.$RrcPayload == selection;
440   }
441 
442   /**
443    * @throws {@code IllegalStateException} if {@code !isRrcPayload}.
444    */
445   @SuppressWarnings("unchecked")
getRrcPayload()446   public PosPayLoad.rrcPayloadType getRrcPayload() {
447     if (!isRrcPayload()) {
448       throw new IllegalStateException("PosPayLoad value not a RrcPayload");
449     }
450     return (PosPayLoad.rrcPayloadType) element;
451   }
452 
setRrcPayload(PosPayLoad.rrcPayloadType selected)453   public void setRrcPayload(PosPayLoad.rrcPayloadType selected) {
454     selection = Select.$RrcPayload;
455     extension = false;
456     element = selected;
457   }
458 
setRrcPayloadToNewInstance()459   public PosPayLoad.rrcPayloadType setRrcPayloadToNewInstance() {
460       PosPayLoad.rrcPayloadType element = new PosPayLoad.rrcPayloadType();
461       setRrcPayload(element);
462       return element;
463   }
464 
465 /*
466  */
467 
468 
469 //
470 
471 /**
472  */
473 public static class rrlpPayloadType extends Asn1OctetString {
474   //
475 
476   private static final Asn1Tag TAG_rrlpPayloadType
477       = Asn1Tag.fromClassAndNumber(-1, -1);
478 
rrlpPayloadType()479   public rrlpPayloadType() {
480     super();
481     setMinSize(1);
482 setMaxSize(8192);
483 
484   }
485 
486   @Override
487   @Nullable
getTag()488   protected Asn1Tag getTag() {
489     return TAG_rrlpPayloadType;
490   }
491 
492   @Override
isTagImplicit()493   protected boolean isTagImplicit() {
494     return true;
495   }
496 
getPossibleFirstTags()497   public static Collection<Asn1Tag> getPossibleFirstTags() {
498     if (TAG_rrlpPayloadType != null) {
499       return ImmutableList.of(TAG_rrlpPayloadType);
500     } else {
501       return Asn1OctetString.getPossibleFirstTags();
502     }
503   }
504 
505   /**
506    * Creates a new rrlpPayloadType from encoded stream.
507    */
fromPerUnaligned(byte[] encodedBytes)508   public static rrlpPayloadType fromPerUnaligned(byte[] encodedBytes) {
509     rrlpPayloadType result = new rrlpPayloadType();
510     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
511     return result;
512   }
513 
514   /**
515    * Creates a new rrlpPayloadType from encoded stream.
516    */
fromPerAligned(byte[] encodedBytes)517   public static rrlpPayloadType fromPerAligned(byte[] encodedBytes) {
518     rrlpPayloadType result = new rrlpPayloadType();
519     result.decodePerAligned(new BitStreamReader(encodedBytes));
520     return result;
521   }
522 
encodePerUnaligned()523   @Override public Iterable<BitStream> encodePerUnaligned() {
524     return super.encodePerUnaligned();
525   }
526 
encodePerAligned()527   @Override public Iterable<BitStream> encodePerAligned() {
528     return super.encodePerAligned();
529   }
530 
decodePerUnaligned(BitStreamReader reader)531   @Override public void decodePerUnaligned(BitStreamReader reader) {
532     super.decodePerUnaligned(reader);
533   }
534 
decodePerAligned(BitStreamReader reader)535   @Override public void decodePerAligned(BitStreamReader reader) {
536     super.decodePerAligned(reader);
537   }
538 
getTypeName()539   @Override protected String getTypeName() {
540     return "rrlpPayloadType";
541   }
542 }
543 
544 
isRrlpPayload()545   public boolean isRrlpPayload() {
546     return !hasExtensionValue() && Select.$RrlpPayload == selection;
547   }
548 
549   /**
550    * @throws {@code IllegalStateException} if {@code !isRrlpPayload}.
551    */
552   @SuppressWarnings("unchecked")
getRrlpPayload()553   public PosPayLoad.rrlpPayloadType getRrlpPayload() {
554     if (!isRrlpPayload()) {
555       throw new IllegalStateException("PosPayLoad value not a RrlpPayload");
556     }
557     return (PosPayLoad.rrlpPayloadType) element;
558   }
559 
setRrlpPayload(PosPayLoad.rrlpPayloadType selected)560   public void setRrlpPayload(PosPayLoad.rrlpPayloadType selected) {
561     selection = Select.$RrlpPayload;
562     extension = false;
563     element = selected;
564   }
565 
setRrlpPayloadToNewInstance()566   public PosPayLoad.rrlpPayloadType setRrlpPayloadToNewInstance() {
567       PosPayLoad.rrlpPayloadType element = new PosPayLoad.rrlpPayloadType();
568       setRrlpPayload(element);
569       return element;
570   }
571 
572 
573   private static enum Extend implements ChoiceComponent {
574 
575     $Ver2_PosPayLoad_extension(Asn1Tag.fromClassAndNumber(2, 3),
576         true) {
577       @Override
createElement()578       public Asn1Object createElement() {
579         return new Ver2_PosPayLoad_extension();
580       }
581 
582       @Override
583       @SuppressWarnings("unchecked")
elementIndentedString(Asn1Object element, String indent)584       String elementIndentedString(Asn1Object element, String indent) {
585         return toString() + " : " + ((Ver2_PosPayLoad_extension) element).toIndentedString(indent);
586       }
587     },
588 
589     ;
590     @Nullable private final Asn1Tag tag;
591     private final boolean isImplicitTagging;
592 
Extend(@ullable Asn1Tag tag, boolean isImplicitTagging)593     Extend(@Nullable Asn1Tag tag, boolean isImplicitTagging) {
594       this.tag = tag;
595       this.isImplicitTagging = isImplicitTagging;
596     }
597 
createElement()598     public Asn1Object createElement() {
599       throw new IllegalStateException("Extend template error");
600     }
601 
602     @Override
603     @Nullable
getTag()604     public Asn1Tag getTag() {
605       return tag;
606     }
607 
608     @Override
isImplicitTagging()609     public boolean isImplicitTagging() {
610       return isImplicitTagging;
611     }
612 
elementIndentedString(Asn1Object element, String indent)613     String elementIndentedString(Asn1Object element, String indent) {
614       throw new IllegalStateException("Extend template error");
615     }
616   }
617 
618 
619 
isExtensionVer2_PosPayLoad_extension()620   public boolean isExtensionVer2_PosPayLoad_extension() {
621     return hasExtensionValue() && Extend.$Ver2_PosPayLoad_extension == selection;
622   }
623 
624   /**
625    * @throws {@code IllegalStateException} if {@code !isVer2_PosPayLoad_extension}.
626    */
627   @SuppressWarnings("unchecked")
getExtensionVer2_PosPayLoad_extension()628   public Ver2_PosPayLoad_extension getExtensionVer2_PosPayLoad_extension() {
629     if (!isExtensionVer2_PosPayLoad_extension()) {
630       throw new IllegalStateException("PosPayLoad value not a Ver2_PosPayLoad_extension");
631     }
632     return (Ver2_PosPayLoad_extension) element;
633   }
634 
setExtensionVer2_PosPayLoad_extension(Ver2_PosPayLoad_extension selected)635   public void setExtensionVer2_PosPayLoad_extension(Ver2_PosPayLoad_extension selected) {
636     selection = Extend.$Ver2_PosPayLoad_extension;
637     extension = true;
638     element = selected;
639   }
640 
setExtensionVer2_PosPayLoad_extensionToNewInstance()641   public void setExtensionVer2_PosPayLoad_extensionToNewInstance() {
642       Ver2_PosPayLoad_extension element = new Ver2_PosPayLoad_extension();
643       setExtensionVer2_PosPayLoad_extension(element);
644   }
645 
646 
encodePerUnaligned()647   @Override public Iterable<BitStream> encodePerUnaligned() {
648     return super.encodePerUnaligned();
649   }
650 
encodePerAligned()651   @Override public Iterable<BitStream> encodePerAligned() {
652     return super.encodePerAligned();
653   }
654 
decodePerUnaligned(BitStreamReader reader)655   @Override public void decodePerUnaligned(BitStreamReader reader) {
656     super.decodePerUnaligned(reader);
657   }
658 
decodePerAligned(BitStreamReader reader)659   @Override public void decodePerAligned(BitStreamReader reader) {
660     super.decodePerAligned(reader);
661   }
662 
toString()663   @Override public String toString() {
664     return toIndentedString("");
665   }
666 
elementIndentedString(String indent)667   private String elementIndentedString(String indent) {
668     if (element == null) {
669       return "null;\n";
670     }
671     if (extension) {
672       return Extend.values()[selection.ordinal()]
673           .elementIndentedString(element, indent + "  ");
674     } else {
675       return Select.values()[selection.ordinal()]
676           .elementIndentedString(element, indent + "  ");
677     }
678   }
679 
toIndentedString(String indent)680   public String toIndentedString(String indent) {
681     return "PosPayLoad = " + elementIndentedString(indent) + indent + ";\n";
682   }
683 }
684