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.rrlp_messages;
18 
19 /*
20  */
21 
22 
23 //
24 //
25 import android.location.cts.asn1.base.Asn1Integer;
26 import android.location.cts.asn1.base.Asn1Null;
27 import android.location.cts.asn1.base.Asn1Object;
28 import android.location.cts.asn1.base.Asn1Sequence;
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.SequenceComponent;
33 import com.google.common.collect.ImmutableList;
34 import java.util.Collection;
35 import javax.annotation.Nullable;
36 
37 
38 /**
39 */
40 public  class PDU extends Asn1Sequence {
41   //
42 
43   private static final Asn1Tag TAG_PDU
44       = Asn1Tag.fromClassAndNumber(-1, -1);
45 
PDU()46   public PDU() {
47     super();
48   }
49 
50   @Override
51   @Nullable
getTag()52   protected Asn1Tag getTag() {
53     return TAG_PDU;
54   }
55 
56   @Override
isTagImplicit()57   protected boolean isTagImplicit() {
58     return true;
59   }
60 
getPossibleFirstTags()61   public static Collection<Asn1Tag> getPossibleFirstTags() {
62     if (TAG_PDU != null) {
63       return ImmutableList.of(TAG_PDU);
64     } else {
65       return Asn1Sequence.getPossibleFirstTags();
66     }
67   }
68 
69   /**
70    * Creates a new PDU from encoded stream.
71    */
fromPerUnaligned(byte[] encodedBytes)72   public static PDU fromPerUnaligned(byte[] encodedBytes) {
73     PDU result = new PDU();
74     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
75     return result;
76   }
77 
78   /**
79    * Creates a new PDU from encoded stream.
80    */
fromPerAligned(byte[] encodedBytes)81   public static PDU fromPerAligned(byte[] encodedBytes) {
82     PDU result = new PDU();
83     result.decodePerAligned(new BitStreamReader(encodedBytes));
84     return result;
85   }
86 
87 
88 
isExtensible()89   @Override protected boolean isExtensible() {
90     return false;
91   }
92 
containsExtensionValues()93   @Override public boolean containsExtensionValues() {
94     for (SequenceComponent extensionComponent : getExtensionComponents()) {
95       if (extensionComponent.isExplicitlySet()) return true;
96     }
97     return false;
98   }
99 
100 
101   private PDU.referenceNumberType referenceNumber_;
getReferenceNumber()102   public PDU.referenceNumberType getReferenceNumber() {
103     return referenceNumber_;
104   }
105   /**
106    * @throws ClassCastException if value is not a PDU.referenceNumberType
107    */
setReferenceNumber(Asn1Object value)108   public void setReferenceNumber(Asn1Object value) {
109     this.referenceNumber_ = (PDU.referenceNumberType) value;
110   }
setReferenceNumberToNewInstance()111   public PDU.referenceNumberType setReferenceNumberToNewInstance() {
112     referenceNumber_ = new PDU.referenceNumberType();
113     return referenceNumber_;
114   }
115 
116   private RRLP_Component component_;
getComponent()117   public RRLP_Component getComponent() {
118     return component_;
119   }
120   /**
121    * @throws ClassCastException if value is not a RRLP_Component
122    */
setComponent(Asn1Object value)123   public void setComponent(Asn1Object value) {
124     this.component_ = (RRLP_Component) value;
125   }
setComponentToNewInstance()126   public RRLP_Component setComponentToNewInstance() {
127     component_ = new RRLP_Component();
128     return component_;
129   }
130 
131 
132 
133 
134 
135 
getComponents()136   @Override public Iterable<? extends SequenceComponent> getComponents() {
137     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
138 
139     builder.add(new SequenceComponent() {
140           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 0);
141 
142           @Override public boolean isExplicitlySet() {
143             return getReferenceNumber() != null;
144           }
145 
146           @Override public boolean hasDefaultValue() {
147             return false;
148           }
149 
150           @Override public boolean isOptional() {
151             return false;
152           }
153 
154           @Override public Asn1Object getComponentValue() {
155             return getReferenceNumber();
156           }
157 
158           @Override public void setToNewInstance() {
159             setReferenceNumberToNewInstance();
160           }
161 
162           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
163             return tag == null ? PDU.referenceNumberType.getPossibleFirstTags() : ImmutableList.of(tag);
164           }
165 
166           @Override
167           public Asn1Tag getTag() {
168             return tag;
169           }
170 
171           @Override
172           public boolean isImplicitTagging() {
173             return true;
174           }
175 
176           @Override public String toIndentedString(String indent) {
177                 return "referenceNumber : "
178                     + getReferenceNumber().toIndentedString(indent);
179               }
180         });
181 
182     builder.add(new SequenceComponent() {
183           Asn1Tag tag = Asn1Tag.fromClassAndNumber(2, 1);
184 
185           @Override public boolean isExplicitlySet() {
186             return getComponent() != null;
187           }
188 
189           @Override public boolean hasDefaultValue() {
190             return false;
191           }
192 
193           @Override public boolean isOptional() {
194             return false;
195           }
196 
197           @Override public Asn1Object getComponentValue() {
198             return getComponent();
199           }
200 
201           @Override public void setToNewInstance() {
202             setComponentToNewInstance();
203           }
204 
205           @Override public Collection<Asn1Tag> getPossibleFirstTags() {
206             return tag == null ? RRLP_Component.getPossibleFirstTags() : ImmutableList.of(tag);
207           }
208 
209           @Override
210           public Asn1Tag getTag() {
211             return tag;
212           }
213 
214           @Override
215           public boolean isImplicitTagging() {
216             return true;
217           }
218 
219           @Override public String toIndentedString(String indent) {
220                 return "component : "
221                     + getComponent().toIndentedString(indent);
222               }
223         });
224 
225     return builder.build();
226   }
227 
228   @Override public Iterable<? extends SequenceComponent>
getExtensionComponents()229                                                     getExtensionComponents() {
230     ImmutableList.Builder<SequenceComponent> builder = ImmutableList.builder();
231 
232       return builder.build();
233     }
234 
235 
236 /*
237  */
238 
239 
240 //
241 
242 /**
243  */
244 public static class referenceNumberType extends Asn1Integer {
245   //
246 
247   private static final Asn1Tag TAG_referenceNumberType
248       = Asn1Tag.fromClassAndNumber(-1, -1);
249 
referenceNumberType()250   public referenceNumberType() {
251     super();
252     setValueRange("0", "7");
253 
254   }
255 
256   @Override
257   @Nullable
getTag()258   protected Asn1Tag getTag() {
259     return TAG_referenceNumberType;
260   }
261 
262   @Override
isTagImplicit()263   protected boolean isTagImplicit() {
264     return true;
265   }
266 
getPossibleFirstTags()267   public static Collection<Asn1Tag> getPossibleFirstTags() {
268     if (TAG_referenceNumberType != null) {
269       return ImmutableList.of(TAG_referenceNumberType);
270     } else {
271       return Asn1Integer.getPossibleFirstTags();
272     }
273   }
274 
275   /**
276    * Creates a new referenceNumberType from encoded stream.
277    */
fromPerUnaligned(byte[] encodedBytes)278   public static referenceNumberType fromPerUnaligned(byte[] encodedBytes) {
279     referenceNumberType result = new referenceNumberType();
280     result.decodePerUnaligned(new BitStreamReader(encodedBytes));
281     return result;
282   }
283 
284   /**
285    * Creates a new referenceNumberType from encoded stream.
286    */
fromPerAligned(byte[] encodedBytes)287   public static referenceNumberType fromPerAligned(byte[] encodedBytes) {
288     referenceNumberType result = new referenceNumberType();
289     result.decodePerAligned(new BitStreamReader(encodedBytes));
290     return result;
291   }
292 
encodePerUnaligned()293   @Override public Iterable<BitStream> encodePerUnaligned() {
294     return super.encodePerUnaligned();
295   }
296 
encodePerAligned()297   @Override public Iterable<BitStream> encodePerAligned() {
298     return super.encodePerAligned();
299   }
300 
decodePerUnaligned(BitStreamReader reader)301   @Override public void decodePerUnaligned(BitStreamReader reader) {
302     super.decodePerUnaligned(reader);
303   }
304 
decodePerAligned(BitStreamReader reader)305   @Override public void decodePerAligned(BitStreamReader reader) {
306     super.decodePerAligned(reader);
307   }
308 
toString()309   @Override public String toString() {
310     return toIndentedString("");
311   }
312 
toIndentedString(String indent)313   public String toIndentedString(String indent) {
314     return "referenceNumberType = " + getInteger() + ";\n";
315   }
316 }
317 
318 
319 
320 
321 
322 
323 
encodePerUnaligned()324   @Override public Iterable<BitStream> encodePerUnaligned() {
325     return super.encodePerUnaligned();
326   }
327 
encodePerAligned()328   @Override public Iterable<BitStream> encodePerAligned() {
329     return super.encodePerAligned();
330   }
331 
decodePerUnaligned(BitStreamReader reader)332   @Override public void decodePerUnaligned(BitStreamReader reader) {
333     super.decodePerUnaligned(reader);
334   }
335 
decodePerAligned(BitStreamReader reader)336   @Override public void decodePerAligned(BitStreamReader reader) {
337     super.decodePerAligned(reader);
338   }
339 
toString()340   @Override public String toString() {
341     return toIndentedString("");
342   }
343 
toIndentedString(String indent)344   public String toIndentedString(String indent) {
345     StringBuilder builder = new StringBuilder();
346     builder.append("PDU = {\n");
347     final String internalIndent = indent + "  ";
348     for (SequenceComponent component : getComponents()) {
349       if (component.isExplicitlySet()) {
350         builder.append(internalIndent)
351             .append(component.toIndentedString(internalIndent));
352       }
353     }
354     if (isExtensible()) {
355       builder.append(internalIndent).append("...\n");
356       for (SequenceComponent component : getExtensionComponents()) {
357         if (component.isExplicitlySet()) {
358           builder.append(internalIndent)
359               .append(component.toIndentedString(internalIndent));
360         }
361       }
362     }
363     builder.append(indent).append("};\n");
364     return builder.toString();
365   }
366 }
367