anweiss / cddl

Concise data definition language (RFC 8610) implementation and JSON and CBOR validator in Rust
https://cddl.anweiss.tech
MIT License
91 stars 13 forks source link

Make it easier to only parse CBOR once for use case of validation + deserialization #216

Open itamarst opened 9 months ago

itamarst commented 9 months ago

Due to some issues with the Python cbor2 library, I decided to add deserialization support to pycddl. My prototype works great, and will hopefully release this soon.

The issue is that currently I need to parse the CBOR twice, or clone the parsed value resulting in extra memory usage, because:

  1. cddl::validator::cbor::CBORValidator takes ownership of the ciborium::cbor::Value.
  2. There is no way to extract that value back out once validation is over.

This should be solvable by adding a method to CBORValidator that takes self and returns the Value back out. If you have a specific way you'd prefer this done (extract_value()? impl From<CBORValidator> for ciborium::cbor::Value?) let me know, I can submit a PR either way. Or I'll just choose one if you don't have an opinion.