[][src]Struct bytebuff::ByteBuff

pub struct ByteBuff { /* fields omitted */ }

ByteBuff is a convenient helper for game networking. Using this is similar to using ThreadRng from rand package. Example speaks for it self.

Example

use bytebuff::{ByteBuff, ReadError, Interface};
let mut buff = ByteBuff::new();

buff.write(10f32); // supports float types
buff.write(30); // all integer types
buff.write(vec![10u8, 5u8, 8u8]); // as well as strings and byte vectors

assert_eq!(Ok(10f32), buff.read());
assert_eq!(Ok(30), buff.read());
assert_eq!(Ok(vec![10u8, 5u8, 8u8]), buff.read());
let bool: Result<bool, ReadError> = buff.read(); // unable to infer type in this case
assert!(bool.is_err());

Implementations

impl ByteBuff[src]

pub fn new() -> Self[src]

pub fn with_capacity(cap: usize) -> Self[src]

works like Vec::with_capacity

pub fn from_bytes(data: &[u8]) -> Self[src]

read creates buffer for reading

pub fn len(&self) -> usize[src]

len returns length of buffer

pub fn clear(&mut self)[src]

clear restarts the buffer, its useful when reusing buffers

pub fn is_finished(&self) -> bool[src]

is_finished returns whether buffer is completely red

pub fn data(&self) -> &[u8][src]

data returns slice of buffers data

pub fn extend(&mut self, other: &Self)[src]

extend works almost as Vec::extend with slight difference. it also appends size of appended data and if the self length is missing as well it will add it too.

pub fn split(
    self,
    reminder: Option<Self>,
    reminding_size: usize,
    reminding_data: Vec<u8>,
    collector: &mut Vec<Self>
) -> (Option<Self>, usize, Vec<u8>)
[src]

split works on previously merged buffers. It splits them to original smaller parts and also some garbage that you are supposed to feed into next split call. NOW you may be asking why is there so match garbage arguments and return values, well as we know your byte buffer witch you are passing to packet sender can be only so big and packages can arrive incomplete. Function simply takes and returns these reminders so all packages get completed.

Trait Implementations

impl Debug for ByteBuff[src]

impl Interface<String> for ByteBuff[src]

impl Interface<Vec<u8>> for ByteBuff[src]

impl Interface<bool> for ByteBuff[src]

impl Interface<f32> for ByteBuff[src]

impl Interface<f64> for ByteBuff[src]

impl Interface<i128> for ByteBuff[src]

impl Interface<i16> for ByteBuff[src]

impl Interface<i32> for ByteBuff[src]

impl Interface<i64> for ByteBuff[src]

impl Interface<i8> for ByteBuff[src]

impl Interface<u128> for ByteBuff[src]

impl Interface<u16> for ByteBuff[src]

impl Interface<u32> for ByteBuff[src]

impl Interface<u64> for ByteBuff[src]

impl Interface<u8> for ByteBuff[src]

impl Interface<usize> for ByteBuff[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.