[][src]Struct tlv_parser::tlv::Tlv

pub struct Tlv { /* fields omitted */ }

Methods

impl Tlv[src]

pub fn new(tag: Tag, value: Value) -> Result<Tlv, TlvError>[src]

Creates Tlv object

Examples:

Create empty primitive TLV:

let primitive_tlv = Tlv::new(0x01, Value::Nothing).unwrap();

Create constructed TLV incapsulated primitive TLV:

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

pub fn tag(&self) -> Tag[src]

Returns tag number of TLV

pub fn tag_len(&self) -> usize[src]

Returns length of tag number

Examples

let tag_len = Tlv::new(0x01, Value::Nothing).unwrap().tag_len();
assert_eq!(tag_len, 1);

pub fn len(&self) -> usize[src]

Returns size of TLV-string in bytes

Examples

let tlv_len = Tlv::new(0x01, Value::Val(vec![0x02, 0x03])).unwrap().len();
assert_eq!(tlv_len, 4);

pub fn is_empty(&self) -> bool[src]

Returns true if Value of TLV is empty

pub fn val(&self) -> &Value[src]

Returns value if TLV

pub fn to_vec(&self) -> Vec<u8>[src]

Returns TLV-encoded array of bytes

Examples

let tlv = Tlv::new(0x21,
    Value::TlvList(vec![
        Tlv::new( 0x01, Value::Val(vec![0xA1, 0xA2])).unwrap(),
        Tlv::new( 0x02, Value::Val(vec![0xB1, 0xB2])).unwrap()])).unwrap();
assert_eq!(tlv.to_vec(), vec![0x21, 0x08, 0x01, 0x02, 0xA1, 0xA2, 0x02, 0x02, 0xB1, 0xB2]);

pub fn find_val(&self, path: &str) -> Option<&Value>[src]

Returns value of TLV

Example

let tlv = Tlv::from_vec(&[0x6F, 0x09, 0xA5, 0x07, 0xBF, 0x0C, 0x04, 0xDF, 0x7F, 0x01, 0x55])
    .unwrap();
if let &Value::Val(ref v) = tlv.find_val("6F / A5 / BF0C / DF7F").unwrap() {
    assert_eq!(*v, vec![0x55]);
}

pub fn is_primitive(&self) -> bool[src]

Returns true if TLV is primitive

pub fn from_vec(slice: &[u8]) -> Result<Tlv, TlvError>[src]

Initializes Tlv object from u8 slice

Examples

let tlv = Tlv::from_vec(&[0x01, 0x00]).unwrap();
assert_eq!(tlv.tag(), 0x01);
assert_eq!(tlv.tag_len(), 0x01);
assert_eq!(tlv.len(), 0x02);

Trait Implementations

impl Display for Tlv[src]

Auto Trait Implementations

impl Send for Tlv

impl Sync for Tlv

Blanket Implementations

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]