Struct MemBufferReader

Source
pub struct MemBufferReader<'a> { /* private fields */ }
Expand description

The reader which is used for reading the memory area produced by the writer, Important notice: The reader uses the native endian of the system used therefore sending between big endian and little endian systems wont work

use membuffer::{MemBufferWriter,MemBufferReader};

let mut data = MemBufferWriter::new();
data.add_entry("Add some data to save to file or send over the network");
let data_vec = data.finalize();
let reader = MemBufferReader::new(&data_vec).unwrap();
assert_eq!(reader.load_entry::<&str>(0).unwrap(),"Add some data to save to file or send over the network");

Implementations§

Source§

impl<'a> MemBufferReader<'a>

Source

pub fn deserialize_i32_from(buffer: &[u8]) -> i32

Deserialize data from a buffer to an i32 integer

Source

pub fn len(&self) -> usize

Source

pub fn payload_len(&self) -> usize

Source

pub fn load_entry<X: MemBufferDeserialize<'a, X> + MemBufferSerialize>( &self, key: usize, ) -> Result<X, MemBufferError>

Load one entry with the given type, expecting the serializable trait as well to determine the integer type, when doing polymorphismus of structures use the same integer for multiple types

Source

pub fn load_serde_entry<T: Deserialize<'a>>( &self, key: usize, ) -> Result<T, MemBufferError>

Loads an entry stored with serde_json and returns it.

Source

pub fn load_recursive_reader( &self, key: usize, ) -> Result<MemBufferReader<'a>, MemBufferError>

Loads a nested MembufferWriter as reader

Source

pub fn new(val: &'a [u8]) -> Result<MemBufferReader<'a>, MemBufferError>

Creates a new memory format reader from the given memory slice, as the readed values are borrowed from the memory slice the reader cannot outlive the memory it borrows from

Trait Implementations§

Source§

impl<'a> Debug for MemBufferReader<'a>

Source§

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

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

impl<'a> MemBufferDeserialize<'a, MemBufferReader<'a>> for MemBufferReader<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for MemBufferReader<'a>

§

impl<'a> RefUnwindSafe for MemBufferReader<'a>

§

impl<'a> Send for MemBufferReader<'a>

§

impl<'a> Sync for MemBufferReader<'a>

§

impl<'a> Unpin for MemBufferReader<'a>

§

impl<'a> UnwindSafe for MemBufferReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.