pub struct TLV<'a> {
pub tag: TLVTag,
pub value: TLVValue<'a>,
}Expand description
A high-level representation of a TLV tag + value.
Amongsat other things, it is a convenient way to emit TLV byte sequences.
A TLV can be constructed programmatically, or returned from a TLVElement.
Unlike a TLVElement however, a TLV does not represent a complete container,
but rather, its beginning or end.
I.e.
use rs_matter::tlv::{TLV, TLVTag, TLVValue};
let tlvs = &[
TLV::new(TLVTag::Anonymous, TLVValue::Struct),
TLV::new(TLVTag::Context(0), TLVValue::Utf8l("Hello, World!")),
TLV::new(TLVTag::Anonymous, TLVValue::EndCnt),
];
let bytes_iter = tlvs.iter().flat_map(|tlv| tlv.bytes_iter());
for byte in bytes_iter {
println!("{:02X}", byte);
}Fields§
§tag: TLVTag§value: TLVValue<'a>Implementations§
Source§impl<'a> TLV<'a>
impl<'a> TLV<'a>
Sourcepub const fn new(tag: TLVTag, value: TLVValue<'a>) -> TLV<'a>
pub const fn new(tag: TLVTag, value: TLVValue<'a>) -> TLV<'a>
Create a new TLV instance with the provided tag and value.
Sourcepub const fn i8(tag: TLVTag, value: i8) -> TLV<'a>
pub const fn i8(tag: TLVTag, value: i8) -> TLV<'a>
Create a TLV with the given tag and the provided value as an S8 TLV.
Sourcepub const fn i16(tag: TLVTag, value: i16) -> TLV<'a>
pub const fn i16(tag: TLVTag, value: i16) -> TLV<'a>
Create a TLV with the given tag and the provided value as an S8 or S16 TLV, depending on whether the value is small enough to fit in an S8 TLV.
Sourcepub const fn i32(tag: TLVTag, value: i32) -> TLV<'a>
pub const fn i32(tag: TLVTag, value: i32) -> TLV<'a>
Create a TLV with the given tag and the provided value as an S8, S16, or S32 TLV, depending on whether the value is small enough to fit in an S8 or S16 TLV.
Sourcepub const fn i64(tag: TLVTag, value: i64) -> TLV<'a>
pub const fn i64(tag: TLVTag, value: i64) -> TLV<'a>
Create a TLV with the given tag and the provided value as an S8, S16, S32, or S64 TLV, depending on whether the value is small enough to fit in an S8, S16, or S32 TLV.
Sourcepub const fn u8(tag: TLVTag, value: u8) -> TLV<'a>
pub const fn u8(tag: TLVTag, value: u8) -> TLV<'a>
Create a TLV with the given tag and the provided value as a U8 TLV.
Sourcepub const fn u16(tag: TLVTag, value: u16) -> TLV<'a>
pub const fn u16(tag: TLVTag, value: u16) -> TLV<'a>
Create a TLV with the given tag and the provided value as a U8 or U16 TLV, depending on whether the value is small enough to fit in a U8 TLV.
Sourcepub const fn u32(tag: TLVTag, value: u32) -> TLV<'a>
pub const fn u32(tag: TLVTag, value: u32) -> TLV<'a>
Create a TLV with the given tag and the provided value as a U8, U16, or U32 TLV, depending on whether the value is small enough to fit in a U8 or U16 TLV.
Sourcepub const fn u64(tag: TLVTag, value: u64) -> TLV<'a>
pub const fn u64(tag: TLVTag, value: u64) -> TLV<'a>
Create a TLV with the given tag and the provided value as a U8, U16, U32, or U64 TLV, depending on whether the value is small enough to fit in a U8, U16, or U32 TLV.
Sourcepub const fn f32(tag: TLVTag, value: f32) -> TLV<'a>
pub const fn f32(tag: TLVTag, value: f32) -> TLV<'a>
Create a TLV with the given tag and the provided value as a F32 TLV.
Sourcepub const fn f64(tag: TLVTag, value: f64) -> TLV<'a>
pub const fn f64(tag: TLVTag, value: f64) -> TLV<'a>
Create a TLV with the given tag and the provided value as a F64 TLV.
Sourcepub const fn utf8(tag: TLVTag, value: &'a str) -> TLV<'a>
pub const fn utf8(tag: TLVTag, value: &'a str) -> TLV<'a>
Create a TLV with the given tag and the provided value as a UTF-8 TLV. The length of the string is encoded as 1, 2, 4 or 8 octets, depending on the length of the string.
Sourcepub const fn str(tag: TLVTag, value: &'a [u8]) -> TLV<'a>
pub const fn str(tag: TLVTag, value: &'a [u8]) -> TLV<'a>
Create a TLV with the given tag and the provided value as an octet string TLV. The length of the string is encoded as 1, 2, 4 or 8 octets, depending on the length of the string.
Sourcepub const fn struct(tag: TLVTag) -> TLV<'a>
pub const fn struct(tag: TLVTag) -> TLV<'a>
Create a TLV with the given tag which will have a value of type Struct (start).
Sourcepub const fn structure(tag: TLVTag) -> TLV<'a>
pub const fn structure(tag: TLVTag) -> TLV<'a>
Create a TLV with the given tag which will have a value of type Struct (start).
Sourcepub const fn array(tag: TLVTag) -> TLV<'a>
pub const fn array(tag: TLVTag) -> TLV<'a>
Create a TLV with the given tag which will have a value of type Array (start).
Sourcepub const fn list(tag: TLVTag) -> TLV<'a>
pub const fn list(tag: TLVTag) -> TLV<'a>
Create a TLV with the given tag which will have a value of type List (start).
Sourcepub const fn end_container() -> TLV<'a>
pub const fn end_container() -> TLV<'a>
Create a TLV with the given tag which will have a value of type EndCnt (container end).
Sourcepub const fn null(tag: TLVTag) -> TLV<'a>
pub const fn null(tag: TLVTag) -> TLV<'a>
Create a TLV with the given tag which will have a value of type Null.
Sourcepub const fn bool(tag: TLVTag, value: bool) -> TLV<'a>
pub const fn bool(tag: TLVTag, value: bool) -> TLV<'a>
Create a TLV with the given tag which will have a value of type True.
Sourcepub fn into_tlv_iter(self) -> Once<Result<TLV<'a>, Error>> ⓘ
pub fn into_tlv_iter(self) -> Once<Result<TLV<'a>, Error>> ⓘ
Converts the TLV into an iterator with a single item - the TLV.
Sourcepub fn bytes_iter(&self) -> TLVBytesIter<'a, &TLVTag, &TLVValue<'a>> ⓘ
pub fn bytes_iter(&self) -> TLVBytesIter<'a, &TLVTag, &TLVValue<'a>> ⓘ
Returns an iterator over the bytes of the TLV.
Sourcepub fn into_bytes_iter(self) -> TLVBytesIter<'a, TLVTag, TLVValue<'a>> ⓘ
pub fn into_bytes_iter(self) -> TLVBytesIter<'a, TLVTag, TLVValue<'a>> ⓘ
Converts the TLV into an iterator over its bytes.
Sourcepub fn result_into_bytes_iter(
result: Result<TLV<'a>, Error>,
) -> TLVResultBytesIter<'a, TLVTag, TLVValue<'a>> ⓘ
pub fn result_into_bytes_iter( result: Result<TLV<'a>, Error>, ) -> TLVResultBytesIter<'a, TLVTag, TLVValue<'a>> ⓘ
Converts the provided result into an iterator over the bytes of the TLV.
Trait Implementations§
Source§impl<'a> IntoIterator for TLV<'a>
impl<'a> IntoIterator for TLV<'a>
Source§impl<'s, 'a> IntoIterator for &'s TLV<'a>
impl<'s, 'a> IntoIterator for &'s TLV<'a>
impl<'a> StructuralPartialEq for TLV<'a>
Auto Trait Implementations§
impl<'a> Freeze for TLV<'a>
impl<'a> RefUnwindSafe for TLV<'a>
impl<'a> Send for TLV<'a>
impl<'a> Sync for TLV<'a>
impl<'a> Unpin for TLV<'a>
impl<'a> UnsafeUnpin for TLV<'a>
impl<'a> UnwindSafe for TLV<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more