Skip to content
Extension Types
step 1/5

Reading — step 1 of 5

Read

~1 min readComposite Types

Extension Types

Ext type allows custom types. Format: [ext_type_byte] [length] [type_id (1 byte)] [N bytes data].

Predefined ext types:

  • fixext 1: 0xd4 + type + 1 byte.
  • fixext 2: 0xd5 + type + 2 bytes.
  • fixext 4: 0xd6 + type + 4 bytes.
  • fixext 8: 0xd7 + type + 8 bytes.
  • fixext 16: 0xd8 + type + 16 bytes.
  • ext 8: 0xc7 + 1 byte length + type + N bytes.
  • ext 16: 0xc8 + 2 byte length + type + N bytes.
  • ext 32: 0xc9 + 4 byte length + type + N bytes.

Type IDs:

  • 0..127: app-specific.
  • -128..-1: reserved for spec.

Spec uses -1 for timestamp:

fixext 4 (4 bytes data, type -1):
  d6 ff <4 bytes seconds>          → timestamp 32 (32-bit unsigned)

fixext 8 (8 bytes data, type -1):
  d7 ff <8 bytes>                   → timestamp 64
                                       (top 30 bits = nanosec; bottom 34 = sec)

ext 8 with length 12, type -1:
  c7 0c ff <8 bytes ns> <4 bytes sec>  → timestamp 96

This allows nano-precision timestamps.

App-specific examples:

  • type 1: UUID (16 bytes).
  • type 2: BigDecimal.
  • type 3: Custom binary blob.

Implementations often have hooks to register handlers:

python

Without registration: ext appears as opaque ExtType in app code.

Compatibility:

  • New ext type → old reader sees ExtType but doesn't know its meaning.
  • Better than schema break.
  • Apps must declare which types they understand.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…