This is an archive of the discontinued Mercurial Phabricator instance.

cborutil: implement streaming arrays and maps
AbandonedPublic

Authored by indygreg on Apr 6 2018, 6:10 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

The vendored cbor2 package doesn't have support for streaming /
indefinite length items when encoding. This is kind of unfortunate.

While it might be worth our while to upstream this feature to the
package, for now it is more expedient to implement it ourselves.

This commit implements support for encoding indefinite length
arrays and maps. We use a context manager that receives a CBOREncoder
and hands the caller a function that can be used to write individual
items. When the context manager exits, the "break" byte is sent.

As a refresher of RFC 7042, tThe initial byte of a CBOR item contains
3 bits for the major type and 5 bits for additional information.
Information value 31 is used to denote indefinite-length items.

Indefinite length arrays and maps simply emit their items inline. After
the final item, a "break" byte (major type 7, additional information 31

  • value 0xff) is written. There are no nesting restrictions.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Apr 6 2018, 6:10 PM
indygreg planned changes to this revision.Apr 12 2018, 9:41 PM

I still have a need for this. But I need to refactor it first.

indygreg abandoned this revision.Apr 12 2018, 11:04 PM

I'll resubmit this as a new review on a different series.