Encoding maps in CBOR in canonical form (finite length) #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 andFF
stop sign.Example
BF...FF
- a map oa any sizeAfter
The new
CanonicalMapSerializer
useswriteStartObject(Object, Int)
to encode the map using its length instead.Example
A0
- empty mapA3...
- map with 3 key-value pairsAF...
- map with 15 pairsB0...
- map with 16 pairsB7...
- map with 23 pairsB8-18...
map with 24 pairsNote
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