preserves/canonical-binary.md

1.7 KiB

title
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 compact binary syntax.

General rules. Streaming formats ("format C") MUST NOT be used. Annotations MUST NOT be present. Whenever there is a choice between fixed-length ("format A") or variable-length ("format B") formats, the fixed-length format MUST be used.

Sets. The elements of a Set MUST be serialized sorted in ascending order following the total order relation defined in the Preserves specification.

Dictionaries. The key-value pairs in a Dictionary MUST be serialized sorted in ascending order by key, following the total order relation defined in the Preserves specification.2

Other kinds of Value. There are no special canonicalization restrictions on SignedIntegers, Strings, ByteStrings, Symbols, Booleans, Floats, Doubles, Records, or Sequences.

Notes


  1. 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. ↩︎

  2. There is no need to order by (key, value) pair, since a Dictionary has no duplicate keys. ↩︎