1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

use std::fmt::Write;

mod group;
mod object;

pub fn object(key: &str, val: &str) -> Vec<u8> {
    object::run(key, val)
}

pub fn group(objs: Vec<(String, String)>) -> Vec<u8> {
    group::run(objs)
}

pub fn u128(val: &u128) -> String {
    encode_hex(&val.to_le_bytes().to_vec())
}

pub fn bytes(val: &Vec<u8>) -> String {
    encode_hex(val)
}

fn encode_hex(bytes: &Vec<u8>) -> String {
    let mut s = String::with_capacity((bytes.len() * 2) + 2);
    s.push_str("0X");
    for &b in bytes {
        write!(&mut s, "{:02X}", b).unwrap();
    }
    s
}