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]
| Code | Type | Parent slot | Destination or interpretation |
|---|---|---|---|
| 0 | Null | Inline | Canonical zero in the strict profile |
| 1 | Int | Inline | Signed integer at parent width |
| 2 | UInt | Inline | Unsigned integer at parent width |
| 3 | Float | Inline | Binary32 or binary64 payload |
| 4 | Key | Offset | Zero-terminated key bytes |
| 5 | String | Offset | Content; length prefix before target |
| 6 | IndirectInt | Offset | Signed scalar at child width |
| 7 | IndirectUInt | Offset | Unsigned scalar at child width |
| 8 | IndirectFloat | Offset | Floating scalar at child width |
| 9 | Map | Offset | Value vector with three-field prefix |
| 10 | Vector | Offset | Untyped vector with type table |
| 11 | VectorInt | Offset | Variable typed signed vector |
| 12 | VectorUInt | Offset | Variable typed unsigned vector |
| 13 | VectorFloat | Offset | Variable typed floating vector |
| 14 | VectorKey | Offset | Variable typed key vector |
| 15 | VectorStringDeprecated | Offset | Legacy form; do not emit in new code |
| 16 | VectorInt2 | Offset | Fixed signed pair |
| 17 | VectorUInt2 | Offset | Fixed unsigned pair |
| 18 | VectorFloat2 | Offset | Fixed floating pair |
| Code | Type | Parent slot | Destination or interpretation |
|---|---|---|---|
| 19 | VectorInt3 | Offset | Fixed signed triple |
| 20 | VectorUInt3 | Offset | Fixed unsigned triple |
| 21 | VectorFloat3 | Offset | Fixed floating triple |
| 22 | VectorInt4 | Offset | Fixed signed quadruple |
| 23 | VectorUInt4 | Offset | Fixed unsigned quadruple |
| 24 | VectorFloat4 | Offset | Fixed floating quadruple |
| 25 | Blob | Offset | Raw bytes; length prefix, no terminator |
| 26 | Bool | Inline | Canonical 0 or 1 in strict profile |
| 27–35 | Unassigned in this snapshot | — | Reject in this implementation |
| 36 | VectorBool | Offset | Variable typed boolean vector |
| 37–63 | Not 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
| Operation | Equation |
|---|---|
| Bounded range | p <= N && n <= N - p |
| Alignment padding | (W - (p & (W - 1))) & (W - 1) |
| FlatBuffers ordinary reference | target = slot + U32(slot) |
| FlatBuffers vtable | vtable = table - S32(table) |
| FlatBuffers field entry | vtable + 4 + 2 * field_id |
| FlexBuffers root slot | N - 2 - bytes[N - 1] |
| FlexBuffers reference | target = slot - U(slot, parent_width) |
| FlexBuffers length prefix | target - child_width |
| FlexBuffers vector element | V + i * W |
| Untyped vector element tag | V + N * W + i |
| Map key-vector offset slot | V - 3 * W |
| Map stored key width | U(V - 2 * W, W) |
| Fixed numeric tuple length | 2 + (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
| Value | Complete hexadecimal bytes |
|---|---|
| Signed 13 | 0d 04 01 |
| True | 01 68 01 |
| Null | 00 00 01 |
String Ada | 03 41 64 61 00 04 14 01 |
| Empty string | 00 00 01 14 01 |
| Empty blob | 00 00 64 01 |
| Empty untyped vector | 00 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 triple | 01 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