Class CanonicalMaps

java.lang.Object
ai.badmonkey.agentspaces.common.codec.CanonicalMaps

public final class CanonicalMaps extends Object
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.
  • Field Details

    • KEY_ORDER

      public static final Comparator<String> 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, which String.compareTo (UTF-16 units) does not.
  • Method Details

    • sorted

      public static <K,V> Map<K,V> sorted(Map<K,V> map)
      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 type
      V - the value type
      Parameters:
      map - the map
      Returns:
      an insertion-ordered copy, sorted