Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tagless Encodings

Tagless encodings may be specified by encoding tags in template placeholders and in tagless-element sequences. In binary, this allows the opcode to be elided from the encoding of values that fill tagless slots.

Consider the following data:

[
  { sum: 123, sample_count: 12 },
  { sum:  54, sample_count:  8 },
  { sum: 125, sample_count: 15 },
  { sum: 314, sample_count: 30 },
]

With a macro such as (metric {sum: (:? {#int}), sample_count: (:? {#int}), unit: ms}), it can be encoded more compactly:

[
  (:metric 123 12),
  (:metric  54  8),
  (:metric 125 15),
  (:metric 314 30),
]

We can increase the compactness even more using a tagless-element list as follows:

[{:metric} // {:<macro_name>} specifies a macro-shape
  (123 12),
  ( 54  8),
  (125 15),
  (314 30),
]

Both primitive and macro-shape encodings may be used in tagless-element sequences; only the primitive encodings in the below table may be used in tagless template placeholders.

Ion TypeEncoding NameSize in bytesBinary Encoding TagEncoding
intintvariable0x60FlexInt
int810x61FixedInt
int1620x62FixedInt
int3240x64FixedInt
int6480x68FixedInt
uintvariable0xE0FlexUInt
uint810xE1FixedUInt
uint1620xE2FixedUInt
uint3240xE4FixedUInt
uint6480xE8FixedUInt
floatfloat1620x6BLittle-endian IEEE-754 half-precision float
float3240x6CLittle-endian IEEE-754 single-precision float
float6480x6DLittle-endian IEEE-754 double-precision float
decimalsmall_decimalvariable (2+)0x70Tuple of (int,int8) representing the coefficient and exponent respectively.
timestamptimestamp_day20x82Day precision timestamp
timestamp_min40x83Minute precision timestamp
timestamp_s50x84Second precision timestamp
timestamp_ms60x85Millisecond precision timestamp
timestamp_us70x86Microsecond precision timestamp
timestamp_ns80x87Nanosecond precision timestamp
symbolsymbolvariable0xEEFlexSym