|
Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
|
This tutorial walks you through the fundamentals of using the Container System. You will learn how to choose the right value type for your data, build containers using the fluent builder API, and iterate over their contents.
value_container (also exposed as message_buffer since v2.0.0) is the primary abstraction in Container System. It is a type-safe, serializable, header+body structure that can hold any combination of the 16 supported value types, including nested containers and arrays.
A typical workflow looks like this:
value_factory or the builder API.Container System defines 16 value types. Choosing the right type matters because it controls:
The table below summarizes when to pick each type.
| Value Type | Code | Use it for | Avoid when |
|---|---|---|---|
null_value | '0' | Optional fields, sentinel placeholders | You need a real value |
bool_value | '1' | Flags, on/off switches | Tri-state values (use int8_value or null_value) |
char_value | '2' | Single ASCII character codes | Multi-byte text (use string_value) |
int8_value | '3' | Small signed counters, status codes | Values >127 or <-128 |
uint8_value | '4' | Bytes, small unsigned counters | Negative numbers |
int16_value | '5' | Mid-range counts, signed IDs | Values outside [-32k, 32k] |
uint16_value | '6' | Port numbers, small unsigned IDs | Negative numbers |
int32_value | '7' | General-purpose integers, signed IDs | Values exceeding ±2.1B |
uint32_value | '8' | Unix timestamps (seconds), unsigned IDs | Negative numbers, values exceeding 4.2B |
int64_value | '9' | Large signed IDs, balances, nanosecond timestamps | Floating-point fractions |
uint64_value | 'a' | Hash values, large counters, monotonic IDs | Negative numbers |
float_value | 'b' | Game coordinates, sensor readings (low precision OK) | Financial calculations |
double_value | 'c' | Money, scientific data, high-precision math | Bit-exact representation needed (use integer cents) |
bytes_value | 'd' | Binary blobs, encrypted payloads, image data | Human-readable text |
container_value | 'e' | Nested structured records | Flat scalar collections (use array or repeat keys) |
string_value | 'f' | UTF-8 text, names, descriptions | Fixed-width binary |
int64_value for user_id, string_value for username, double_value for balance, bool_value for active.uint32_value for timestamp, float_value for temperature, uint16_value for device_id.bytes_value for payload, uint32_value for crc, uint16_value for length.The fluent messaging_container_builder API is the most ergonomic way to construct containers. It accepts native C++ types and selects the matching value_types automatically.
If you need explicit control over each value type (for example, when bridging from another type system), use value_factory directly.
The most common pattern is keyed lookup of a known field.
value_container supports range iteration over its top-level values, so you can walk the entire body without knowing the keys in advance.
Nested containers form a tree. Recursion is the natural way to walk it.