Trait cbor_data::Writer[][src]

pub trait Writer: Sized {
    type Output;
Show methods fn max_definite(&self) -> Option<u64>; fn write_pos(
        self,
        value: u64,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_neg(
        self,
        value: u64,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_bytes(
        self,
        value: &[u8],
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_str(
        self,
        value: &str,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_bool(
        self,
        value: bool,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output { ... }
fn write_undefined(
        self,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_lit(
        self,
        value: Literal,
        tags: impl IntoIterator<Item = u64>
    ) -> Self::Output { ... }
fn write_array<F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> Self::Output
    where
        F: FnOnce(&mut ArrayWriter<'_>)
, { ... }
fn write_array_ret<T, F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> (Self::Output, T)
    where
        F: FnOnce(&mut ArrayWriter<'_>) -> T
, { ... }
fn write_dict<F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> Self::Output
    where
        F: FnOnce(&mut DictWriter<'_>)
, { ... }
fn write_dict_ret<T, F>(
        self,
        tags: impl IntoIterator<Item = u64>,
        f: F
    ) -> (Self::Output, T)
    where
        F: FnOnce(&mut DictWriter<'_>) -> T
, { ... }
fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output> { ... }
fn write_trusting(self, bytes: &[u8]) -> Self::Output { ... }
fn write_item(self, item: Cbor<'_>) -> Self::Output { ... }
}
Expand description

Low-level primitives for emitting CBOR items.

The methods of this trait give you full control over the encoding of values according to the CBOR specification (apart from the technically allowed non-optimal integer encodings). It allows you to emit any item tagged with any number you desire.

If you are looking for convenient methods of writing end-user data types please refer to the Encoder trait.

Associated Types

Required methods

Configured maximum array or dict length up to which definite size encoding is used.

Provided methods

Write a unsigned value of up to 64 bits. Tags are from outer to inner.

Write a negative value of up to 64 bits — the represented number is -1 - value. Tags are from outer to inner.

Write the given slice as a definite size byte string. Tags are from outer to inner.

Write the given slice as a definite size string. Tags are from outer to inner.

Tags are from outer to inner.

Tags are from outer to inner.

Tags are from outer to inner.

Write custom literal value — RFC 7049 §2.3 is required reading. Tags are from outer to inner.

Write a nested array using the given closure that receives an array builder. Tags are from outer to inner.

let cbor = CborBuilder::default().write_array(None, |builder| {
    builder.write_array_ret(None, |builder| {
        builder.write_pos(42, None);
    });
});

Write a nested array using the given closure that receives an array builder. Tags are from outer to inner.

let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder| {
    builder.write_array_ret(None, |builder| {
        builder.write_pos(42, None);
    });
    42
});
assert_eq!(ret, 42);

Write a nested dict using the given closure that receives a dict builder. Tags are from outer to inner.

let cbor = CborBuilder::default().write_array(None, |builder | {
    builder.write_dict_ret(None, |builder| {
        builder.with_key("y", |b| b.write_pos(42, None));
    });
});

Write a nested dict using the given closure that receives a dict builder. Tags are from outer to inner.

let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder | {
    builder.write_dict_ret(None, |builder| {
        builder.with_key("y", |b| b.write_pos(42, None));
    });
    42
});
assert_eq!(ret, 42);

Interpret the given bytes as a single CBOR item and write it to this builder, canonicalising its contents like CborOwned::canonical()

Assume that the given bytes are a well-formed single CBOR item and write it to this builder.

If those bytes are not valid CBOR you get to keep the pieces!

Write the given CBOR item

Implementations on Foreign Types

Implementors