Tag             22098 (indirection)
   Data Item       multiple
   Semantics       hint that indicates an additional level of indirection
   Contact         Marc A. Lehmann <>


This tag indicates an additional level of indirection when decoding a value.


Data structures in some languages or data models sometimes employ references, pointers or similar forms of indirection to represent relationships between values. For example, in Perl, CBOR arrays are usually represented as references to perl arrays, rather than arrays themselves, while simple scalar values are represented as these values themselves. However, CBOR leaves explicit references unencodable - while arrays and maps might implicitly result in references, references to simple values, or references to references are not representable.

For example, in Perl:

   { 1, 2, 3, 4 } # reference to a hash, becomes CBOR map
   [ 1, 2, 3, 4 } # reference to an array, becomes CBOR array
   \5             # reference to the scalar value 5, needs extension
   \[]            # reference to a reference to an array, needs extension

This tag allows to encode such references - prefixing a value with this tag indicates a hint to the decoder that the original value was actually a reference. Decoders can chose to heed the hint (if their data model has a convenient representation), or simply ignore it and decode the value as-is.

For example, CBOR encoders for Perl would not use the indirection tag for hash and array references, as the only way to reference these values in a data structure is already by reference. However, references to strings, numbers, other references or other complex objects would be encoded by tagging the referenced value with the indirection tag.

Indirection tags can be nested - each additional level of nesting would indicate an additional indirection.


The following Perl data structure is an array containing a reference to an array, followed by a reference to a string:

   [[], \"string"]

Since Perl cannot have "naked" arrays or maps inside another data structure, but only a reference to it, the natural encoding of this data structure uses a normal array for the array-reference (i.e. it omits the reference). The string reference is uncommon but valid, and not the natural way to store a string inside another data structure. An encoder might therefore chose to encode this string reference using the indirection tag:

   256([[], 22098("string")])

   d9 0100                  # tag(256)
      82                    # array(2)
         80                 # array(0)
         d9 5652            # tag(22098)
            66              # text(6)
               737472696e67 # "string"


This section lists known implementations of this extension (drop me a mail if you want to be listed here).

* [Perl] CBOR::XS (reference implementation)
* [Perl] CBOR::Free