[][src]Trait cbor_data::Encoder

pub trait Encoder: Writer {
    pub fn encode_u64(self, value: u64) -> Self::Output { ... }
pub fn encode_i64(self, value: i64) -> Self::Output { ... }
pub fn encode_f64(self, value: f64) -> Self::Output { ... }
pub fn encode_array<F, T>(self, f: F) -> (Self::Output, T)
    where
        F: FnMut(&mut ArrayWriter<'_>) -> T
, { ... }
pub fn encode_dict<F, T>(self, f: F) -> (Self::Output, T)
    where
        F: FnMut(&mut DictWriter<'_>) -> T
, { ... } }

High-level encoding functions to write values in their canonical format.

use cbor_data::{CborBuilder, Encoder, Writer};

let cbor = CborBuilder::default().encode_u64(12);

let (array, ret) = CborBuilder::default().encode_array(|builder| {
    builder
        .encode_u64(18)
        .encode_i64(-12);
    42
});
assert_eq!(ret, 42);

let array2 = CborBuilder::default().with_max_definite_size(Some(1)).write_array(None, |builder| {
    builder
        .encode_u64(18)
        .encode_i64(-12);
});

let dict = CborBuilder::default().encode_dict(|builder| {
    builder
        .with_key("a", |b| b.encode_u64(14))
        .with_key("b", |b| b.encode_i64(-1));
}).0;

let (dict2, ret) = CborBuilder::default().write_dict_ret(None, |builder| {
    builder
        .with_key("a", |b| b.encode_u64(14))
        .with_key("b", |b| b.encode_i64(-1));
    "hello"
});
assert_eq!(ret, "hello");

Provided methods

pub fn encode_u64(self, value: u64) -> Self::Output[src]

Encode an unsigned integer of at most 64 bit.

Also to be used for smaller unsigned integers:

use cbor_data::{CborBuilder, Encoder};

let short = 12345u16;
let cbor = CborBuilder::default().encode_u64(short.into());

pub fn encode_i64(self, value: i64) -> Self::Output[src]

Encode a signed integer of at most 64 bit.

Also to be used for smaller signed integers:

use cbor_data::{CborBuilder, Encoder};

let short = -12345i16;
let cbor = CborBuilder::default().encode_i64(short.into());

pub fn encode_f64(self, value: f64) -> Self::Output[src]

Encode a floating-point number of at most 64 bit.

Also to be used for smaller formats:

use cbor_data::{CborBuilder, Encoder};

let single = -3.14f32;
let cbor = CborBuilder::default().encode_f64(single.into());

pub fn encode_array<F, T>(self, f: F) -> (Self::Output, T) where
    F: FnMut(&mut ArrayWriter<'_>) -> T, 
[src]

Write an array that is then filled by the provided closure using the passed builder.

see trait Encoder for usage examples

pub fn encode_dict<F, T>(self, f: F) -> (Self::Output, T) where
    F: FnMut(&mut DictWriter<'_>) -> T, 
[src]

Write a dict that is then filled by the provided closure using the passed builder.

see trait Encoder for usage examples

Loading content...

Implementors

impl<T: Writer> Encoder for T[src]

Loading content...