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

Encoding maps in CBOR in canonical form (finite length) #150

Merged
merged 1 commit into from
May 14, 2024

Conversation

philips77
Copy link
Member

This PR changes the way how maps are encoded to CBOR by using a finite length.

Before

Maps were encoded with BF token (indefinite length map), followed by key-value pairs and FF stop sign.

Example

BF...FF - a map oa any size

After

The new CanonicalMapSerializer uses writeStartObject(Object, Int) to encode the map using its length instead.

Example

A0 - empty map
A3... - map with 3 key-value pairs
AF... - map with 15 pairs
B0... - map with 16 pairs
B7... - map with 23 pairs
B8-18... map with 24 pairs

Note

Canonical form of encoding maps is currently not supported in Jackson library nor in Kotlin CBOR. The proper implementation should rather add a Feature to the CBORFactory or somewhere. This one is using a bit of a hack.

This PR is related to FasterXML/jackson-dataformats-binary#3

@philips77 philips77 merged commit 2057fca into main May 14, 2024
1 check passed
@philips77 philips77 deleted the cbor-canonical branch May 14, 2024 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant