ltv="0.1"
```Rust
struct LTVObjectExample { #[ltv_field(1)] field1: u8, }
struct AnotherStruct { #[ltv_field(1)] field1: u8, }
enum MyCollection { Object1(LTVObjectExample), Object2(AnotherStruct), }
let myobjectbytes = LTVObjectExample{ field1: 55 }; asserteq!(myobjectbytes.toltvobject(), vec![ 4, // Total Length (length can be 1 or two bytes by setting lengthsize) 10, // Outer object ID (LTVObjectExample) 2, // Length of Field (field1) 1, // Field ID (field1) 55 //Field Value ]);
asserteq!(MyCollection::Object1(myobjectbytes).toltvobject(), vec![ 4, // Total Length (length can be 1 or two bytes by setting lengthsize) 10, // Outer object ID (LTVObjectExample) 2, // Length of Field (field1) 1, // Field ID (field1) 55 //Field Value ]);
```
```Rust
use ltv::*;
struct InnerStructData { #[ltvfield(1)] field1: u8, #[ltvfield(2)] field2: u16, }
struct ExampleStruct {
#[ltvfield(1)]
field1: InnerStructData,
#[ltvfield(2)]
field2: Option
fn main() { let original_ltv = ExampleStruct { field1: InnerStructData { field1: 19, field2: 77, }, field2: None, };
let ltv_bytes = original_ltv.to_ltv_object();
let new_ltv = ExampleStruct::from_ltv_object(<v_bytes).unwrap();
assert_eq!(original_ltv, new_ltv);
} ```
```Rust
struct BasicLTV{ field1: u8, }
impl<'a> LTVItem<{ ByteOrder::LE }> for BasicLTV {
type Item = Self;
fn fromltv(: usize, data: &[u8]) -> LTVResult
Rust
let original = BasicLTV{
field1: 0x35
};
// toltv only returns the [v] infomation of an object let buffer = original.toltv();
let out = BasicLTV::fromltv(0x01, &buffer).unwrap(); asserteq!(original, out); assert_eq!(&buffer, &[2, 0x01, 0x35]); ```
```Rust
struct InnerStructData {
field1: u8,
field2: u16,
}
impl
Ok(InnerStructData {
field1: reader.get_item::<u8>(0x1)?,
field2: reader.get_item::<u16>(0x2)?,
})
}
fn to_ltv(&self) -> Vec<u8> {
unimplemented!()
}
} ```
```Rust let inputdata: &[u8] = &[ 0x04, 0x01, 0x02, 0x01, 0xFF, 0x08, 0x02, 0x02, 0x01, 0x55, 0x03, 0x02, 0x01, 0x00, ]; let reader = LTVReaderLE::<1>::new(&inputdata[2..]);
let field1 = reader.getitem::
let field2 = reader.getitem::
asserteq!( field2, InnerStructData { field1: 0x55, field2: 0x0100 } ); ```