pub struct WriteBuf<'a> { /* private fields */ }Implementations§
Source§impl WriteBuf<'_>
impl WriteBuf<'_>
Sourcepub fn str_cb(
&mut self,
tag: &TLVTag,
cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>,
) -> Result<(), Error>
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.
Sourcepub fn utf8_cb(
&mut self,
tag: &TLVTag,
cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>,
) -> Result<(), Error>
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>
impl<'a> WriteBuf<'a>
pub fn new(buf: &'a mut [u8]) -> WriteBuf<'a>
pub fn new_with(buf: &'a mut [u8], start: usize, end: usize) -> WriteBuf<'a>
pub fn get_start(&self) -> usize
pub fn get_tail(&self) -> usize
pub fn rewind_tail_to(&mut self, new_end: usize)
pub fn forward_tail_by(&mut self, new_offset: usize)
pub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn empty_as_mut_slice(&mut self) -> &mut [u8] ⓘ
pub fn split(self) -> (&'a mut [u8], WriteBuf<'a>)
pub fn split_str(self) -> (&'a str, WriteBuf<'a>)
pub fn into_buf(self) -> &'a mut [u8] ⓘ
pub fn reset(&mut self)
pub fn load(&mut self, wb: &WriteBuf<'_>) -> Result<(), Error>
pub fn reserve(&mut self, reserve: usize) -> Result<(), Error>
pub fn shrink(&mut self, with: usize) -> Result<(), Error>
pub fn expand(&mut self, by: usize) -> Result<(), Error>
pub fn prepend_with<F>(&mut self, size: usize, f: F) -> Result<(), Error>
pub fn prepend(&mut self, src: &[u8]) -> Result<(), Error>
pub fn append_with_buf<F>(&mut self, f: F) -> Result<usize, Error>
pub fn append_with<F>(&mut self, size: usize, f: F) -> Result<(), Error>
pub fn append(&mut self, src: &[u8]) -> Result<(), Error>
pub fn copy_from_slice(&mut self, src: &[u8]) -> Result<(), Error>
pub fn le_i8(&mut self, data: i8) -> Result<(), Error>
pub fn le_u8(&mut self, data: u8) -> Result<(), Error>
pub fn le_u16(&mut self, data: u16) -> Result<(), Error>
pub fn le_i16(&mut self, data: i16) -> Result<(), Error>
pub fn le_u32(&mut self, data: u32) -> Result<(), Error>
pub fn le_i32(&mut self, data: i32) -> Result<(), Error>
pub fn le_u64(&mut self, data: u64) -> Result<(), Error>
pub fn le_i64(&mut self, data: i64) -> Result<(), Error>
Trait Implementations§
Source§impl TLVWrite for WriteBuf<'_>
impl TLVWrite for WriteBuf<'_>
type Position = usize
Source§fn get_tail(&self) -> <WriteBuf<'_> as TLVWrite>::Position
fn get_tail(&self) -> <WriteBuf<'_> as TLVWrite>::Position
Source§fn rewind_to(&mut self, pos: <WriteBuf<'_> as TLVWrite>::Position)
fn rewind_to(&mut self, pos: <WriteBuf<'_> as TLVWrite>::Position)
Source§fn available_space(&mut self) -> &mut [u8] ⓘ
fn available_space(&mut self) -> &mut [u8] ⓘ
Source§fn str_cb(
&mut self,
tag: &TLVTag,
cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>,
) -> Result<(), Error>
fn str_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>
Source§fn utf8_cb(
&mut self,
tag: &TLVTag,
cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>,
) -> Result<(), Error>
fn utf8_cb( &mut self, tag: &TLVTag, cb: impl FnOnce(&mut [u8]) -> Result<usize, Error>, ) -> Result<(), Error>
Source§fn write_ctx<T>(&mut self, ctx: u8, value: &T) -> Result<(), Error>
fn write_ctx<T>(&mut self, ctx: u8, value: &T) -> Result<(), Error>
value under a context tag. Read moreSource§fn tlv(&mut self, tag: &TLVTag, value: &TLVValue<'_>) -> Result<(), Error>
fn tlv(&mut self, tag: &TLVTag, value: &TLVValue<'_>) -> Result<(), Error>
Source§fn i8(&mut self, tag: &TLVTag, data: i8) -> Result<(), Error>
fn i8(&mut self, tag: &TLVTag, data: i8) -> Result<(), Error>
Source§fn u8(&mut self, tag: &TLVTag, data: u8) -> Result<(), Error>
fn u8(&mut self, tag: &TLVTag, data: u8) -> Result<(), Error>
Source§fn i16(&mut self, tag: &TLVTag, data: i16) -> Result<(), Error>
fn i16(&mut self, tag: &TLVTag, data: i16) -> Result<(), Error>
Source§fn u16(&mut self, tag: &TLVTag, data: u16) -> Result<(), Error>
fn u16(&mut self, tag: &TLVTag, data: u16) -> Result<(), Error>
Source§fn i32(&mut self, tag: &TLVTag, data: i32) -> Result<(), Error>
fn i32(&mut self, tag: &TLVTag, data: i32) -> Result<(), Error>
Source§fn u32(&mut self, tag: &TLVTag, data: u32) -> Result<(), Error>
fn u32(&mut self, tag: &TLVTag, data: u32) -> Result<(), Error>
Source§fn i64(&mut self, tag: &TLVTag, data: i64) -> Result<(), Error>
fn i64(&mut self, tag: &TLVTag, data: i64) -> Result<(), Error>
Source§fn u64(&mut self, tag: &TLVTag, data: u64) -> Result<(), Error>
fn u64(&mut self, tag: &TLVTag, data: u64) -> Result<(), Error>
Source§fn f32(&mut self, tag: &TLVTag, data: f32) -> Result<(), Error>
fn f32(&mut self, tag: &TLVTag, data: f32) -> Result<(), Error>
Source§fn f64(&mut self, tag: &TLVTag, data: f64) -> Result<(), Error>
fn f64(&mut self, tag: &TLVTag, data: f64) -> Result<(), Error>
Source§fn str(&mut self, tag: &TLVTag, data: &[u8]) -> Result<(), Error>
fn str(&mut self, tag: &TLVTag, data: &[u8]) -> Result<(), Error>
Source§fn stri<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
fn stri<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
Source§fn utf8(&mut self, tag: &TLVTag, data: &str) -> Result<(), Error>
fn utf8(&mut self, tag: &TLVTag, data: &str) -> Result<(), Error>
Source§fn utf8i<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
fn utf8i<I>(&mut self, tag: &TLVTag, len: usize, data: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
Source§fn start_struct(&mut self, tag: &TLVTag) -> Result<(), Error>
fn start_struct(&mut self, tag: &TLVTag) -> Result<(), Error>
Source§fn start_array(&mut self, tag: &TLVTag) -> Result<(), Error>
fn start_array(&mut self, tag: &TLVTag) -> Result<(), Error>
Source§fn start_list(&mut self, tag: &TLVTag) -> Result<(), Error>
fn start_list(&mut self, tag: &TLVTag) -> Result<(), Error>
Source§fn start_container(
&mut self,
tag: &TLVTag,
container_type: TLVValueType,
) -> Result<(), Error>
fn start_container( &mut self, tag: &TLVTag, container_type: TLVValueType, ) -> Result<(), Error>
Source§fn end_container(&mut self) -> Result<(), Error>
fn end_container(&mut self) -> Result<(), Error>
Source§fn null(&mut self, tag: &TLVTag) -> Result<(), Error>
fn null(&mut self, tag: &TLVTag) -> Result<(), Error>
Source§fn bool(&mut self, tag: &TLVTag, val: bool) -> Result<(), Error>
fn bool(&mut self, tag: &TLVTag, val: bool) -> Result<(), Error>
Source§fn raw_value(
&mut self,
tag: &TLVTag,
value_type: TLVValueType,
value_payload: &[u8],
) -> Result<(), Error>
fn raw_value( &mut self, tag: &TLVTag, value_type: TLVValueType, value_payload: &[u8], ) -> Result<(), Error>
Source§fn write_raw_data<I>(&mut self, bytes: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
fn write_raw_data<I>(&mut self, bytes: I) -> Result<(), Error>where
I: IntoIterator<Item = u8>,
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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