Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Encoded CBOR data item #104

Open
sargun opened this issue Jan 25, 2021 · 3 comments
Open

Support Encoded CBOR data item #104

sargun opened this issue Jan 25, 2021 · 3 comments

Comments

@sargun
Copy link

sargun commented Jan 25, 2021

CBOR has the idea of encoding data items in binary (CBOR) and then embedding them in the object itself. This has some really big benefits around in-place decoding because bstr are length prefixed, and you can skip decoding the entire item versus having to seek through the stream.

@Sekenre
Copy link
Collaborator

Sekenre commented Feb 18, 2021

CBOR Tags 24 and 63 are used for this. I think it makes sense to handle this at the application level since the choice of which items to embed should lie with the application developer.

The encoder method encode_to_bytes is designed for this, but could do with documentation and example usage. The equivalent decoder method is decode_from_bytes

tag 24 is used for single items, and 63 is used for an embedded sequence. We have not yet explored how best to handle sequences other than cbor2.tool which can call the decoder iteratively.

I would be interested in further discussion/suggestions/

@sargun
Copy link
Author

sargun commented Feb 18, 2021

It'd be nice to be able to have some documentation on how to write an object that would naturally encode into tag 24. Or potentially a base class you could subclass and get encoded as tag 24?

@Sekenre
Copy link
Collaborator

Sekenre commented May 28, 2021

Here's something I threw together: https://gist.github.com/Sekenre/ccee9ae253d1b7612b4da57361eff271

If that works for you I can add it to our documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants