Struct cbor::Encoder
[−]
[src]
pub struct Encoder<W> { // some fields omitted }
Encodes Rust values to CBOR bytes in the underlying writer W
.
Note that currently, using the serialization infrastructure is the only way to write CBOR in this crate.
Methods
impl<W: Write> Encoder<W>
[src]
fn from_writer(wtr: W) -> Encoder<BufWriter<W>>
Encode CBOR to an arbitrary writer.
fn encode<I>(&mut self, it: I) -> CborResult<()> where I: IntoIterator, I::IntoIter::Item: Encodable
Encode an iterator of Rust values to CBOR in the underlying writer.
Every value in the iterator must satisfy Encodable
(from the
rustc-serialize
crate).
Note that this encodes top-level CBOR data items. They can be decoded in a streaming fashion.
Example
Encode a list of numbers.
use cbor::Encoder; let mut enc = Encoder::from_memory(); enc.encode(&[1, 2, 3, 4, 5]); assert_eq!(vec![1, 2, 3, 4, 5], enc.as_bytes());
fn flush(&mut self) -> CborResult<()>
Flush the underlying writer.
impl Encoder<Vec<u8>>
[src]
fn from_memory() -> Encoder<Vec<u8>>
Encode CBOR to an in memory buffer.
fn as_bytes(&mut self) -> &[u8]
Flush and retrieve the CBOR bytes that have been written.
fn into_bytes(self) -> Vec<u8>
Flush and retrieve the CBOR bytes that have been written without copying.