1 /***
2 * Java DAB EPG API - Serialize/Deserialize To/From POJOs to XML/Binary as per
3 * ETSI specifications TS 102 818 (XML Specification for DAB EPG) and TS 102
4 * 371 (Transportation and Binary Encoding Specification for EPG).
5 *
6 * Copyright (C) 2007 GCap Media PLC
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 package com.gcapmedia.dab.epg.binary;
23
24
25 /***
26 * List all defined token tags as per ETSI TS 101 371 V1.2.1 (2006-02)
27 */
28 public enum TokenTag implements Encodable {
29
30 TOKEN_1(0x01),
31 TOKEN_2(0x02),
32 TOKEN_3(0x03),
33 TOKEN_4(0x04),
34 TOKEN_5(0x05),
35 TOKEN_6(0x06),
36 TOKEN_7(0x07),
37 TOKEN_8(0x08),
38 TOKEN_9(0x0B),
39 TOKEN_10(0x0C),
40 TOKEN_11(0x0E),
41 TOKEN_12(0x0F),
42 TOKEN_13(0x10),
43 TOKEN_14(0x11),
44 TOKEN_15(0x12),
45 TOKEN_16(0x13);
46
47 /***
48 * Attribute tag value
49 */
50 private byte value;
51
52 /***
53 *
54 * @param value
55 */
56 TokenTag(int value) {
57 this.value = (byte)value;
58 }
59
60 /***
61 * @see com.gcapmedia.dab.epg.binary.Encodable#getBytes()
62 */
63 public byte[] getBytes() {
64 BitBuilder bits = new BitBuilder(8);
65 bits.put(0, value);
66 return bits.toByteArray();
67 }
68
69 /***
70 * @return Returns the tag value
71 */
72 public int getValue() {
73 return value & 0xFF;
74 }
75
76 /***
77 * @see com.gcapmedia.dab.epg.binary.Encodable#getLength()
78 */
79 public int getLength() {
80 return 1;
81 }
82
83 /***
84 * Parse an object from its byte array representation
85 * @param parent Tag parent
86 * @param bytes Byte array representation
87 */
88 public static TokenTag fromBytes(byte[] bytes) {
89 BitParser parser = new BitParser(bytes);
90 int value = parser.getInt(0, 8);
91 TokenTag result = null;
92 for(TokenTag tag : values()) {
93 if(tag.getValue() == value) {
94 result = tag;
95 break;
96 }
97 }
98 if(result == null) {
99 throw new IllegalArgumentException("Tag not found for value: " + value);
100 }
101 return result;
102 }
103
104 public static boolean isToken(byte bite) {
105 for(TokenTag tag : values()) {
106 if(tag.getValue() == bite) {
107 return true;
108 }
109 }
110 return false;
111 }
112
113 }