[][src]Struct flexbuffers::Reader

pub struct Reader<'de> { /* fields omitted */ }

Readers allow access to data stored in a Flexbuffer.

Each reader represents a single address in the buffer so data is read lazily. Start a reader by calling get_root on your flexbuffer &[u8].

  • The get_T methods return a Result<T, Error>. They return an OK value if and only if the flexbuffer type matches T. This is analogous to the behavior of Rust's json library, though with Result instead of Option.
  • The as_T methods will try their best to return to a value of type T (by casting or even parsing a string if necessary) but ultimately returns T::default if it fails. This behavior is analogous to that of flexbuffers C++.

Implementations

impl<'de> Reader<'de>[src]

pub fn get_root(buffer: &'de [u8]) -> Result<Self, Error>[src]

Parses the flexbuffer from the given buffer. Assumes the flexbuffer root is the last byte of the buffer.

pub fn flexbuffer_type(&self) -> FlexBufferType[src]

Returns the FlexBufferType of this Reader.

pub fn bitwidth(&self) -> BitWidth[src]

Returns the bitwidth of this Reader.

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

Returns the length of the Flexbuffer. If the type has no length, or if an error occurs, 0 is returned.

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

Returns true if the flexbuffer is aligned to 8 bytes. This guarantees, for valid flexbuffers, that the data is correctly aligned in memory and slices can be read directly e.g. with get_f64s or get_i16s.

pub fn as_vector(&self) -> VectorReader<'de>[src]

pub fn as_map(&self) -> MapReader<'de>[src]

pub fn get_slice<T: ReadLE>(&self) -> Result<&'de [T], Error>[src]

Directly reads a slice of type Twhere T is one of u8,u16,u32,u64,i8,i16,i32,i64,f32,f64. Returns Err if the type, bitwidth, or memory alignment does not match. Since the bitwidth is dynamic, its better to use a VectorReader unless you know your data and performance is critical.

pub fn get_bool(&self) -> Result<bool, Error>[src]

pub fn get_key(&self) -> Result<&'de str, Error>[src]

pub fn get_blob(&self) -> Result<Blob<'de>, Error>[src]

pub fn as_blob(&self) -> Blob<'de>[src]

pub fn get_str(&self) -> Result<&'de str, Error>[src]

pub fn get_map(&self) -> Result<MapReader<'de>, Error>[src]

pub fn get_u64(&self) -> Result<u64, Error>[src]

Tries to read a FlexBufferType::UInt. Returns Err if the type is not a UInt or if the address is out of bounds.

pub fn get_i64(&self) -> Result<i64, Error>[src]

Tries to read a FlexBufferType::Int. Returns Err if the type is not a UInt or if the address is out of bounds.

pub fn get_f64(&self) -> Result<f64, Error>[src]

Tries to read a FlexBufferType::Float. Returns Err if the type is not a UInt, if the address is out of bounds, or if its a f16 or f8 (not currently supported).

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

pub fn as_u64(&self) -> u64[src]

Returns a u64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.

pub fn as_u32(&self) -> u32[src]

pub fn as_u16(&self) -> u16[src]

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

pub fn as_i64(&self) -> i64[src]

Returns an i64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.

pub fn as_i32(&self) -> i32[src]

pub fn as_i16(&self) -> i16[src]

pub fn as_i8(&self) -> i8[src]

pub fn as_f64(&self) -> f64[src]

Returns an f64, casting if necessary. For Maps and Vectors, their length is returned. If anything fails, 0 is returned.

pub fn as_f32(&self) -> f32[src]

pub fn as_str(&self) -> &'de str[src]

Returns empty string if you're not trying to read a string.

pub fn get_vector(&self) -> Result<VectorReader<'de>, Error>[src]

Trait Implementations

impl<'de> Clone for Reader<'de>[src]

impl<'de> Debug for Reader<'de>[src]

impl<'de> Default for Reader<'de>[src]

impl<'de> Deserializer<'de> for Reader<'de>[src]

type Error = DeserializationError

The error type that can be returned if some error occurs during deserialization. Read more

impl<'de> Display for Reader<'de>[src]

impl<'de> VariantAccess<'de> for Reader<'de>[src]

type Error = DeserializationError

The error type that can be returned if some error occurs during deserialization. Must match the error type of our EnumAccess. Read more

Auto Trait Implementations

impl<'de> RefUnwindSafe for Reader<'de>[src]

impl<'de> Send for Reader<'de>[src]

impl<'de> Sync for Reader<'de>[src]

impl<'de> Unpin for Reader<'de>[src]

impl<'de> UnwindSafe for Reader<'de>[src]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.