Appendix A Type Codes and Byte Equations

Book contents · Previous: Part V LiveFlex Mutable Memory · Next: Appendix B Exercise Solutions and Implementation Hints

Appendix A of FlatBuffers & FlexBuffers: From Bytes to Mutable Memory. Type Codes and Byte Equations from the complete supplied first edition.

This is the supplied first edition, pinned to its September 2026 source baseline. The laboratories and LiveFlex capstone are educational implementations and design proposals. The book overview explains the evidence limits; Reaktor’s performance review documents the current framework.

Appendix A: Type codes and byte equations

Complete FlexBuffers type table for this edition

The numeric codes below are from the pinned C++ source. The packed type byte is (code << 2) | width_code, where width codes 0, 1, 2, and 3 mean 1, 2, 4, and 8 bytes respectively. “Indirect” describes the parent slot, not an extra field stored beside every object. [1]

CodeTypeParent slotDestination or interpretation
0NullInlineCanonical zero in the strict profile
1IntInlineSigned integer at parent width
2UIntInlineUnsigned integer at parent width
3FloatInlineBinary32 or binary64 payload
4KeyOffsetZero-terminated key bytes
5StringOffsetContent; length prefix before target
6IndirectIntOffsetSigned scalar at child width
7IndirectUIntOffsetUnsigned scalar at child width
8IndirectFloatOffsetFloating scalar at child width
9MapOffsetValue vector with three-field prefix
10VectorOffsetUntyped vector with type table
11VectorIntOffsetVariable typed signed vector
12VectorUIntOffsetVariable typed unsigned vector
13VectorFloatOffsetVariable typed floating vector
14VectorKeyOffsetVariable typed key vector
15VectorStringDeprecatedOffsetLegacy form; do not emit in new code
16VectorInt2OffsetFixed signed pair
17VectorUInt2OffsetFixed unsigned pair
18VectorFloat2OffsetFixed floating pair
CodeTypeParent slotDestination or interpretation
19VectorInt3OffsetFixed signed triple
20VectorUInt3OffsetFixed unsigned triple
21VectorFloat3OffsetFixed floating triple
22VectorInt4OffsetFixed signed quadruple
23VectorUInt4OffsetFixed unsigned quadruple
24VectorFloat4OffsetFixed floating quadruple
25BlobOffsetRaw bytes; length prefix, no terminator
26BoolInlineCanonical 0 or 1 in strict profile
27–35Unassigned in this snapshot—Reject in this implementation
36VectorBoolOffsetVariable typed boolean vector
37–63Not supported by this snapshot—Reject rather than guess

A type-number range check is not enough to establish support when there are gaps. A future assignment of a previously unused code should cause an explicit capability decision, not accidental interpretation by arithmetic intended for an older family.

The equations worth memorizing

OperationEquation
Bounded rangep <= N && n <= N - p
Alignment padding(W - (p & (W - 1))) & (W - 1)
FlatBuffers ordinary referencetarget = slot + U32(slot)
FlatBuffers vtablevtable = table - S32(table)
FlatBuffers field entryvtable + 4 + 2 * field_id
FlexBuffers root slotN - 2 - bytes[N - 1]
FlexBuffers referencetarget = slot - U(slot, parent_width)
FlexBuffers length prefixtarget - child_width
FlexBuffers vector elementV + i * W
Untyped vector element tagV + N * W + i
Map key-vector offset slotV - 3 * W
Map stored key widthU(V - 2 * W, W)
Fixed numeric tuple length2 + (type_code - 16) / 3

Every equation involving untrusted values requires the relevant checked arithmetic and bounds conditions before pointer formation. The notation is a compact memory aid, not a complete verifier.

Small golden buffers

ValueComplete hexadecimal bytes
Signed 130d 04 01
True01 68 01
Null00 00 01
String Ada03 41 64 61 00 04 14 01
Empty string00 00 01 14 01
Empty blob00 00 64 01
Empty untyped vector00 00 28 01
Untyped [1,2,3]03 01 02 03 04 04 04 06 28 01
Typed signed [1,2,3]03 01 02 03 03 2c 01
Fixed signed triple01 02 03 03 4c 01

These buffers are generated by the companion and checked by its tests. Their validity is grounded in the described wire rules; executed independent-runtime confirmation remains a separate qualification step.

REFERENCE & COMPLETE SOURCE


Book contents · Previous: Part V LiveFlex Mutable Memory · Next: Appendix B Exercise Solutions and Implementation Hints