Struct octets::OctetsMut

source ·
pub struct OctetsMut<'a> { /* private fields */ }
Expand description

A zero-copy mutable byte buffer.

Like Octets but mutable.

Implementations§

source§

impl<'a> OctetsMut<'a>

source

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

Creates an OctetsMut from the given slice, without copying.

Since there’s no copy, the input slice needs to be mutable to allow modifications.

source

pub fn get_u8(&mut self) -> Result<u8>

Reads an unsigned 8-bit integer from the current offset and advances the buffer.

source

pub fn peek_u8(&mut self) -> Result<u8>

Reads an unsigned 8-bit integer from the current offset without advancing the buffer.

source

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

Writes an unsigned 8-bit integer at the current offset and advances the buffer.

source

pub fn get_u16(&mut self) -> Result<u16>

Reads an unsigned 16-bit integer in network byte-order from the current offset and advances the buffer.

source

pub fn put_u16(&mut self, v: u16) -> Result<&mut [u8]>

Writes an unsigned 16-bit integer in network byte-order at the current offset and advances the buffer.

source

pub fn get_u24(&mut self) -> Result<u32>

Reads an unsigned 24-bit integer in network byte-order from the current offset and advances the buffer.

source

pub fn put_u24(&mut self, v: u32) -> Result<&mut [u8]>

Writes an unsigned 24-bit integer in network byte-order at the current offset and advances the buffer.

source

pub fn get_u32(&mut self) -> Result<u32>

Reads an unsigned 32-bit integer in network byte-order from the current offset and advances the buffer.

source

pub fn put_u32(&mut self, v: u32) -> Result<&mut [u8]>

Writes an unsigned 32-bit integer in network byte-order at the current offset and advances the buffer.

source

pub fn get_u64(&mut self) -> Result<u64>

Reads an unsigned 64-bit integer in network byte-order from the current offset and advances the buffer.

source

pub fn put_u64(&mut self, v: u64) -> Result<&mut [u8]>

Writes an unsigned 64-bit integer in network byte-order at the current offset and advances the buffer.

source

pub fn get_varint(&mut self) -> Result<u64>

Reads an unsigned variable-length integer in network byte-order from the current offset and advances the buffer.

source

pub fn put_varint(&mut self, v: u64) -> Result<&mut [u8]>

Writes an unsigned variable-length integer in network byte-order at the current offset and advances the buffer.

source

pub fn put_varint_with_len(&mut self, v: u64, len: usize) -> Result<&mut [u8]>

Writes an unsigned variable-length integer of the specified length, in network byte-order at the current offset and advances the buffer.

source

pub fn get_bytes(&mut self, len: usize) -> Result<Octets<'_>>

Reads len bytes from the current offset without copying and advances the buffer.

source

pub fn get_bytes_mut(&mut self, len: usize) -> Result<OctetsMut<'_>>

Reads len bytes from the current offset without copying and advances the buffer.

source

pub fn get_bytes_with_u8_length(&mut self) -> Result<Octets<'_>>

Reads len bytes from the current offset without copying and advances the buffer, where len is an unsigned 8-bit integer prefix.

source

pub fn get_bytes_with_u16_length(&mut self) -> Result<Octets<'_>>

Reads len bytes from the current offset without copying and advances the buffer, where len is an unsigned 16-bit integer prefix in network byte-order.

source

pub fn get_bytes_with_varint_length(&mut self) -> Result<Octets<'_>>

Reads len bytes from the current offset without copying and advances the buffer, where len is an unsigned variable-length integer prefix in network byte-order.

source

pub fn peek_bytes(&mut self, len: usize) -> Result<Octets<'_>>

Reads len bytes from the current offset without copying and without advancing the buffer.

source

pub fn peek_bytes_mut(&mut self, len: usize) -> Result<OctetsMut<'_>>

Reads len bytes from the current offset without copying and without advancing the buffer.

source

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

Writes len bytes from the current offset without copying and advances the buffer.

source

pub fn split_at(&mut self, off: usize) -> Result<(OctetsMut<'_>, OctetsMut<'_>)>

Splits the buffer in two at the given absolute offset.

source

pub fn slice(&'a mut self, len: usize) -> Result<&'a mut [u8]>

Returns a slice of len elements from the current offset.

source

pub fn slice_last(&'a mut self, len: usize) -> Result<&'a mut [u8]>

Returns a slice of len elements from the end of the buffer.

source

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

Advances the buffer’s offset.

source

pub fn cap(&self) -> usize

Returns the remaining capacity in the buffer.

source

pub fn len(&self) -> usize

Returns the total length of the buffer.

source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

source

pub fn off(&self) -> usize

Returns the current offset of the buffer.

source

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

Returns a reference to the internal buffer.

source

pub fn to_vec(&self) -> Vec<u8>

Copies the buffer from the current offset into a new Vec<u8>.

Trait Implementations§

source§

impl<'a> AsMut<[u8]> for OctetsMut<'a>

source§

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

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<'a> AsRef<[u8]> for OctetsMut<'a>

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Debug for OctetsMut<'a>

source§

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

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

impl<'a> PartialEq for OctetsMut<'a>

source§

fn eq(&self, other: &OctetsMut<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for OctetsMut<'a>

source§

impl<'a> StructuralPartialEq for OctetsMut<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for OctetsMut<'a>

§

impl<'a> RefUnwindSafe for OctetsMut<'a>

§

impl<'a> Send for OctetsMut<'a>

§

impl<'a> Sync for OctetsMut<'a>

§

impl<'a> Unpin for OctetsMut<'a>

§

impl<'a> !UnwindSafe for OctetsMut<'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>,

§

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>,

§

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.