Struct TlvWriter
pub struct TlvWriter {
packet: Vec<u8>,
overflow: bool,
}Expand description
Writes the TLVs of a request.
The writer leaves room for the message header, so sending the request doesn’t copy the TLVs.
§Example
use ql_qmi::codec::TlvWriter;
let mut tlvs = TlvWriter::new();
tlvs.tlv(0x01, &1u8)
.tlv(0x10, "apn")
.optional::<u16>(0x11, None);
assert_eq!(
tlvs.body(),
[0x01, 0x01, 0x00, 0x01, 0x10, 0x03, 0x00, b'a', b'p', b'n'],
);Fields§
§packet: Vec<u8>§overflow: boolImplementations§
§impl TlvWriter
impl TlvWriter
const DEFAULT_CAPACITY: usize
const DEFAULT_CAPACITY: usize
Room for the TLVs of most requests. The packet then fits into 64 bytes.
pub fn new() -> Self
pub fn new() -> Self
Returns a writer without TLVs.
The buffer has room for the TLVs of most requests, and grows for larger ones.
pub fn with_capacity(len: usize) -> Self
pub fn with_capacity(len: usize) -> Self
Returns a writer with room for len bytes of TLVs.
Writing more than len bytes grows the buffer.
pub fn tlv<T: Encode + ?Sized>(&mut self, kind: u8, value: &T) -> &mut Self
pub fn tlv<T: Encode + ?Sized>(&mut self, kind: u8, value: &T) -> &mut Self
Writes a TLV.
A value longer than u16::MAX bytes is dropped, and sending the
request fails with Error::TlvTooLarge.
pub fn optional<T: Encode + ?Sized>(
&mut self,
kind: u8,
value: Option<&T>,
) -> &mut Self
pub fn optional<T: Encode + ?Sized>( &mut self, kind: u8, value: Option<&T>, ) -> &mut Self
Writes a TLV if value is set.
pub(crate) fn into_packet(self, msg_id: u16) -> Result<Packet, Error>
pub(crate) fn into_packet(self, msg_id: u16) -> Result<Packet, Error>
Writes the request header and returns the writer’s buffer as the packet, without allocating.
The connection sets the transaction ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TlvWriter
impl RefUnwindSafe for TlvWriter
impl Send for TlvWriter
impl Sync for TlvWriter
impl Unpin for TlvWriter
impl UnsafeUnpin for TlvWriter
impl UnwindSafe for TlvWriter
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