blob: 8c5acaa092ac7320a58407b323c64e8f08122093 [file] [log] [blame]
slowr60d4d102017-08-16 18:33:58 -07001/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08004package org.onosproject.xran.asn1lib.ber.types;
slowr60d4d102017-08-16 18:33:58 -07005
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08006import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
7import org.onosproject.xran.asn1lib.ber.BerTag;
slowr60d4d102017-08-16 18:33:58 -07008
9import java.io.IOException;
10import java.io.InputStream;
11import java.math.BigInteger;
12
13public class BerEnum extends BerInteger {
14
15 public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.ENUMERATED_TAG);
16 private static final long serialVersionUID = 1L;
17
18 public BerEnum() {
19 }
20
21 public BerEnum(byte[] code) {
22 this.code = code;
23 }
24
25 public BerEnum(BigInteger val) {
26 this.value = val;
27 }
28
29 public BerEnum(long val) {
30 this.value = BigInteger.valueOf(val);
31 }
32
33 @Override
34 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
35
36 int codeLength = super.encode(os, false);
37
38 if (withTag) {
39 codeLength += tag.encode(os);
40 }
41
42 return codeLength;
43 }
44
45 @Override
46 public int decode(InputStream is, boolean withTag) throws IOException {
47
48 int codeLength = 0;
49
50 if (withTag) {
51 codeLength += tag.decodeAndCheck(is);
52 }
53
54 codeLength += super.decode(is, false);
55
56 return codeLength;
57 }
58
59}