Class CanonicalMaps
java.lang.Object
ai.badmonkey.agentspaces.common.codec.CanonicalMaps
The canonical order of map entries (ISSUE-CanonicalMaps, wire version 3,
TECH-SPEC §1): every map the codec serializes is written with its entries
sorted by the RFC 8949 §4.2.1 rule for text keys, shorter UTF-8 encoding
first and bytewise between equal lengths, so the signed bytes of a structure
are a function of its content and not of the order its author built a map
in. Record and bean properties are not maps and keep their declared order.
Decoding is unchanged: a decoded map keeps the wire order, which is sorted.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA map the codec writes in insertion order. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<String> The key order: the UTF-8 encodings compared by length, then bytewise unsigned. -
Method Summary
-
Field Details
-
KEY_ORDER
The key order: the UTF-8 encodings compared by length, then bytewise unsigned. For text keys this is exactly the bytewise order of the encoded CBOR keys RFC 8949 §4.2.1 specifies, and every language implements it the same way, whichString.compareTo(UTF-16 units) does not.
-
-
Method Details
-
sorted
Returns a copy of the map with its entries in canonical order. Keys that are not strings are ordered by their string form, which is the form the codec writes them in.- Type Parameters:
K- the key typeV- the value type- Parameters:
map- the map- Returns:
- an insertion-ordered copy, sorted
-