Skip to main content

WriteBuf

Struct WriteBuf 

Source
pub struct WriteBuf<'a> { /* private fields */ }

Implementations§

Source§

impl WriteBuf<'_>

Source

pub fn str_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>

Write a tag and a TLV Octet String to the TLV stream, where the Octet String is a slice of u8 bytes.

The writing is done via a user-supplied callback cb, that is expected to fill the provided buffer with the data and to return the length of the written data.

This method is useful when the data to be written needs to be computed first, and the computation needs a buffer where to operate.

Note that this method reserves a Str16l header before invoking the callback, restricting the data length to no more than 65535 bytes. If the actual length fits in a single byte, the header is downgraded in-place to a canonical Str8l encoding (shortest-form length), which some strict Matter controllers (e.g. SmartThings) require.

Source

pub fn utf8_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>

Write a tag and a TLV UTF-8 String to the TLV stream, where the UTF-8 String is a str.

The writing is done via a user-supplied callback cb, that is expected to fill the provided buffer with the data and to return the length of the written data.

This method is useful when the data to be written needs to be computed first, and the computation needs a buffer where to operate.

Note that this method reserves a Utf16l header before invoking the callback, restricting the data length to no more than 65535 bytes. If the actual length fits in a single byte, the header is downgraded in-place to a canonical Utf8l encoding (shortest-form length).

Source§

impl<'a> WriteBuf<'a>

Source

pub fn new(buf: &'a mut [u8]) -> WriteBuf<'a>

Source

pub fn new_with(buf: &'a mut [u8], start: usize, end: usize) -> WriteBuf<'a>

Source

pub fn get_start(&self) -> usize

Source

pub fn get_tail(&self) -> usize

Source

pub fn rewind_tail_to(&mut self, new_end: usize)

Source

pub fn forward_tail_by(&mut self, new_offset: usize)

Source

pub fn as_slice(&self) -> &[u8]

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Source

pub fn empty_as_mut_slice(&mut self) -> &mut [u8]

Source

pub fn split(self) -> (&'a mut [u8], WriteBuf<'a>)

Source

pub fn split_str(self) -> (&'a str, WriteBuf<'a>)

Source

pub fn into_buf(self) -> &'a mut [u8]

Source

pub fn reset(&mut self)

Source

pub fn load(&mut self, wb: &WriteBuf<'_>) -> Result<(), Error>

Source

pub fn reserve(&mut self, reserve: usize) -> Result<(), Error>

Source

pub fn shrink(&mut self, with: usize) -> Result<(), Error>

Source

pub fn expand(&mut self, by: usize) -> Result<(), Error>

Source

pub fn prepend_with<F>(&mut self, size: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut WriteBuf<'a>),

Source

pub fn prepend(&mut self, src: &[u8]) -> Result<(), Error>

Source

pub fn append_with_buf<F>(&mut self, f: F) -> Result<usize, Error>
where F: FnOnce(&mut [u8]) -> Result<usize, Error>,

Source

pub fn append_with<F>(&mut self, size: usize, f: F) -> Result<(), Error>
where F: FnOnce(&mut WriteBuf<'a>),

Source

pub fn append(&mut self, src: &[u8]) -> Result<(), Error>

Source

pub fn copy_from_slice(&mut self, src: &[u8]) -> Result<(), Error>

Source

pub fn le_i8(&mut self, data: i8) -> Result<(), Error>

Source

pub fn le_u8(&mut self, data: u8) -> Result<(), Error>

Source

pub fn le_u16(&mut self, data: u16) -> Result<(), Error>

Source

pub fn le_i16(&mut self, data: i16) -> Result<(), Error>

Source

pub fn le_u32(&mut self, data: u32) -> Result<(), Error>

Source

pub fn le_i32(&mut self, data: i32) -> Result<(), Error>

Source

pub fn le_u64(&mut self, data: u64) -> Result<(), Error>

Source

pub fn le_i64(&mut self, data: i64) -> Result<(), Error>

Trait Implementations§

Source§

impl<'a> Debug for WriteBuf<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl TLVWrite for WriteBuf<'_>

Source§

type Position = usize

Source§

fn write(&mut self, byte: u8) -> Result<(), Error>

Append a single byte to the TLV stream.
Source§

fn get_tail(&self) -> <WriteBuf<'_> as TLVWrite>::Position

Get the current position in the TLV stream. Read more
Source§

fn rewind_to(&mut self, pos: <WriteBuf<'_> as TLVWrite>::Position)

Rewind the TLV stream to a previous position. Read more
Source§

fn available_space(&mut self) -> &mut [u8]

Get a mutable slice of the available space in the TLV stream. Read more
Source§

fn str_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>

Write a tag and a TLV Octet String to the TLV stream, where the Octet String is a slice of u8 bytes. Read more
Source§

fn utf8_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>

Write a tag and a TLV UTF-8 String to the TLV stream, where the UTF-8 String is a str. Read more
Source§

fn write_ctx<T>(&mut self, ctx: u8, value: &T) -> Result<(), Error>
where T: ToTLV, Self: Sized,

Write value under a context tag. Read more
Source§

fn tlv(&mut self, tag: &TLVTag, value: &TLVValue<'_>) -> Result<(), Error>

Write a TLV tag and value to the TLV stream.
Source§

fn i8(&mut self, tag: &TLVTag, data: i8) -> Result<(), Error>

Write a tag and a TLV S8 value to the TLV stream.
Source§

fn u8(&mut self, tag: &TLVTag, data: u8) -> Result<(), Error>

Write a tag and a TLV U8 value to the TLV stream.
Source§

fn i16(&mut self, tag: &TLVTag, data: i16) -> Result<(), Error>

Write a tag and a TLV S16 or (if the data is small enough) S8 value to the TLV stream.
Source§

fn u16(&mut self, tag: &TLVTag, data: u16) -> Result<(), Error>

Write a tag and a TLV U16 or (if the data is small enough) U8 value to the TLV stream.
Source§

fn i32(&mut self, tag: &TLVTag, data: i32) -> Result<(), Error>

Write a tag and a TLV S32 or (if the data is small enough) S16 or S8 value to the TLV stream.
Source§

fn u32(&mut self, tag: &TLVTag, data: u32) -> Result<(), Error>

Write a tag and a TLV U32 or (if the data is small enough) U16 or U8 value to the TLV stream.
Source§

fn i64(&mut self, tag: &TLVTag, data: i64) -> Result<(), Error>

Write a tag and a TLV S64 or (if the data is small enough) S32, S16, or S8 value to the TLV stream.
Source§

fn u64(&mut self, tag: &TLVTag, data: u64) -> Result<(), Error>

Write a tag and a TLV U64 or (if the data is small enough) U32, U16, or U8 value to the TLV stream.
Source§

fn f32(&mut self, tag: &TLVTag, data: f32) -> Result<(), Error>

Write a tag and a TLV F32 to the TLV stream.
Source§

fn f64(&mut self, tag: &TLVTag, data: f64) -> Result<(), Error>

Write a tag and a TLV F64 to the TLV stream.
Source§

fn str(&mut self, tag: &TLVTag, data: &[u8]) -> Result<(), Error>

Write a tag and a TLV Octet String to the TLV stream, where the Octet String is a slice of u8 bytes. Read more
Source§

fn stri<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>
where I: IntoIterator<Item = u8>,

Write a tag and a TLV Octet String to the TLV stream, where the Octet String is anything that can be turned into an iterator of u8 bytes. Read more
Source§

fn utf8(&mut self, tag: &TLVTag, data: &str) -> Result<(), Error>

Write a tag and a TLV UTF-8 String to the TLV stream, where the UTF-8 String is a str. Read more
Source§

fn utf8i<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>
where I: IntoIterator<Item = u8>,

Write a tag and a TLV UTF-8 String to the TLV stream, where the UTF-8 String is anything that can be turned into an iterator of u8 bytes. Read more
Source§

fn start_struct(&mut self, tag: &TLVTag) -> Result<(), Error>

Write a tag and a value indicating the start of a Struct TLV container. Read more
Source§

fn start_array(&mut self, tag: &TLVTag) -> Result<(), Error>

Write a tag and a value indicating the start of an Array TLV container. Read more
Source§

fn start_list(&mut self, tag: &TLVTag) -> Result<(), Error>

Write a tag and a value indicating the start of a List TLV container. Read more
Source§

fn start_container( &mut self, tag: &TLVTag, container_type: TLVValueType, ) -> Result<(), Error>

Write a tag and a value indicating the start of a Struct TLV container. Read more
Source§

fn end_container(&mut self) -> Result<(), Error>

Write a value indicating the end of a Struct, Array, or List TLV container. Read more
Source§

fn null(&mut self, tag: &TLVTag) -> Result<(), Error>

Write a tag and a TLV Null value to the TLV stream.
Source§

fn bool(&mut self, tag: &TLVTag, val: bool) -> Result<(), Error>

Write a tag and a TLV True or False value to the TLV stream.
Source§

fn raw_value( &mut self, tag: &TLVTag, value_type: TLVValueType, value_payload: &[u8], ) -> Result<(), Error>

Write a tag and a raw, already-encoded TLV value represented as a byte slice.
Source§

fn write_raw_data<I>(&mut self, bytes: I) -> Result<(), Error>
where I: IntoIterator<Item = u8>,

Append multiple raw bytes to the TLV stream.
Source§

impl Write for WriteBuf<'_>

Source§

fn write_str(&mut self, s: &str) -> Result<(), Error>

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

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

§

impl<'a> Freeze for WriteBuf<'a>

§

impl<'a> RefUnwindSafe for WriteBuf<'a>

§

impl<'a> Send for WriteBuf<'a>

§

impl<'a> Sync for WriteBuf<'a>

§

impl<'a> Unpin for WriteBuf<'a>

§

impl<'a> UnsafeUnpin for WriteBuf<'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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, I> IntoFallibleInit<T> for I
where I: Init<T>,

Source§

fn into_fallible<E>(self) -> impl Init<T, E>

Convert the infallible initializer to a fallible one.
Source§

impl<Source, Target> OctetsInto<Target> for Source
where Target: OctetsFrom<Source>,

Source§

type Error = <Target as OctetsFrom<Source>>::Error

Source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
Source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V