Supported Types
This page documents all types supported by Fory C++ serialization.
Primitive Types
All C++ primitive types are supported with efficient binary encoding:
| Type | Size | Fory TypeId | Notes |
|---|---|---|---|
bool | 1 byte | BOOL | True/false |
int8_t | 1 byte | INT8 | Signed byte |
uint8_t | 1 byte | INT8 | Unsigned byte |
int16_t | 2 byte | INT16 | Signed short |
uint16_t | 2 byte | INT16 | Unsigned short |
int32_t | 4 byte | INT32 | Signed integer |
uint32_t | 4 byte | INT32 | Unsigned integer |
int64_t | 8 byte | INT64 | Signed long |
uint64_t | 8 byte | INT64 | Unsigned long |
float | 4 byte | FLOAT32 | IEEE 754 single |
double | 8 byte | FLOAT64 | IEEE 754 double |
char | 1 byte | INT8 | Character (as signed) |
char16_t | 2 byte | INT16 | 16-bits characters |
char32_t | 4 byte | INT32 | 32-bits characters |
int32_t value = 42;
auto bytes = fory.serialize(value).value();
auto decoded = fory.deserialize<int32_t>(bytes).value();
assert(value == decoded);
String Types
| Type | Fory TypeId | Notes |
|---|---|---|
std::string | STRING | UTF-8 encoded |
std::string_view | STRING | Zero-copy view (read) |
std::u16string | STRING | UTF-16 (converted) |
binary | BINARY | Raw bytes without length |
std::string text = "Hello, World!";
auto bytes = fory.serialize(text).value();
auto decoded = fory.deserialize<std::string>(bytes).value();
assert(text == decoded);
Collection Types
Vector / List
std::vector<T> for any serializable element type:
std::vector<int32_t> numbers{1, 2, 3, 4, 5};
auto bytes = fory.serialize(numbers).value();
auto decoded = fory.deserialize<std::vector<int32_t>>(bytes).value();
// Nested vectors
std::vector<std::vector<std::string>> nested{
{"a", "b"},
{"c", "d", "e"}
};
Set
std::set<T> and std::unordered_set<T>:
std::set<std::string> tags{"cpp", "serialization", "fory"};
auto bytes = fory.serialize(tags).value();
auto decoded = fory.deserialize<std::set<std::string>>(bytes).value();
std::unordered_set<int32_t> ids{1, 2, 3};
Map
std::map<K, V> and std::unordered_map<K, V>:
std::map<std::string, int32_t> scores{
{"Alice", 100},
{"Bob", 95}
};
auto bytes = fory.serialize(scores).value();
auto decoded = fory.deserialize<std::map<std::string, int32_t>>(bytes).value();
// Unordered map
std::unordered_map<int32_t, std::string> lookup{
{1, "one"},
{2, "two"}
};