Canonical Form for Binary Syntax
When two Values are written down in canonical form, comparing
their syntax for equivalence gives the same result as comparing them
semantically according to the equivalence defined in the
Preserves specification.1
That is, canonical forms are equal if and only if the encoded Values
are equal.
This document specifies canonical form for the Preserves machine-oriented binary syntax.
Annotations. Annotations MUST NOT be present.
Sets.
The elements of a Set MUST be serialized sorted in ascending order
by comparing their canonical encoded binary representations.
Dictionaries.
The key-value pairs in a Dictionary MUST be serialized sorted in
ascending order by comparing the canonical encoded binary
representations of their keys.2
Other kinds of Value.
There are no special canonicalization restrictions on
SignedIntegers, Strings, ByteStrings, Symbols, Booleans,
Doubles, Records, Sequences, or Embeddeds. The
constraints given for these Values in the specification
suffice to ensure canonicity.
Notes
-
However, canonical form does not induce a match between lexicographic ordering on syntax and semantic ordering as specified. It only induces a connection between equivalences. ↩
-
There is no need to order by (key, value) pair, since a
Dictionaryhas no duplicate keys. ↩