cbor: allow user to control nesting (#329)

* cbor: allow user to control nesting

 - Make the default read/write entrypoints allow infinite nesting.
 - Add {read,write}_nested() entrypoints that allow the crate user to
   control the depth of nesting that's allowed.
 - Along the way, convert the write[_nested] variants to return a
   `Result<(), EncoderError>` rather than a bool.  This exposes
   more failure information (and forces the caller to take notice
   of those tailures), and allows use of the ? operator.

* fixup: transmute error

Co-authored-by: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com>
This commit is contained in:
David Drysdale
2021-06-18 17:39:54 +00:00
committed by GitHub
parent dbce426e9f
commit 0287a09573
10 changed files with 111 additions and 99 deletions

View File

@@ -58,10 +58,10 @@ fn main() {
// Serialize to bytes.
let mut manual_data = vec![];
sk_cbor::writer::write(manual_object, &mut manual_data);
sk_cbor::writer::write(manual_object, &mut manual_data).unwrap();
let hex_manual_data = hexify(&manual_data);
let mut macro_data = vec![];
sk_cbor::writer::write(macro_object, &mut macro_data);
sk_cbor::writer::write(macro_object, &mut macro_data).unwrap();
let hex_macro_data = hexify(&macro_data);
assert_eq!(hex_manual_data, hex_macro_data);