Skip to main content

TlvWriter

Struct TlvWriter 

Source
pub struct TlvWriter<'a> { /* private fields */ }
Expand description

A streaming TLV encoder that appends to a caller-provided Vec<u8>.

Implementations§

Source§

impl<'a> TlvWriter<'a>

Source

pub fn new(out: &'a mut Vec<u8>) -> Self

Construct a writer that appends to out. The writer borrows out mutably; release the borrow by dropping the writer.

Source

pub fn put_bool(&mut self, tag: Tag, v: bool) -> Result<()>

Emit a boolean value with the given tag.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_null(&mut self, tag: Tag) -> Result<()>

Emit a null value with the given tag.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_uint(&mut self, tag: Tag, v: u64) -> Result<()>

Emit an unsigned integer with the given tag. The minimum-width encoding (1, 2, 4, or 8 bytes) is chosen automatically per Matter Core Spec §A.2.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_int(&mut self, tag: Tag, v: i64) -> Result<()>

Emit a signed integer with the given tag. The minimum-width encoding (1, 2, 4, or 8 bytes) is chosen automatically per Matter Core Spec §A.2.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_float(&mut self, tag: Tag, v: f32) -> Result<()>

Emit a single-precision IEEE 754 float with the given tag.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_double(&mut self, tag: Tag, v: f64) -> Result<()>

Emit a double-precision IEEE 754 float with the given tag.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn put_utf8(&mut self, tag: Tag, v: &str) -> Result<()>

Emit a UTF-8 string with the given tag. The minimum-width length field (1, 2, 4, or 8 bytes) is chosen automatically.

§Errors

Returns Error::LengthOverflow if the string is longer than u64::MAX bytes (impossible in practice on any supported platform, but the return type is Result for portability).

Source

pub fn put_bytes(&mut self, tag: Tag, v: &[u8]) -> Result<()>

Emit an octet string with the given tag. The minimum-width length field (1, 2, 4, or 8 bytes) is chosen automatically.

§Errors

Returns Error::LengthOverflow if the slice is longer than u64::MAX bytes (impossible in practice on any supported platform, but the return type is Result for portability).

Source

pub fn put_preencoded(&mut self, tag: Tag, element: &[u8]) -> Result<()>

Splice an already-encoded TLV element into the stream under a new tag, replacing the element’s own tag control.

element MUST be a single complete TLV element encoded with an anonymous tag (one control octet, no tag bytes), e.g. the output of another TlvWriter that began with start_structure(Tag::Anonymous). Used to embed pre-encoded command-fields / payloads under a context tag without re-parsing them.

§Errors

Returns Error::UnexpectedEof if element is empty, Error::InvalidTagControl if element does not begin with an anonymous-tagged control octet, or Error::InvalidElementType if the element is a bare end-of-container marker (0x18), which is a delimiter, not a complete element.

Source

pub fn start_structure(&mut self, tag: Tag) -> Result<()>

Begin a structure with the given tag. Children must be emitted with their own put_* / write_value calls; the structure is closed with Self::end_container.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn start_array(&mut self, tag: Tag) -> Result<()>

Begin an array with the given tag. Children MUST be emitted with Tag::Anonymous per the Matter spec.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn start_list(&mut self, tag: Tag) -> Result<()>

Begin a list with the given tag. List members may carry any tag form (including anonymous).

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn end_container(&mut self) -> Result<()>

Emit the end-of-container marker (0x18) closing the most recently-opened container. The marker has no tag.

§Errors

Currently infallible; returns Ok(()) always. The Result return type is reserved for future I/O-backed writers.

Source

pub fn write_value(&mut self, tag: Tag, value: &Value) -> Result<()>

Walk a Value tree and emit the appropriate sequence of TLV elements. Scalar variants are dispatched to the corresponding put_* method; container variants (Structure, Array, List) recursively encode all members and close with Self::end_container.

Array elements are always written with Tag::Anonymous regardless of what tag is stored in the Value, enforcing the Matter spec requirement that array elements carry no tag.

Container nesting is bounded by MAX_DEPTH, mirroring the reader’s limit. A Value tree nested deeper than that is rejected with Error::ContainerTooDeep rather than risking a stack overflow on a hostile or buggy input tree.

§Errors

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for TlvWriter<'a>

§

impl<'a> Freeze for TlvWriter<'a>

§

impl<'a> RefUnwindSafe for TlvWriter<'a>

§

impl<'a> Send for TlvWriter<'a>

§

impl<'a> Sync for TlvWriter<'a>

§

impl<'a> Unpin for TlvWriter<'a>

§

impl<'a> UnsafeUnpin for TlvWriter<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.