Skip to main content

TlvWriter

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: bool

Implementations§

§

impl TlvWriter

const DEFAULT_CAPACITY: usize

Room for the TLVs of most requests. The packet then fits into 64 bytes.

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

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

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

Writes a TLV if value is set.

pub fn append(&mut self, tlvs: &Tlvs) -> &mut Self

Appends encoded TLVs.

pub fn body(&self) -> &[u8] ⓘ

Returns the encoded TLVs written so far.

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§

§

impl Clone for TlvWriter

§

fn clone(&self) -> TlvWriter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for TlvWriter

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for TlvWriter

§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more