pub struct OctetsMut<'a> { /* private fields */ }
Expand description
A zero-copy mutable byte buffer.
Like Octets
but mutable.
Implementations§
Source§impl<'a> OctetsMut<'a>
impl<'a> OctetsMut<'a>
Sourcepub fn with_slice(buf: &'a mut [u8]) -> Self
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.
Sourcepub fn get_u8(&mut self) -> Result<u8>
pub fn get_u8(&mut self) -> Result<u8>
Reads an unsigned 8-bit integer from the current offset and advances the buffer.
Sourcepub fn peek_u8(&mut self) -> Result<u8>
pub fn peek_u8(&mut self) -> Result<u8>
Reads an unsigned 8-bit integer from the current offset without advancing the buffer.
Sourcepub fn put_u8(&mut self, v: u8) -> Result<&mut [u8]>
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.
Sourcepub fn get_u16(&mut self) -> Result<u16>
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.
Sourcepub fn put_u16(&mut self, v: u16) -> Result<&mut [u8]>
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.
Sourcepub fn get_u24(&mut self) -> Result<u32>
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.
Sourcepub fn put_u24(&mut self, v: u32) -> Result<&mut [u8]>
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.
Sourcepub fn get_u32(&mut self) -> Result<u32>
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.
Sourcepub fn put_u32(&mut self, v: u32) -> Result<&mut [u8]>
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.
Sourcepub fn get_u64(&mut self) -> Result<u64>
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.
Sourcepub fn put_u64(&mut self, v: u64) -> Result<&mut [u8]>
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.
Sourcepub fn get_varint(&mut self) -> Result<u64>
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.
Sourcepub fn put_varint(&mut self, v: u64) -> Result<&mut [u8]>
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.
Sourcepub fn put_varint_with_len(&mut self, v: u64, len: usize) -> Result<&mut [u8]>
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.
Sourcepub fn get_bytes(&mut self, len: usize) -> Result<Octets<'_>>
pub fn get_bytes(&mut self, len: usize) -> Result<Octets<'_>>
Reads len
bytes from the current offset without copying and advances
the buffer.
Sourcepub fn get_bytes_mut(&mut self, len: usize) -> Result<OctetsMut<'_>>
pub fn get_bytes_mut(&mut self, len: usize) -> Result<OctetsMut<'_>>
Reads len
bytes from the current offset without copying and advances
the buffer.
Sourcepub fn get_bytes_with_u8_length(&mut self) -> Result<Octets<'_>>
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.
Sourcepub fn get_bytes_with_u16_length(&mut self) -> Result<Octets<'_>>
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.
Sourcepub fn get_bytes_with_varint_length(&mut self) -> Result<Octets<'_>>
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.
Sourcepub fn peek_bytes(&mut self, len: usize) -> Result<Octets<'_>>
pub fn peek_bytes(&mut self, len: usize) -> Result<Octets<'_>>
Reads len
bytes from the current offset without copying and without
advancing the buffer.
Sourcepub fn peek_bytes_mut(&mut self, len: usize) -> Result<OctetsMut<'_>>
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.
Sourcepub fn put_bytes(&mut self, v: &[u8]) -> Result<()>
pub fn put_bytes(&mut self, v: &[u8]) -> Result<()>
Writes len
bytes from the current offset without copying and advances
the buffer.
Sourcepub fn split_at(&mut self, off: usize) -> Result<(OctetsMut<'_>, OctetsMut<'_>)>
pub fn split_at(&mut self, off: usize) -> Result<(OctetsMut<'_>, OctetsMut<'_>)>
Splits the buffer in two at the given absolute offset.
Sourcepub fn slice(&'a mut self, len: usize) -> Result<&'a mut [u8]>
pub fn slice(&'a mut self, len: usize) -> Result<&'a mut [u8]>
Returns a slice of len
elements from the current offset.
Sourcepub fn slice_last(&'a mut self, len: usize) -> Result<&'a mut [u8]>
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.