Skip to content

Types and codecs

Type Meaning
unit No value
bool Boolean
i8 i16 i32 i64 u8 u16 u32 u64 Integers
f32 f64 IEEE 754 floats
string UTF-8 text
bytes Byte string
timestamp An instant, millisecond precision
uuid 128-bit UUID
{"option": T} T or absent/null. {"option": "unit"} is not allowed
{"list": T} Sequence
{"map": T} Map with string keys and T values
{"tuple": [T...]} Fixed-length heterogeneous sequence
{"ref": "Name"} Reference to a named type
"any" An untyped item of the CBOR data model (RFC 8949 §2), passed through as received. Codegen emits the runtime’s own type for such an item, so a value of another shape is a compile error

Named types (in the manifest’s types table):

  • Struct: {"struct": {"fields": [{"name": "...", "type": T, "optional": bool}]}}. optional is only valid on fields whose type is {"option": T}; it means the field may be omitted on the wire. A missing key for an optional field decodes as absent (null); a missing key for any other field is a decode error (INVALID_ARGUMENT).
  • Enum: {"enum": {"variants": [{"name": "...", "type": T?}], "open": bool?}}. A variant without type is a unit variant. An open enum (open: true, default false) tells decoders to map an unknown variant to a generated catch-all (Unknown carrying the raw variant name) instead of failing, which makes adding variants a compatible change (§12.7). Application code MUST handle the catch-all. In an open enum a variant MUST NOT be named Unknown (manifest validation error). The catch-all keeps only a name that follows the name grammar and is at most 255 bytes, the manifest’s name limit (§12.2); any other unknown name is a decode error. The catch-all is decode-only; encoding it is a local error (§12.3). Closed enums stay strict.
  • Alias: {"alias": T}

Generics are not supported in the manifest. Implementations monomorphize each instantiation into a distinct named type: the outer type name, followed for each type argument in order by an underscore and the argument’s name as it appears in the type table, or the primitive name (Page_Message, Page_u32, Page_List_Message for a nested instantiation). A collision with a user-defined name is a manifest validation error.

Type cbor json
unit null null
bool bool bool
8-32-bit integers int number
i64, u64 int string (decimal), to avoid JavaScript precision loss
f32, f64 float; encoders emit the shortest of half, single and double precision that represents the value exactly; decoders MUST accept all three widths, and round a double to the nearest single-precision value for f32; a finite value that rounds to infinity in single precision is a decode error number; NaN/±Infinity are not allowed; for f32, decoders read the number as a double and round it to the nearest single-precision value; a finite value that rounds to infinity in single precision is a decode error
string text string
bytes byte string base64url string without padding; decoders reject padded input
timestamp, from 0000-01-01T00:00:00.000Z to 9999-12-31T23:59:59.999Z tag 1 (epoch seconds); encoders emit an integer for whole seconds and otherwise the shortest float that preserves millisecond precision; decoders accept integer or float RFC 3339 string in UTC with milliseconds
uuid tag 37 with 16-byte byte string lowercase hyphenated string
option value, or null value, or null
list, tuple array array
map map with text keys object
struct map with text keys = field names; optional fields that are absent are omitted object
unit enum variant text = variant name string
data enum variant single-entry map {variant_name: value} single-key object
any the item as held, with map entries in the order held its JSON form, with map entries in the order held and integers written with every digit, an exception to RFC 8785 §3.2.2
  • Encoding order: encoders MUST produce one encoding per value, so test vectors are byte-exact and equal values encode to equal bytes. cbor: definite lengths and the shortest form of every integer and length (RFC 8949 §4.2.1, except key order); struct fields in the declaration order of the manifest (§12.2); map keys sorted by the bytewise order of their encodings (RFC 8949 §4.2.1). json: no insignificant whitespace; strings and numbers serialized as RFC 8785 §3.2.2 specifies; struct members in declaration order; map members sorted by the bytewise order of their UTF-8 keys. A value of type any keeps its map entries in the order held, and in json its integers keep every digit (table above); the other rules apply to it as to any value. Decoders MUST accept struct fields and map keys in any order and any valid encoding.
  • Field and variant names on the wire are exactly the manifest names. Generators MAY expose idiomatic names in the target language but MUST map them back.
  • Decoders MUST ignore unknown struct fields (forward compatibility). Unknown variants of a closed enum are a decode error; open enums map them to the catch-all (§12.1).
  • JSON decoders MUST reject NaN/Infinity, duplicate object keys, and invalid UTF-8. CBOR decoders MUST accept only the tags the contract type declares (1 for timestamp, 37 for uuid); other tags inside typed values are a decode error, while any values pass tags through untouched. Data sections are subject to a depth limit and to max_frame. Every receiver MUST accept data sections nested 16 deep, and MAY accept deeper ones for its own reads. Encoders check against 16, whatever depth they accept themselves: a value nested deeper than 16, or with more than 16 tags along a path, does not encode, since a receiver may refuse it. Tags count separately from that nesting: the path from the root of a data section to any item holds at most as many tags as the depth limit, in one run or spread between arrays and maps, and a decoder MUST refuse a data section past it as one nested too deep.
  • CBOR decoders MUST reject invalid UTF-8 in text strings (RFC 8949 §5.3.1) and a map that holds a key twice (RFC 8949 §5.6), anywhere in a data section, any values included. Encoders of either codec MUST NOT write a map that holds a key twice. Two integer keys, two text keys or two byte-string keys are one key when their values are equal; two keys of any other kind are one key when a cbor encoder writes the same bytes for them, in the forms given under Encoding order, with map entries in the order held and a NaN as f9 7e 00. So 1.0 written as a half or a single float is one key, two NaN keys are one key, and 0.0 and -0.0 are two keys.
  • When the session codec is json, encoding an any value that has no JSON form is a local error. Such a value holds a byte string; a tag; a simple value other than true, false and null, undefined included; a NaN or infinite float; a map key that is not text; or a map that holds a key twice. An any value that holds a simple value from 20 to 31 has no form in either codec: 20 to 23 are the encodings of false, true, null and undefined, and 24 to 31 are reserved (RFC 8949 §3.3).
  • Values that do not encode: a value does not encode in a codec when it is not a value of its contract type (§12.1), or when the rules of this section give it no form there: the codec table, the rule on repeated map keys, the depth limit, or the CBOR data model. For example: an integer outside its type; an f32 with no exact single-precision form, such as 0.1; an any value with no form in that codec; the catch-all of an open enum (§12.1); a simple value from 20 to 31; a NaN or infinite f32 or f64 in json; a map that holds a key twice; a value nested deeper than 16; a timestamp outside the range the codec table gives. A value with more than one of these problems does not encode either, and which of them an implementation reports is not specified. Such a value is never sent. Frames without a data section, and PING and PONG, are outside this rule and the table below.
  • Entry rule: when data enters the server, the server refuses it unless every codec the endpoint offers (§13.8) can encode it, before the data is queued for any session or given an offset. The depth is checked against the data section the value travels in, against 16 as for any encoder. Framing uses up nesting room only: presence info sits inside the array and an entry map of a PRESENCE data section and nests at most 14 (§10.6), and the arguments of a NOTIFY sit inside its array and nest at most 15 each (§9.1). Framing holds no tags, so the tags on each path are counted over the whole data section, against 16, as for any value. This covers a NOTIFY or a datagram sent to any target but Session(id) (§13.1), a publication, and presence info, whatever codecs the recipients use. A send to one known session, Session(id), is encoded in that session’s codec and has the outcome the table gives. Refusing at entry keeps replays and recovery (§10.2, §10.5) gapless and exactly-once (§13.7) for subscribers that join later. A snapshot is still encoded and checked before the subscription is registered (§10.2 step 7).

The outcome of a value that does not encode, by frame or data:

Frame or data Outcome
CALL arguments The caller fails the call locally with INVALID_ARGUMENT and nx: true. Nothing is sent.
SUBSCRIBE parameters The client fails the subscription locally, with no nx. Nothing is sent.
NOTIFY or datagram sent by a client, sent to Session(id), or refused by the entry rule Refused to the sending code. Nothing is sent, and no status is defined: each runtime uses its own error type.
RESULT, or a typed error detail The callee answers ERROR INTERNAL, under the disclosure rule of §8.4.
SUBSCRIBED snapshot REQUEST_ERROR INTERNAL, and the subscription is not registered (§10.2 step 7).
Presence info at join REQUEST_ERROR INTERNAL, the subscription is not registered, and no join is emitted (§10.2 step 7).
Presence info at update Refused to the code that supplies it.
Publication Refused to the publishing code. Nothing is published and the offset does not advance.
Streamed ITEM (either direction) Rejected to the producing code, and the call stays open, as for an oversized ITEM (§6.4); no status is defined.

From the specification: §12.1, §12.3.