Struct Tlvs
pub struct Tlvs {
body: Bytes,
}Expand description
The TLVs of a message.
This wraps a buffer that is known to split into whole TLVs. Decoded bytes and strings share the buffer.
§Example
use bytes::Bytes;
use ql_qmi::codec::{DecodeError, Tlvs, Utf8Bytes};
let body = Bytes::from_static(&[0x01, 0x02, 0x00, 0x34, 0x12, 0x10, 0x02, 0x00, b'o', b'k']);
let tlvs = Tlvs::new(body)?;
assert_eq!(tlvs.get::<u16>(0x01)?, 0x1234);
assert_eq!(tlvs.optional::<Utf8Bytes>(0x10)?.as_deref(), Some("ok"));
assert_eq!(tlvs.optional::<u8>(0x11)?, None);Fields§
§body: BytesImplementations§
§impl Tlvs
impl Tlvs
pub fn new(body: Bytes) -> Result<Self, DecodeError>
pub fn new(body: Bytes) -> Result<Self, DecodeError>
Checks that body splits into whole TLVs.
§Errors
Returns DecodeError::Truncated if the last TLV is cut off.
pub fn get<T: Decode>(&self, kind: u8) -> Result<T, DecodeError>
pub fn get<T: Decode>(&self, kind: u8) -> Result<T, DecodeError>
Trait Implementations§
impl Eq for Tlvs
§impl<'a> IntoIterator for &'a Tlvs
impl<'a> IntoIterator for &'a Tlvs
impl StructuralPartialEq for Tlvs
Auto Trait Implementations§
impl !Freeze for Tlvs
impl RefUnwindSafe for Tlvs
impl Send for Tlvs
impl Sync for Tlvs
impl Unpin for Tlvs
impl UnsafeUnpin for Tlvs
impl UnwindSafe for Tlvs
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
Mutably borrows from an owned value. Read more