embassy-usb

Crates

git

Versions

default

Flavors

Skip to main content

MtpWriter

Struct MtpWriter 

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

Cursor-based serializer for little-endian MTP/PTP datasets and UTF-16LE strings.

Implementations§

Source§

impl<'a> MtpWriter<'a>

Source

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

Creates a new MtpWriter backed by buf.

Source

pub const fn len(&self) -> usize

Returns the number of bytes written so far.

Source

pub const fn is_empty(&self) -> bool

Returns true if no bytes have been written.

Source

pub const fn remaining(&self) -> usize

Returns the remaining capacity in bytes.

Source

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

Returns the written bytes slice.

Source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), MtpError>

Writes raw bytes.

Source

pub fn write_u8(&mut self, v: u8) -> Result<(), MtpError>

Writes a u8.

Source

pub fn write_u16(&mut self, v: u16) -> Result<(), MtpError>

Writes a little-endian u16.

Source

pub fn write_u32(&mut self, v: u32) -> Result<(), MtpError>

Writes a little-endian u32.

Source

pub fn write_u64(&mut self, v: u64) -> Result<(), MtpError>

Writes a little-endian u64.

Source

pub fn write_u16_array(&mut self, items: &[u16]) -> Result<(), MtpError>

Writes a PTP/MTP u16 array (u32 element count followed by LE u16 elements).

Source

pub fn write_u32_array(&mut self, items: &[u32]) -> Result<(), MtpError>

Writes a PTP/MTP u32 array (u32 element count followed by LE u32 elements).

Source

pub fn write_string(&mut self, s: &str) -> Result<(), MtpError>

Writes a PTP/MTP UTF-16LE length-prefixed string.

Empty strings are encoded as a single 0x00 byte; non-empty strings are encoded as num_chars (including trailing NUL, max 255) followed by UTF-16LE code units and 0x0000.

Auto Trait Implementations§

§

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

§

impl<'a> Forget for MtpWriter<'a>

§

impl<'a> Freeze for MtpWriter<'a>

§

impl<'a> Move for MtpWriter<'a>

§

impl<'a> RefUnwindSafe for MtpWriter<'a>

§

impl<'a> Send for MtpWriter<'a>

§

impl<'a> Sync for MtpWriter<'a>

§

impl<'a> Unpin for MtpWriter<'a>

§

impl<'a> UnsafeUnpin for MtpWriter<'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 = !

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

fn try_from(value: U) -> Result<T, !>

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.