Struct flexbuffers::Reader [−][src]
pub struct Reader<B> { /* fields omitted */ }
Expand description
Reader
s 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 aResult<T, Error>
. They return an OK value if and only if the flexbuffer type matchesT
. 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 typeT
(by casting or even parsing a string if necessary) but ultimately returnsT::default
if it fails. This behavior is analogous to that of flexbuffers C++.
Implementations
impl<B: Buffer> Reader<B>
[src]
impl<B: Buffer> Reader<B>
[src]pub fn get_root(buffer: B) -> Result<Self, Error>
[src]
pub fn get_root(buffer: B) -> Result<Self, Error>
[src]Parses the flexbuffer from the given buffer. Assumes the flexbuffer root is the last byte of the buffer.
pub fn buffer(&self) -> B
[src]
pub fn buffer(&self) -> B
[src]Convenience function to get the underlying buffer. By using shallow_copy
, this preserves
the lifetime that the underlying buffer has.
pub fn flexbuffer_type(&self) -> FlexBufferType
[src]
pub fn flexbuffer_type(&self) -> FlexBufferType
[src]Returns the FlexBufferType of this Reader.
pub fn length(&self) -> usize
[src]
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]
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<B>
[src]
pub fn as_map(&self) -> MapReader<B>
[src]
pub fn get_slice<T: ReadLE>(&self) -> Result<&[T], Error>
[src]
👎 Deprecated since 0.3.0: This function is unsafe - if this functionality is needed use Reader::buffer::align_to
pub fn get_slice<T: ReadLE>(&self) -> Result<&[T], Error>
[src]This function is unsafe - if this functionality is needed use Reader::buffer::align_to
Directly reads a slice of type T
where 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_bool(&self) -> Result<bool, Error>
[src]Returns the value of the reader if it is a boolean. Otherwise Returns error.
pub fn get_key(&self) -> Result<B::BufferString, Error>
[src]
pub fn get_key(&self) -> Result<B::BufferString, Error>
[src]Retrieves the string value up until the first \0
character.
pub fn get_blob(&self) -> Result<Blob<B>, Error>
[src]
pub fn as_blob(&self) -> Blob<B>
[src]
pub fn get_str(&self) -> Result<B::BufferString, Error>
[src]
pub fn get_str(&self) -> Result<B::BufferString, Error>
[src]Retrieves str pointer, errors if invalid UTF-8, or the provided index is out of bounds.
pub fn get_map(&self) -> Result<MapReader<B>, Error>
[src]
pub fn get_u64(&self) -> Result<u64, 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]
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]
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]
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]
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]
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) -> B::BufferString
[src]
pub fn as_str(&self) -> B::BufferString
[src]Returns empty string if you’re not trying to read a string.
pub fn get_vector(&self) -> Result<VectorReader<B>, Error>
[src]
Trait Implementations
impl<'de> Deserializer<'de> for Reader<&'de [u8]>
[src]
impl<'de> Deserializer<'de> for Reader<&'de [u8]>
[src]type Error = DeserializationError
type Error = DeserializationError
The error type that can be returned if some error occurs during deserialization. Read more
fn is_human_readable(&self) -> bool
[src]
fn is_human_readable(&self) -> bool
[src]Determine whether Deserialize
implementations should expect to
deserialize their human-readable form. Read more
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Require the Deserializer
to figure out how to drive the visitor based
on what data type is in the input. Read more
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a bool
value.
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an i8
value.
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an i16
value.
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an i32
value.
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an i64
value.
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a u8
value.
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a u16
value.
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a u32
value.
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a u64
value.
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a f32
value.
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a f64
value.
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a unit value.
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_unit_struct<V>(
self,
name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a unit struct with a
particular name. Read more
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read more
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a map of key-value pairs.
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting the name of a struct
field or the discriminant of an enum variant. Read more
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a struct with a particular
name and fields. Read more
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_tuple<V>(
self,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a sequence of values and
knows how many values there are without looking at the serialized data. Read more
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_tuple_struct<V>(
self,
name: &'static str,
len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a tuple struct with a
particular name and number of fields. Read more
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a sequence of values.
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a char
value.
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer
. Read more
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an optional value. Read more
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting a newtype struct with a
particular name. Read more
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn deserialize_enum<V>(
self,
_name: &'static str,
_variants: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Hint that the Deserialize
type is expecting an enum value with a
particular name and possible variants. Read more
impl<'de> VariantAccess<'de> for Reader<&'de [u8]>
[src]
impl<'de> VariantAccess<'de> for Reader<&'de [u8]>
[src]type Error = DeserializationError
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
fn unit_variant(self) -> Result<(), Self::Error>
[src]
fn unit_variant(self) -> Result<(), Self::Error>
[src]Called when deserializing a variant with no values. Read more
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> where
T: DeserializeSeed<'de>,
[src]
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Self::Error> where
T: DeserializeSeed<'de>,
[src]Called when deserializing a variant with a single value. Read more
fn tuple_variant<V>(
self,
_len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn tuple_variant<V>(
self,
_len: usize,
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Called when deserializing a tuple-like variant. Read more
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V
) -> Result<V::Value, Self::Error> where
V: Visitor<'de>,
[src]Called when deserializing a struct-like variant. Read more
fn newtype_variant<T>(self) -> Result<T, Self::Error> where
T: Deserialize<'de>,
[src]
fn newtype_variant<T>(self) -> Result<T, Self::Error> where
T: Deserialize<'de>,
[src]Called when deserializing a variant with a single value. Read more
Auto Trait Implementations
impl<B> RefUnwindSafe for Reader<B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
impl<B> Send for Reader<B> where
B: Send,
B: Send,
impl<B> Sync for Reader<B> where
B: Sync,
B: Sync,
impl<B> Unpin for Reader<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for Reader<B> where
B: UnwindSafe,
B: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more