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]

Create a new CBOR decoder from the underlying reader.

impl<R: Read> Decoder<R>
[src]

Important traits for DecodedItems<'a, 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>

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]

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

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

Auto Trait Implementations

impl<R> Send for Decoder<R> where
    R: Send

impl<R> Sync for Decoder<R> where
    R: Sync