pub struct Tlv {
pub tag: u16,
pub length: u16,
pub value: Vec<u8>,
}Expand description
Tag-Length-Value (TLV) Parameter
Fields§
§tag: u16The tag identifier for the parameter
length: u16The length of the value field
value: Vec<u8>The value of the parameter
Implementations§
Source§impl Tlv
impl Tlv
Sourcepub fn new_from_name(name: &str, value: Vec<u8>) -> Self
pub fn new_from_name(name: &str, value: Vec<u8>) -> Self
Convenience: create a TLV using a string name for the tag
Sourcepub fn new_u8_from_name(name: &str, val: u8) -> Self
pub fn new_u8_from_name(name: &str, val: u8) -> Self
Convenience: create u8 TLV from name
Sourcepub fn new_u16_from_name(name: &str, val: u16) -> Self
pub fn new_u16_from_name(name: &str, val: u16) -> Self
Convenience: create u16 TLV from name
Sourcepub fn new_string(tag: u16, val: &str) -> Self
pub fn new_string(tag: u16, val: &str) -> Self
Creates a new TLV with a C-style string value (null-terminated).
Sourcepub fn new_payload(tag: u16, val: Vec<u8>) -> Self
pub fn new_payload(tag: u16, val: Vec<u8>) -> Self
Creates a new TLV with a raw payload.
Sourcepub fn encode(&self, writer: &mut impl Write) -> Result<(), PduError>
pub fn encode(&self, writer: &mut impl Write) -> Result<(), PduError>
Encodes the TLV into the writer.
Sourcepub fn decode(cursor: &mut Cursor<&[u8]>) -> Result<Option<Self>, PduError>
pub fn decode(cursor: &mut Cursor<&[u8]>) -> Result<Option<Self>, PduError>
Decodes a TLV from the cursor.
Sourcepub fn value_as_u8(&self) -> Result<u8, PduError>
pub fn value_as_u8(&self) -> Result<u8, PduError>
Returns the value as a u8 (if length is 1).
Sourcepub fn value_as_u16(&self) -> Result<u16, PduError>
pub fn value_as_u16(&self) -> Result<u16, PduError>
Returns the value as a u16 (if length is 2).
Sourcepub fn value_as_string(&self) -> Result<String, PduError>
pub fn value_as_string(&self) -> Result<String, PduError>
Returns the value as a String (removes trailing null if present).
Trait Implementations§
impl StructuralPartialEq for Tlv
Auto Trait Implementations§
impl Freeze for Tlv
impl RefUnwindSafe for Tlv
impl Send for Tlv
impl Sync for Tlv
impl Unpin for Tlv
impl UnwindSafe for Tlv
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