[go: up one dir, main page]

cbor

Struct DirectDecoder

Source
pub struct DirectDecoder<R> { /* private fields */ }
Expand description

Experimental and incomplete direct decoder.

WARNING: Do not use this to decode CBOR data that you don’t control. It is currently subject to an attack vector that permits an attacker to cause your process to abort due to an out-of-memory error. See: https://github.com/rust-lang/rustc-serialize/issues/115 (The normal decoder in this crate is not subject to this problem.)

A “direct” decoder is one that does not use an intermediate abstact syntax representation. Namely, the bytes are decoded directly into types. This significantly impacts performance. For example, it doesn’t have to box and unbox every data item.

However, implementing a direct decoder is much harder in the existing serialization infrastructure. Currently, structs and enums are not implemented. (But Vecs, tuples, Options and maps should work.)

Implementations§

Source§

impl CborDecoder<Cursor<Vec<u8>>>

Source

pub fn from_bytes<'a, T>(bytes: T) -> CborDecoder<Cursor<Vec<u8>>>
where T: Into<Vec<u8>>,

Create a new CBOR decoder that reads from the buffer given.

The buffer is usually given as either a Vec<u8> or a &[u8].

Source§

impl<R: Read> CborDecoder<BufReader<R>>

Source

pub fn from_reader(rdr: R) -> CborDecoder<BufReader<R>>

Create a new CBOR decoder that reads from the reader given.

Trait Implementations§

Source§

impl<R: Read> Decoder for CborDecoder<R>

Source§

type Error = CborError

The error type for method results.
Source§

fn error(&mut self, err: &str) -> CborError

Record a decoding error. Read more
Source§

fn read_nil(&mut self) -> CborResult<()>

Read a nil value.
Source§

fn read_usize(&mut self) -> CborResult<usize>

Read a usize value.
Source§

fn read_u64(&mut self) -> CborResult<u64>

Read a u64 value.
Source§

fn read_u32(&mut self) -> CborResult<u32>

Read a u32 value.
Source§

fn read_u16(&mut self) -> CborResult<u16>

Read a u16 value.
Source§

fn read_u8(&mut self) -> CborResult<u8>

Read a u8 value.
Source§

fn read_isize(&mut self) -> CborResult<isize>

Read a isize value.
Source§

fn read_i64(&mut self) -> CborResult<i64>

Read a i64 value.
Source§

fn read_i32(&mut self) -> CborResult<i32>

Read a i32 value.
Source§

fn read_i16(&mut self) -> CborResult<i16>

Read a i16 value.
Source§

fn read_i8(&mut self) -> CborResult<i8>

Read a i8 value.
Source§

fn read_bool(&mut self) -> CborResult<bool>

Read a bool value.
Source§

fn read_f64(&mut self) -> CborResult<f64>

Read a f64 value.
Source§

fn read_f32(&mut self) -> CborResult<f32>

Read a f32 value.
Source§

fn read_char(&mut self) -> CborResult<char>

Read a char value.
Source§

fn read_str(&mut self) -> CborResult<String>

Read a string value.
Source§

fn read_enum<T, F>(&mut self, _name: &str, _f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read an enumeration value. Read more
Source§

fn read_enum_variant<T, F>(&mut self, _names: &[&str], _f: F) -> CborResult<T>
where F: FnMut(&mut CborDecoder<R>, usize) -> CborResult<T>,

Read an enumeration value. Read more
Source§

fn read_enum_variant_arg<T, F>(&mut self, _a_idx: usize, _f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read an unnamed data item for an enumeration variant. Read more
Source§

fn read_enum_struct_variant<T, F>( &mut self, _names: &[&str], _f: F, ) -> CborResult<T>
where F: FnMut(&mut CborDecoder<R>, usize) -> CborResult<T>,

Read an enumeration value. Read more
Source§

fn read_enum_struct_variant_field<T, F>( &mut self, _f_name: &str, _f_idx: usize, _f: F, ) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a named data item for an enumeration variant. Read more
Source§

fn read_struct<T, F>( &mut self, _s_name: &str, _len: usize, _f: F, ) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read an struct value. Read more
Source§

fn read_struct_field<T, F>( &mut self, _f_name: &str, _f_idx: usize, _f: F, ) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a field for a struct value. Read more
Source§

fn read_tuple<T, F>(&mut self, len: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a tuple value. Read more
Source§

fn read_tuple_arg<T, F>(&mut self, _a_idx: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a data item for a tuple. Read more
Source§

fn read_tuple_struct<T, F>( &mut self, _s_name: &str, len: usize, f: F, ) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a tuple struct value. Read more
Source§

fn read_tuple_struct_arg<T, F>(&mut self, _a_idx: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read a data item for a tuple struct. Read more
Source§

fn read_option<T, F>(&mut self, f: F) -> CborResult<T>
where F: FnMut(&mut CborDecoder<R>, bool) -> CborResult<T>,

Read an optional value. Read more
Source§

fn read_seq<T, F>(&mut self, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>, usize) -> CborResult<T>,

Read a sequence of values. Read more
Source§

fn read_seq_elt<T, F>(&mut self, _idx: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read an element in the sequence. Read more
Source§

fn read_map<T, F>(&mut self, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>, usize) -> CborResult<T>,

Read an associative container (map). Read more
Source§

fn read_map_elt_key<T, F>(&mut self, _idx: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read the key for an entry in a map. Read more
Source§

fn read_map_elt_val<T, F>(&mut self, _idx: usize, f: F) -> CborResult<T>
where F: FnOnce(&mut CborDecoder<R>) -> CborResult<T>,

Read the value for an entry in a map. Read more

Auto Trait Implementations§

§

impl<R> Freeze for CborDecoder<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for CborDecoder<R>
where R: RefUnwindSafe,

§

impl<R> Send for CborDecoder<R>
where R: Send,

§

impl<R> Sync for CborDecoder<R>
where R: Sync,

§

impl<R> Unpin for CborDecoder<R>
where R: Unpin,

§

impl<R> UnwindSafe for CborDecoder<R>
where R: UnwindSafe,

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<D> DecoderHelpers for D
where D: Decoder,

Source§

fn read_to_vec<T, F>(&mut self, f: F) -> Result<Vec<T>, <D as Decoder>::Error>
where F: FnMut(&mut D) -> Result<T, <D as Decoder>::Error>,

Read a sequence into a vector. 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.