Struct cbor::Decoder [−][src]
pub struct Decoder<R> { /* fields omitted */ }
Read CBOR data items into Rust values from the underlying reader R
.
Methods
impl<R: Read> Decoder<R>
[src]
impl<R: Read> Decoder<R>
pub fn from_reader(rdr: R) -> Decoder<BufReader<R>>
[src]
pub fn from_reader(rdr: R) -> Decoder<BufReader<R>>
Create a new CBOR decoder from the underlying reader.
impl<R: Read> Decoder<R>
[src]
impl<R: Read> Decoder<R>
ⓘImportant traits for DecodedItems<'a, R, D>pub fn decode<D: Decodable>(&mut self) -> DecodedItems<R, D>
[src]
ⓘImportant traits for DecodedItems<'a, R, D>
pub fn decode<D: Decodable>(&mut self) -> DecodedItems<R, D>
Decode a sequence of top-level CBOR data items into Rust values.
Example
This shows how to encode and decode a sequence of data items:
use cbor::{Decoder, Encoder}; let data = vec![("a".to_string(), 1), ("b".to_string(), 2), ("c".to_string(), 3)]; let mut enc = Encoder::from_memory(); enc.encode(&data).unwrap(); let mut dec = Decoder::from_bytes(enc.as_bytes()); let items: Vec<(String, i32)> = dec.decode() .collect::<Result<_, _>>() .unwrap(); assert_eq!(items, data);
ⓘImportant traits for Items<'a, R>pub fn items(&mut self) -> Items<R>
[src]
ⓘImportant traits for Items<'a, R>
pub fn items(&mut self) -> Items<R>
Read a sequence of top-level CBOR data items.
This yields data items represented by the Cbor
type, which is its
abstract syntax. (Using the decode
iterator is probably much more
convenient, but this is useful when you need to do more sophisticated
analysis on the CBOR data.)
Example
This shows how to encode and decode a sequence of data items:
use cbor::{Cbor, CborUnsigned, Decoder, Encoder}; let mut enc = Encoder::from_memory(); enc.encode(vec![("a", 1), ("b", 2), ("c", 3)]).unwrap(); let mut dec = Decoder::from_bytes(enc.as_bytes()); let items = dec.items().collect::<Result<Vec<_>, _>>().unwrap(); assert_eq!(items, vec![ Cbor::Array(vec![ Cbor::Unicode("a".to_string()), Cbor::Unsigned(CborUnsigned::UInt8(1)), ]), Cbor::Array(vec![ Cbor::Unicode("b".to_string()), Cbor::Unsigned(CborUnsigned::UInt8(2)), ]), Cbor::Array(vec![ Cbor::Unicode("c".to_string()), Cbor::Unsigned(CborUnsigned::UInt8(3)), ]), ]);
impl Decoder<Cursor<Vec<u8>>>
[src]
impl Decoder<Cursor<Vec<u8>>>
pub fn from_bytes<T>(bytes: T) -> Decoder<Cursor<Vec<u8>>> where
T: Into<Vec<u8>>,
[src]
pub fn from_bytes<T>(bytes: T) -> Decoder<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]
.