octets

Struct 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 AsMut<[u8]> for OctetsMut<'_>

Source§

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

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

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

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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.