Struct mbpr::Encoder
[−]
[src]
pub struct Encoder { /* fields omitted */ }
Data type used to encode data efficient
This structure has been built from the ground up to avoid branching while encoding.
Methods
impl Encoder
[src]
fn new<P: PacketVal>(msg: &P) -> Encoder
Pass an already constructed packet in. This will allocate a buffer the size of that packet
fn from_vec<P: PacketVal>(msg: &P, x: Vec<u8>) -> Encoder
To avoid allocations this method allows for a pre-allocated vector be passed in. The Vector's size will be checked, and it MAY be resized if too small. If it's capacity is sufficient no allocations will be done.
fn get_vec(self) -> Vec<u8>
Consumes this type (destroying it) but returns the underlying vector as to not dellocator it's memory (be used again).
unsafe fn with_capacity(size: usize) -> Self
Used internally for testing, maybe useful to the developer reading this this allows for the input value to set the len/capacity of the internal memory
Unsafe
This method is unsafe. If you encode a packet LARGER then the method your program may seg fault as there is no bounds checking when encoding.
fn as_slice<'a>(&'a self) -> &'a [u8]
While the underlying vec
is fully populated this returns
only the data written to it. So if with::capacity
is used
to create a buffer larger then a packet this can be used
to read only the packet data.
fn len(&self) -> usize
Get length of data written to the encoder
fn encode_u8(&mut self, x: u8)
Encode a u8 used internally.
fn encode_u16(&mut self, x: u16)
Encode a u16 used internally.
fn encode_u32(&mut self, x: u32)
Encode a u32 used internally.
fn encode_u64(&mut self, x: u64)
Encode a u64 used internally.
fn encode_slice(&mut self, x: &[u8])
Encode a [u8] used internally.