pub struct Encoder<W> { /* private fields */ }Expand description
A non-allocating CBOR encoder writing encoded bytes to the given Write sink.
Implementations§
Source§impl<W: Write> Encoder<W>
impl<W: Write> Encoder<W>
Sourcepub fn writer_mut(&mut self) -> &mut W
pub fn writer_mut(&mut self) -> &mut W
Get mutable access to the inner writer.
Sourcepub fn into_writer(self) -> W
pub fn into_writer(self) -> W
Get back the Write impl.
Sourcepub fn encode<T: Encode<()>>(
&mut self,
x: T,
) -> Result<&mut Self, Error<W::Error>>
pub fn encode<T: Encode<()>>( &mut self, x: T, ) -> Result<&mut Self, Error<W::Error>>
Encode any type that implements Encode.
Sourcepub fn encode_with<C, T: Encode<C>>(
&mut self,
x: T,
ctx: &mut C,
) -> Result<&mut Self, Error<W::Error>>
pub fn encode_with<C, T: Encode<C>>( &mut self, x: T, ctx: &mut C, ) -> Result<&mut Self, Error<W::Error>>
Encode any type that implements Encode.
Sourcepub fn int(&mut self, x: Int) -> Result<&mut Self, Error<W::Error>>
pub fn int(&mut self, x: Int) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR integer.
See Int for details regarding the value range of CBOR integers.
Sourcepub fn undefined(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn undefined(&mut self) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR undefined value.
Sourcepub fn simple(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>
pub fn simple(&mut self, x: u8) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR simple value.
Sourcepub fn f16(&mut self, x: f32) -> Result<&mut Self, Error<W::Error>>
pub fn f16(&mut self, x: f32) -> Result<&mut Self, Error<W::Error>>
Encode an f32 value as a half float (f16).
Requires feature "half".
NB: The conversion from f32 to f16 is potentially lossy.
Generally values are truncated and rounded to the nearest 16-bit
value, except:
- 32-bit values which do not fit into 16 bit become ±∞.
- 32-bit subnormal values become ±0.
- Exponents smaller than the min. 16-bit exponent become 16-bit subnormals or ±0.
For further details please consult the half crate which is
used internally for f16 support.
Sourcepub fn tag<T: Into<Tag>>(&mut self, x: T) -> Result<&mut Self, Error<W::Error>>
pub fn tag<T: Into<Tag>>(&mut self, x: T) -> Result<&mut Self, Error<W::Error>>
Encode a CBOR tag.
Sourcepub fn bytes_len(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn bytes_len(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding len bytes.
In contrast to Encoder::bytes which also encodes a byte string, this
method writes only the CBOR item head.
Sourcepub fn str_len(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn str_len(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding a string of len bytes.
In contrast to Encoder::str which also encodes a string, this
method writes only the CBOR item head.
Sourcepub fn array(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn array(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding an array with len elements.
Sourcepub fn map(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
pub fn map(&mut self, len: u64) -> Result<&mut Self, Error<W::Error>>
Begin encoding a map with len entries.
Sourcepub fn begin_array(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_array(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an array of unknown size.
Use Encoder::end to terminate the array.
Sourcepub fn begin_bytes(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_bytes(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an indefinite number of byte slices.
Use Encoder::end to terminate.
Sourcepub fn begin_map(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_map(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding a map of unknown size.
Use Encoder::end to terminate the map.
Sourcepub fn begin_str(&mut self) -> Result<&mut Self, Error<W::Error>>
pub fn begin_str(&mut self) -> Result<&mut Self, Error<W::Error>>
Begin encoding an indefinite number of string slices.
Use Encoder::end to terminate.