pub mod concat;
pub mod gsm7;
pub mod pdu;
pub mod ucs2;
pub fn hex_decode(s: &str) -> Option<Vec<u8>> {
let s = s.trim().as_bytes();
if s.len() % 2 != 0 {
return None;
}
s.chunks_exact(2)
.map(|p| Some((hex_val(p[0])? << 4) | hex_val(p[1])?))
.collect()
}
pub fn hex_encode(bytes: &[u8]) -> String {
const D: &[u8; 16] = b"0123456789ABCDEF";
let mut s = String::with_capacity(bytes.len() * 2);
for b in bytes {
s.push(char::from(D[usize::from(b >> 4)]));
s.push(char::from(D[usize::from(b & 15)]));
}
s
}
fn hex_val(c: u8) -> Option<u8> {
match c {
b'0'..=b'9' => Some(c - b'0'),
b'a'..=b'f' => Some(c - b'a' + 10),
b'A'..=b'F' => Some(c - b'A' + 10),
_ => None,
}
}