Trait cbor_data::Writer [−][src]
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
fn max_definite(&self) -> Option<u64>
[src]
Configured maximum array or dict length up to which definite size encoding is used.
Provided methods
fn write_pos(
self,
value: u64,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: u64,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Write a unsigned value of up to 64 bits. Tags are from outer to inner.
fn write_neg(
self,
value: u64,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: u64,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Write a negative value of up to 64 bits — the represented number is -1 - value
.
Tags are from outer to inner.
fn write_bytes(
self,
value: &[u8],
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: &[u8],
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Write the given slice as a definite size byte string. Tags are from outer to inner.
fn write_str(
self,
value: &str,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: &str,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Write the given slice as a definite size string. Tags are from outer to inner.
fn write_bool(
self,
value: bool,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: bool,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Tags are from outer to inner.
fn write_null(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
[src]
Tags are from outer to inner.
fn write_undefined(self, tags: impl IntoIterator<Item = u64>) -> Self::Output
[src]
Tags are from outer to inner.
fn write_lit(
self,
value: Literal,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
[src]
self,
value: Literal,
tags: impl IntoIterator<Item = u64>
) -> Self::Output
Write custom literal value — RFC 7049 §2.3 is required reading. Tags are from outer to inner.
fn write_array<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> Self::Output where
F: FnOnce(&mut ArrayWriter<'_>),
[src]
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> Self::Output where
F: FnOnce(&mut ArrayWriter<'_>),
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); }); });
fn write_array_ret<T, F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> (Self::Output, T) where
F: FnOnce(&mut ArrayWriter<'_>) -> T,
[src]
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> (Self::Output, T) where
F: FnOnce(&mut ArrayWriter<'_>) -> T,
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);
fn write_dict<F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> Self::Output where
F: FnOnce(&mut DictWriter<'_>),
[src]
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> Self::Output where
F: FnOnce(&mut DictWriter<'_>),
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)); }); });
fn write_dict_ret<T, F>(
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> (Self::Output, T) where
F: FnOnce(&mut DictWriter<'_>) -> T,
[src]
self,
tags: impl IntoIterator<Item = u64>,
f: F
) -> (Self::Output, T) where
F: FnOnce(&mut DictWriter<'_>) -> T,
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);
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()
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>,