pub fn import_from_reader<R: Read, W: Write>(
input_format: &str,
reader: R,
writer: &mut W,
) -> Result<()>Expand description
Convert a stream of some other format into a stream of CBOR bytes.
Each top-level item in the input is serialized to CBOR and written to
writer. The input is never buffered in memory — items are streamed one at
a time.
§Arguments
input_format: one of"json","yaml","toml","cbor". A"cbor"input is re-emitted item-for-item (passthrough/normalization).reader: the input byte stream. Multiple concatenated top-level items are supported for every format that allows it (all except yaml/toml, which consume the whole stream as one value).writer: the CBOR output sink.
§Example
use cbor_cli::import::import_from_reader;
let json = br#"{"key": "value"}"#;
let mut cbor = Vec::new();
import_from_reader("json", &json[..], &mut cbor).unwrap();
assert_eq!(cbor[0], 0xa1); // CBOR map header (major type 5, length 1)