21 unstable releases

0.10.0 Sep 24, 2024
0.9.0 Feb 2, 2024
0.8.0 Aug 17, 2023
0.7.1 May 13, 2022
0.1.1 Jul 30, 2016

#393 in Parser implementations

Download history 1989/week @ 2024-07-25 2033/week @ 2024-08-01 1994/week @ 2024-08-08 1783/week @ 2024-08-15 2113/week @ 2024-08-22 2123/week @ 2024-08-29 1112/week @ 2024-09-05 1444/week @ 2024-09-12 1233/week @ 2024-09-19 376/week @ 2024-09-26 1779/week @ 2024-10-03 1396/week @ 2024-10-10 833/week @ 2024-10-17 974/week @ 2024-10-24 1501/week @ 2024-10-31 1716/week @ 2024-11-07

5,180 downloads per month

MIT/Apache

22KB
484 lines

tlv-parser

Build status Latest Version Docs

Library for parsing BER-TLV

Library supports parsing from &[u8] and emitting Vec<u8>.

This is no_std crate if you can use core::alloc.

For usage see decode-tlv/src/main.rs.

$ echo "7003820151" | cargo run
     Running `target/debug/decode-tlv`
	 tag=70
	   tag=82,     len=1,    data=51 Q

lib.rs:

A library to parse and emit BER-TLV data.

#Examples

Parse TLV:

use tlv_parser::tlv::{Tlv, Value};

let input: Vec<u8> = vec![0x21, 0x05, 0x22, 0x03, 0x03, 0x01, 0xaa];
let tlv = Tlv::from_vec( &input ).unwrap();

if let Some(&Value::Val(ref val)) = tlv.find_val("21 / 22 / 03") {
    assert_eq!(*val, vec![0xaa]);
}

Emit constructed TLV incapsulated primitive TLV:

use tlv_parser::tlv::*;

let primitive_tlv = Tlv::new(0x01, Value::Nothing).unwrap();
let constructed_tlv = Tlv::new(0x21, Value::TlvList(vec![primitive_tlv])).unwrap();

assert_eq!(constructed_tlv.to_vec(), vec![0x21, 0x02, 0x01, 0x00]);

No runtime deps