pub struct Buffer { /* private fields */ }Expand description
The Buffer struct is used to read and write Buffer messages.
§Description
This works as a wrapper around a byte buffer. The idea is to have an opinionated reading/writing API for little-endian encodings for various signed and unsigned integer types. It also includes basic varint encoding and decoding.
§Usage
Create a new Buffer instance:
use gistools::util::Buffer;
let mut buf = Buffer::new();Create a Buffer instance from a byte buffer:
use gistools::util::Buffer;
let mut vec = vec![0x0A, 0x03, 0x74, 0x65, 0x73, 0x74];
let mut buf = Buffer::new(vec);
// DO STUFF
let res = buf.take();Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn get_i32_at(&mut self, pos: usize) -> i32
pub fn get_i32_at(&mut self, pos: usize) -> i32
return the current i32 at position
Sourcepub fn set_i32_at(&mut self, pos: usize, value: i32)
pub fn set_i32_at(&mut self, pos: usize, value: i32)
set the current i32 at position
Sourcepub fn get_u16_at(&mut self, pos: usize) -> u16
pub fn get_u16_at(&mut self, pos: usize) -> u16
return the current u16 at position
Sourcepub fn set_u16_at(&mut self, pos: usize, value: u16)
pub fn set_u16_at(&mut self, pos: usize, value: u16)
set the current u16 at position
Sourcepub fn get_i16_at(&mut self, pos: usize) -> i16
pub fn get_i16_at(&mut self, pos: usize) -> i16
return the current i16 at position
Sourcepub fn set_i16_at(&mut self, pos: usize, value: i16)
pub fn set_i16_at(&mut self, pos: usize, value: i16)
set the current i16 at position
Sourcepub fn get_u32_at(&mut self, pos: usize) -> u32
pub fn get_u32_at(&mut self, pos: usize) -> u32
return the current u32 at position
Sourcepub fn set_u32_at(&mut self, pos: usize, value: u32)
pub fn set_u32_at(&mut self, pos: usize, value: u32)
set the current u32 at position
Sourcepub fn get_f32_at(&mut self, pos: usize) -> f32
pub fn get_f32_at(&mut self, pos: usize) -> f32
Return the current f32 at position
Sourcepub fn set_f32_at(&mut self, pos: usize, value: f32)
pub fn set_f32_at(&mut self, pos: usize, value: f32)
Set the current f32 at position
Sourcepub fn get_i64_at(&mut self, pos: usize) -> i64
pub fn get_i64_at(&mut self, pos: usize) -> i64
return the current i32 at position
Sourcepub fn set_i64_at(&mut self, pos: usize, value: i64)
pub fn set_i64_at(&mut self, pos: usize, value: i64)
set the current i32 at position
Sourcepub fn get_u64_at(&mut self, pos: usize) -> u64
pub fn get_u64_at(&mut self, pos: usize) -> u64
return the current u64 at position
Sourcepub fn set_u64_at(&mut self, pos: usize, value: u64)
pub fn set_u64_at(&mut self, pos: usize, value: u64)
set the current u64 at position
Sourcepub fn get_f64_at(&mut self, pos: usize) -> f64
pub fn get_f64_at(&mut self, pos: usize) -> f64
Return the current f64 at position
Sourcepub fn set_f64_at(&mut self, pos: usize, value: f64)
pub fn set_f64_at(&mut self, pos: usize, value: f64)
Set the current f64 at position
Sourcepub fn decode_varint(&mut self) -> u64
pub fn decode_varint(&mut self) -> u64
Decode a varint from the buffer at the current position.
Sourcepub fn read_varint<T>(&mut self) -> Twhere
T: BitCast,
pub fn read_varint<T>(&mut self) -> Twhere
T: BitCast,
Read in a variable size value from the buffer.
Sourcepub fn write_varint<T>(&mut self, val: T)where
T: BitCast,
pub fn write_varint<T>(&mut self, val: T)where
T: BitCast,
Write a u64 to the buffer.
Sourcepub fn take(&mut self) -> Vec<u8> ⓘ
pub fn take(&mut self) -> Vec<u8> ⓘ
When done writing to the buffer, call this function to take ownership
Sourcepub fn copy_from_slice(&mut self, offset: usize, slice: &[u8])
pub fn copy_from_slice(&mut self, offset: usize, slice: &[u8])
Copy a slice into the buffer
Trait Implementations§
impl StructuralPartialEq for Buffer
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().