pub struct BufViewMut<'a> { /* private fields */ }Expand description
Wrap a &mut [u8] buffer as read and write.
BufViewMut support many methods to read/write primitive types from a byte buffer easily, it support to read/write primitive types as big endian or little endian. BufViewMut wrap the original buffer with reader_index and writer_index as fllowing structure. When read data from it, the reader_index will advance the data length, and the read must between the reader_index and writer_index. When write data to it, the writer_index will advance the data length, too.
Any more, it support get method, too. It make random get data from the BufViewMut, and support set method, too, which make random put data to the BufViewMut.
BufViewMut structure
-----------------------------------------------------
| | | |
-----------------------------------------------------
^ ^ ^
| | |
reader_index writer_index buf.len()Example
use buf_view::BufViewMut;
let mut buf = [0u8;7];
let mut buf_view = BufViewMut::wrap(&mut buf);
buf_view.write_u8(0);
buf_view.write_u16(0x0102);
buf_view.write_u32(0x03040506);
assert_eq!(buf_view.read_u8(), 0);
assert_eq!(buf_view.read_u16(), 0x0102);
assert_eq!(buf_view.read_u32(), 0x03040506);
assert_eq!(buf_view.get_u16(1), 0x0102);Implementations§
Source§impl<'a> BufViewMut<'a>
impl<'a> BufViewMut<'a>
Sourcepub fn wrap(buf: &'a mut [u8]) -> Self
pub fn wrap(buf: &'a mut [u8]) -> Self
Wrap the buf as BufViewMut, set the reader_index=0 and writer_index=0,
this make the whole buf can write by default.
Sourcepub fn wrap_with(
buf: &'a mut [u8],
reader_index: usize,
writer_index: usize,
) -> Self
pub fn wrap_with( buf: &'a mut [u8], reader_index: usize, writer_index: usize, ) -> Self
Wrap the buf as BufViewMut, and specify the reader_index and writer_index.
use buf_view::BufViewMut;
let mut buf = [0, 1, 2, 3, 4, 5, 6, 7];
let mut buf = BufViewMut::wrap_with(&mut buf, 1, 3);
buf.write_u32(0x01020304);
assert_eq!(buf.read_u16(), 0x0102);
assert_eq!(buf.read_u32(), 0x01020304);pub fn read_u8(&mut self) -> u8
pub fn read_i8(&mut self) -> i8
pub fn read_u16(&mut self) -> u16
pub fn read_u16_le(&mut self) -> u16
pub fn read_i16(&mut self) -> i16
pub fn read_i16_le(&mut self) -> i16
pub fn read_u32(&mut self) -> u32
pub fn read_u32_le(&mut self) -> u32
pub fn read_i32(&mut self) -> i32
pub fn read_i32_le(&mut self) -> i32
pub fn read_u64(&mut self) -> u64
pub fn read_u64_le(&mut self) -> u64
pub fn read_i64(&mut self) -> i64
pub fn read_i64_le(&mut self) -> i64
pub fn read_u128(&mut self) -> u128
pub fn read_u128_le(&mut self) -> u128
pub fn read_i128(&mut self) -> i128
pub fn read_i128_le(&mut self) -> i128
pub fn read_f32(&mut self) -> f32
pub fn read_f32_le(&mut self) -> f32
pub fn read_f64(&mut self) -> f64
pub fn read_f64_le(&mut self) -> f64
pub fn read_bytes(&mut self, dest: &mut [u8]) -> usize
pub fn get_u8(&mut self, index: usize) -> u8
pub fn get_i8(&mut self, index: usize) -> i8
pub fn get_u16(&mut self, index: usize) -> u16
pub fn get_u16_le(&mut self, index: usize) -> u16
pub fn get_i16(&mut self, index: usize) -> i16
pub fn get_i16_le(&mut self, index: usize) -> i16
pub fn get_u32(&mut self, index: usize) -> u32
pub fn get_u32_le(&mut self, index: usize) -> u32
pub fn get_i32(&mut self, index: usize) -> i32
pub fn get_i32_le(&mut self, index: usize) -> i32
pub fn get_u64(&mut self, index: usize) -> u64
pub fn get_u64_le(&mut self, index: usize) -> u64
pub fn get_i64(&mut self, index: usize) -> i64
pub fn get_i64_le(&mut self, index: usize) -> i64
pub fn get_u128(&mut self, index: usize) -> u128
pub fn get_u128_le(&mut self, index: usize) -> u128
pub fn get_i128(&mut self, index: usize) -> i128
pub fn get_i128_le(&mut self, index: usize) -> i128
pub fn get_f32(&mut self, index: usize) -> f32
pub fn get_f32_le(&mut self, index: usize) -> f32
pub fn get_f64(&mut self, index: usize) -> f64
pub fn get_f64_le(&mut self, index: usize) -> f64
pub fn get_bytes(&mut self, index: usize, dest: &mut [u8]) -> usize
pub fn write_u8(&mut self, val: u8)
pub fn write_u16(&mut self, val: u16)
pub fn write_u16_le(&mut self, val: u16)
pub fn write_i16(&mut self, val: i16)
pub fn write_i16_le(&mut self, val: i16)
pub fn write_u32(&mut self, val: u32)
pub fn write_u32_le(&mut self, val: u32)
pub fn write_i32(&mut self, val: i32)
pub fn write_i32_le(&mut self, val: i32)
pub fn write_u64(&mut self, val: u64)
pub fn write_u64_le(&mut self, val: u64)
pub fn write_i64(&mut self, val: i64)
pub fn write_i64_le(&mut self, val: i64)
pub fn write_u128(&mut self, val: u128)
pub fn write_u128_le(&mut self, val: u128)
pub fn write_i128(&mut self, val: i128)
pub fn write_i128_le(&mut self, val: i128)
pub fn write_f32(&mut self, val: f32)
pub fn write_f32_le(&mut self, val: f32)
pub fn write_f64(&mut self, val: f64)
pub fn write_f64_le(&mut self, val: f64)
pub fn write_bytes(&mut self, src: &[u8])
pub fn write_bytes_uncheck(&mut self, src: &[u8]) -> usize
pub fn set_u8(&mut self, index: usize, val: u8)
pub fn set_u16(&mut self, index: usize, val: u16)
pub fn set_u16_le(&mut self, index: usize, val: u16)
pub fn set_i16(&mut self, index: usize, val: i16)
pub fn set_i16_le(&mut self, index: usize, val: i16)
pub fn set_u32(&mut self, index: usize, val: u32)
pub fn set_u32_le(&mut self, index: usize, val: u32)
pub fn set_i32(&mut self, index: usize, val: i32)
pub fn set_i32_le(&mut self, index: usize, val: i32)
pub fn set_u64(&mut self, index: usize, val: u64)
pub fn set_u64_le(&mut self, index: usize, val: u64)
pub fn set_i64(&mut self, index: usize, val: i64)
pub fn set_i64_le(&mut self, index: usize, val: i64)
pub fn set_u128(&mut self, index: usize, val: u128)
pub fn set_u128_le(&mut self, index: usize, val: u128)
pub fn set_i128(&mut self, index: usize, val: i128)
pub fn set_i128_le(&mut self, index: usize, val: i128)
pub fn set_f32(&mut self, index: usize, val: f32)
pub fn set_f32_le(&mut self, index: usize, val: f32)
pub fn set_f64(&mut self, index: usize, val: f64)
pub fn set_f64_le(&mut self, index: usize, val: f64)
pub fn set_bytes(&mut self, index: usize, src: &[u8])
pub fn set_reader_index(&mut self, index: usize)
pub fn reader_index(&self) -> usize
pub fn set_writer_index(&mut self, index: usize)
pub fn writer_index(&self) -> usize
pub fn set_index(&mut self, reader_index: usize, writer_index: usize)
pub fn clear(&mut self)
pub fn remaining(&self) -> usize
pub fn capacity(&self) -> usize
pub fn as_slice(&mut self) -> &mut [u8] ⓘ
pub fn as_raw_slice(&mut self) -> &mut [u8] ⓘ
Trait Implementations§
Source§impl<'a> Debug for BufViewMut<'a>
impl<'a> Debug for BufViewMut<'a>
Source§impl Display for BufViewMut<'_>
impl Display for BufViewMut<'_>
Source§impl<'a> Write for BufViewMut<'a>
impl<'a> Write for BufViewMut<'a>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)