Buffer

Struct Buffer 

Source
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

Source

pub fn new(buf: Vec<u8>) -> Buffer

Create a new Buffer instance.

Source

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

See the contents of the buffer

Source

pub fn pos(&self) -> usize

Get the position to read from the buffer next.

Source

pub fn set_pos(&mut self, pos: usize)

Set the position to read from the buffer next.

Source

pub fn len(&self) -> usize

get the length of the bufer

Source

pub fn is_empty(&self) -> bool

check if the buffer is empty

Source

pub fn get_u8(&mut self) -> u8

return the current u8 under the buffer

Source

pub fn get_u8_at(&mut self, pos: usize) -> u8

return the current u8 at position

Source

pub fn set_u8(&mut self, value: u8)

set the current u8 under the buffer

Source

pub fn set_u8_at(&mut self, pos: usize, value: u8)

set the current u8 at position

Source

pub fn get_i8(&mut self) -> i8

return the current i8 under the buffer

Source

pub fn get_i8_at(&mut self, pos: usize) -> i8

return the current i8 at position

Source

pub fn set_i8(&mut self, value: i8)

set the current u8 under the buffer

Source

pub fn set_i8_at(&mut self, pos: usize, value: i8)

set the current i8 at position

Source

pub fn get_i32(&mut self) -> i32

return the current i32 under the buffer

Source

pub fn get_i32_at(&mut self, pos: usize) -> i32

return the current i32 at position

Source

pub fn set_i32(&mut self, value: i32)

set the current i32 under the buffer

Source

pub fn set_i32_at(&mut self, pos: usize, value: i32)

set the current i32 at position

Source

pub fn get_u16(&mut self) -> u16

return the current u16 under the buffer

Source

pub fn get_u16_at(&mut self, pos: usize) -> u16

return the current u16 at position

Source

pub fn set_u16(&mut self, value: u16)

set the current u16 under the buffer

Source

pub fn set_u16_at(&mut self, pos: usize, value: u16)

set the current u16 at position

Source

pub fn get_i16(&mut self) -> i16

return the current i16 under the buffer

Source

pub fn get_i16_at(&mut self, pos: usize) -> i16

return the current i16 at position

Source

pub fn set_i16(&mut self, value: i16)

set the current i16 under the buffer

Source

pub fn set_i16_at(&mut self, pos: usize, value: i16)

set the current i16 at position

Source

pub fn get_u32(&mut self) -> u32

return the current u32 under the buffer

Source

pub fn get_u32_at(&mut self, pos: usize) -> u32

return the current u32 at position

Source

pub fn set_u32(&mut self, value: u32)

set the current u32 under the buffer

Source

pub fn set_u32_at(&mut self, pos: usize, value: u32)

set the current u32 at position

Source

pub fn get_f32(&mut self) -> f32

Return the current f32 at position

Source

pub fn get_f32_at(&mut self, pos: usize) -> f32

Return the current f32 at position

Source

pub fn set_f32(&mut self, value: f32)

Set the current f32 at position

Source

pub fn set_f32_at(&mut self, pos: usize, value: f32)

Set the current f32 at position

Source

pub fn get_i64(&mut self) -> i64

return the current i32 under the buffer

Source

pub fn get_i64_at(&mut self, pos: usize) -> i64

return the current i32 at position

Source

pub fn set_i64(&mut self, value: i64)

set the current i32 under the buffer

Source

pub fn set_i64_at(&mut self, pos: usize, value: i64)

set the current i32 at position

Source

pub fn get_u64(&mut self) -> u64

return the current u64 under the buffer

Source

pub fn get_u64_at(&mut self, pos: usize) -> u64

return the current u64 at position

Source

pub fn set_u64(&mut self, value: u64)

set the current u64 under the buffer

Source

pub fn set_u64_at(&mut self, pos: usize, value: u64)

set the current u64 at position

Source

pub fn get_f64(&mut self) -> f64

Return the current f64 at position

Source

pub fn get_f64_at(&mut self, pos: usize) -> f64

Return the current f64 at position

Source

pub fn set_f64(&mut self, value: f64)

Set the current f64 at position

Source

pub fn set_f64_at(&mut self, pos: usize, value: f64)

Set the current f64 at position

Source

pub fn decode_varint(&mut self) -> u64

Decode a varint from the buffer at the current position.

Source

pub fn read_varint<T>(&mut self) -> T
where T: BitCast,

Read in a variable size value from the buffer.

Source

pub fn write_varint<T>(&mut self, val: T)
where T: BitCast,

Write a u64 to the buffer.

Source

pub fn take(&mut self) -> Vec<u8>

When done writing to the buffer, call this function to take ownership

Source

pub fn copy_from_slice(&mut self, offset: usize, slice: &[u8])

Copy a slice into the buffer

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Buffer

Source§

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

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

impl Default for Buffer

Source§

fn default() -> Buffer

Returns the “default value” for a type. Read more
Source§

impl From<Vec<u8>> for Buffer

Source§

fn from(buf: Vec<u8>) -> Buffer

Converts to this type from the input type.
Source§

impl PartialEq for Buffer

Source§

fn eq(&self, other: &Buffer) -> bool

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

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 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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V