[−][src]Trait cbor_data::Writer
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
Loading content...Required methods
pub fn max_definite(&self) -> Option<u64>[src]
Configured maximum array or dict length up to which definite size encoding is used.
Provided methods
pub fn write_pos(self, value: u64, tag: Option<u64>) -> Self::Output[src]
Write a unsigned value of up to 64 bits.
pub fn write_neg(self, value: u64, tag: Option<u64>) -> Self::Output[src]
Write a negative value of up to 64 bits — the represented number is -1 - value.
pub fn write_bytes(self, value: &[u8], tag: Option<u64>) -> Self::Output[src]
Write the given slice as a definite size byte string.
pub fn write_str(self, value: &str, tag: Option<u64>) -> Self::Output[src]
Write the given slice as a definite size string.
pub fn write_bool(self, value: bool, tag: Option<u64>) -> Self::Output[src]
pub fn write_null(self, tag: Option<u64>) -> Self::Output[src]
pub fn write_undefined(self, tag: Option<u64>) -> Self::Output[src]
pub fn write_lit(self, value: Literal, tag: Option<u64>) -> Self::Output[src]
Write custom literal value — RFC 7049 §2.3 is required reading.
pub fn write_array<F>(self, tag: Option<u64>, f: F) -> Self::Output where
F: FnOnce(&mut ArrayWriter<'_>), [src]
F: FnOnce(&mut ArrayWriter<'_>),
Write a nested array using the given closure that receives an array builder.
let cbor = CborBuilder::default().write_array(None, |builder| { builder.write_array_ret(None, |mut builder| { builder.write_pos(42, None); }); });
pub fn write_array_ret<T, F>(self, tag: Option<u64>, f: F) -> (Self::Output, T) where
F: FnOnce(&mut ArrayWriter<'_>) -> T, [src]
F: FnOnce(&mut ArrayWriter<'_>) -> T,
Write a nested array using the given closure that receives an array builder.
let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder| { builder.write_array_ret(None, |mut builder| { builder.write_pos(42, None); }); 42 }); assert_eq!(ret, 42);
pub fn write_dict<F>(self, tag: Option<u64>, f: F) -> Self::Output where
F: FnOnce(&mut DictWriter<'_>), [src]
F: FnOnce(&mut DictWriter<'_>),
Write a nested dict using the given closure that receives a dict builder.
let cbor = CborBuilder::default().write_array(None, |builder | { builder.write_dict_ret(None, |mut builder| { builder.with_key("y", |b| b.write_pos(42, None)); }); });
pub fn write_dict_ret<T, F>(self, tag: Option<u64>, f: F) -> (Self::Output, T) where
F: FnOnce(&mut DictWriter<'_>) -> T, [src]
F: FnOnce(&mut DictWriter<'_>) -> T,
Write a nested dict using the given closure that receives a dict builder.
let (cbor, ret) = CborBuilder::default().write_array_ret(None, |builder | { builder.write_dict_ret(None, |mut builder| { builder.with_key("y", |b| b.write_pos(42, None)); }); 42 }); assert_eq!(ret, 42);
pub fn write_canonical(self, bytes: &[u8]) -> Option<Self::Output>[src]
Interpret the given bytes as a single CBOR item and write it to this builder,
canonicalising its contents like CborOwned::canonical()
pub fn write_trusting(self, bytes: &[u8]) -> Self::Output[src]
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!
Implementations on Foreign Types
impl<T> Writer for &mut T where
T: Writer<Output = T>, [src]
T: Writer<Output = T>,