wacore_binary/
token.rs

1pub const DICT_VERSION: u8 = 3;
2
3// --- Public Constants for Special Tags ---
4pub const LIST_EMPTY: u8 = 0;
5pub const DICTIONARY_0: u8 = 236;
6pub const DICTIONARY_1: u8 = 237;
7pub const DICTIONARY_2: u8 = 238;
8pub const DICTIONARY_3: u8 = 239;
9
10pub const JID_PAIR: u8 = 250;
11pub const HEX_8: u8 = 251;
12pub const BINARY_8: u8 = 252;
13pub const BINARY_20: u8 = 253;
14pub const BINARY_32: u8 = 254;
15pub const NIBBLE_8: u8 = 255;
16pub const INTEROP_JID: u8 = 245;
17pub const FB_JID: u8 = 246;
18pub const AD_JID: u8 = 247;
19pub const LIST_8: u8 = 248;
20pub const LIST_16: u8 = 249;
21
22pub const PACKED_MAX: u8 = 127;
23pub const SINGLE_BYTE_MAX: u16 = 256;
24
25// Include the generated maps from the build script
26include!(concat!(env!("OUT_DIR"), "/token_maps.rs"));
27
28// The lookup functions now use the compile-time maps
29pub fn index_of_single_token(token: &str) -> Option<u8> {
30    SINGLE_BYTE_MAP.get(token).copied()
31}
32
33pub fn index_of_double_byte_token(token: &str) -> Option<(u8, u8)> {
34    DOUBLE_BYTE_MAP.get(token).copied()
35}
36
37pub fn get_single_token(index: u8) -> Option<&'static str> {
38    SINGLE_BYTE_TOKENS.get(index as usize).copied()
39}
40
41pub fn get_double_token(dict: u8, index: u8) -> Option<&'static str> {
42    DOUBLE_BYTE_TOKENS
43        .get(dict as usize)
44        .and_then(|d| d.get(index as usize))
45        .copied()
46}