Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d1f8422
fix(reflection): fix dangling string_view in rfl::internal::get_type_…
clockblocker Nov 28, 2026
91de7aa
fix(validation): fix rfl::OneOf broken .and_then().or_else() composition
clockblocker Nov 29, 2026
2248133
fix(json): reject uint64 > INT64_MAX instead of silently wrapping int…
clockblocker Nov 28, 2026
f5331b0
feat(json-schema): emit oneOf for rfl::TaggedUnion in JSON Schema (#375)
clockblocker Nov 29, 2026
b5306ad
fix(headers): eliminate -Wextra, -Wextra-semi, -Wsign-conversion, and…
clockblocker Nov 27, 2026
238a791
fix(parsing): gate <expected> include behind <version> feature test t…
clockblocker Nov 30, 2026
a41fc8c
feat(enums): accept std::string_view in rfl::string_to_enum (#565)
clockblocker Nov 27, 2026
d6bfb77
perf(headers): trim <functional>, <sstream>, and unused <map> from th…
clockblocker Nov 28, 2026
3b7d217
fix(yaml): guard rfl::yaml::Reader against recursive aliases and out-…
clockblocker Nov 25, 2026
f74d86d
fix(yaml): reject negative-to-unsigned wraparound, narrow integer ove…
clockblocker Nov 29, 2026
7062895
fix(xml): fix get_field_from_array index increment and write() indent…
clockblocker Nov 27, 2026
cfefaa8
fix(env): use getenv_s and _dupenv_s under _MSC_VER in rfl::env::Reader
clockblocker Nov 30, 2026
6fc44d7
fix(yaml): return error on non-scalar mapping keys instead of silentl…
clockblocker Nov 29, 2026
610ead4
fix(parsing): prevent std::terminate() at noexcept validation, map-ke…
clockblocker Nov 29, 2026
03c1030
fix(parsing): capture input keys matching ExtraFields member name
clockblocker Nov 29, 2026
0b18dfc
perf(strings): fix O(N^2) replace_all and split and empty-needle infi…
clockblocker Nov 30, 2026
b702de7
docs(licensing): add THIRD_PARTY_NOTICES for vendored dependencies
clockblocker Nov 29, 2026
f4c96d7
fix(enums): backport enchantum MSVC 64-bit enum cast suffix fix
clockblocker Nov 30, 2026
9f4bf6c
fix(json-schema): flatten nested anyOf for optional variants and rfl:…
clockblocker Nov 29, 2026
72cf64a
feat(cli): add rfl::cli::usage to generate usage and help text (#692)
clockblocker Nov 29, 2026
9d2c276
feat(json): add first-class rfl::json read and write flag constants
clockblocker Nov 29, 2026
4e17f7a
perf(parsing): isolate per-field helpers in NamedTupleParser, destruc…
clockblocker Nov 29, 2026
6f8dd02
perf(tuple): replace O(N^2) calculate_positions fold and per-index Tu…
clockblocker Nov 30, 2026
52a67d5
perf(internal): add apply_to_fields and avoid NamedTuple in HasDefaul…
clockblocker Nov 29, 2026
d83aefd
fix(error): preserve structured Error::details() paths in FieldVarian…
clockblocker Nov 29, 2026
dde4888
perf(generic): eliminate O(N*D) subtree deep copies in Generic constr…
clockblocker Nov 30, 2026
5ef60c9
perf(internal): use O(log N) exponential + binary search in cpp20::nu…
clockblocker Nov 29, 2026
654cb38
perf(parsing): isolate per-field helpers in ViewReader and ViewReader…
clockblocker Nov 29, 2026
1ec92e4
feat(enums): add rfl::TransformEnumNames processors (#731)
clockblocker Nov 29, 2026
fe20f8d
feat(reflection): add public rfl::type_name<T>() and rfl::type_name_v<T>
clockblocker Nov 29, 2026
5f4def4
perf(schema): fast-path scalar defaults in NamedTupleParser::to_schema
clockblocker Nov 29, 2026
027fc70
perf(cli): lower_bound prefix skipping in cli::Reader, O(F) usage pos…
clockblocker Nov 30, 2026
f09c67e
perf(named-tuple): O(1)-instantiation find_index, non-recursive find_…
clockblocker Nov 30, 2026
439ae36
perf(processors): eliminate redundant Tuple round-trip copies in case…
clockblocker Nov 30, 2026
64a2659
feat(json-schema): add rfl::IntegerBounds opt-in processor (#683)
clockblocker Nov 29, 2026
d29d3b0
fix(schema): cast char to unsigned char for std::isalnum and add miss…
clockblocker Nov 29, 2026
5657a7a
feat(reflection): expose public rfl::StringLiteral header and constex…
clockblocker Nov 29, 2026
46af4bd
perf(literal): O(1) name lookup, O(log N) string lookup, and O(1)-ins…
clockblocker Nov 30, 2026
c4e1757
perf(formats): O(1) Cap'n Proto union discriminant, O(log M) flexbuf/…
clockblocker Nov 30, 2026
ab2b359
perf(internal): O(1) nth_element/nth_element_t, single-bind C++20 get…
clockblocker Nov 30, 2026
9e432f9
feat(json-schema): add rfl::VariantsAsOneOf opt-in processor (#375)
clockblocker Nov 29, 2026
4504b74
perf(parsing): short-circuit dispatch and symbol isolation for Parser…
clockblocker Nov 30, 2026
530480b
perf(parsing): add FieldNameLookup cursor-hint and binary-search fiel…
clockblocker Nov 29, 2026
1ae4f64
perf(parsing): O(log K) lookup and symbol isolation for FieldVariantR…
clockblocker Nov 30, 2026
91c1292
perf(parsing): O(1) TupleReader dispatch, strip-name/destructor symbo…
clockblocker Nov 30, 2026
081e66c
fix(schema): unwrap Type::Description and Type::Deprecated in Avro an…
clockblocker Nov 29, 2026
603b2cb
feat(enums): add rfl::EnumNames<E> per-enum wire-name trait (#106)
clockblocker Nov 29, 2026
bf4209d
feat(json): add rfl::json::Raw for passthrough raw JSON values (#368)
clockblocker Nov 29, 2026
4e7c74b
perf(variant): inline switch-based Variant::visit, O(1) get_if/elemen…
clockblocker Nov 30, 2026
b14a7f9
perf(tuple): single-pass O(N) tuple_cat, move_from_tuple fast path, w…
clockblocker Nov 30, 2026
41613b3
build(cmake): subproject ergonomics, CMake 3.20 support, warning/lint…
clockblocker Nov 30, 2026
c19e8c8
perf(schema): eliminate O(N^2) Object::operator[] schema insertions a…
clockblocker Nov 30, 2026
eec23bf
build(cmake): isolate bundled yyjson visibility, support external yyj…
clockblocker Nov 30, 2026
1397beb
perf(internal): O(N) remove_fields and balanced define_* type builders
clockblocker Nov 30, 2026
35d4ba8
fix(capnproto): support rfl::Vectorstring in struct fields and unions
clockblocker Dec 2, 2026
6708afe
perf(parsing): use emplace_hint(end()) for ordered maps in MapReader
clockblocker Dec 2, 2026
e7abb80
perf(capnproto): positional DynamicStruct writes, hoisted map handles…
clockblocker Dec 2, 2026
0401593
perf(capnproto): typed capnp::List<T> fast path for numeric vectors a…
clockblocker Dec 2, 2026
f9c004d
fix(capnproto): return rfl::Error on Cap'n Proto reader exceptions
clockblocker Dec 2, 2026
e582504
feat(capnproto): add capnp::ReaderOptions overloads and unpacked flat…
clockblocker Dec 2, 2026
0f1ad5a
fix(headers): replace remaining std::invoke_result with decltype for …
clockblocker Dec 2, 2026
3d33e72
perf(parsing): peel transparent metadata wrappers before Parser read,…
clockblocker Dec 2, 2026
283ad7d
build(tests): respect CMAKE_BUILD_TYPE flags, expand format PCHs, and…
clockblocker Dec 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
652 changes: 509 additions & 143 deletions CMakeLists.txt

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ reflect-cpp and sqlgen fill important gaps in C++ development. They reduce boile
- [Extra fields](#extra-fields)
- [Reflective programming](#reflective-programming)
- [Standard Library Integration](#support-for-containers)
- [Installation](#installation)
- [The team behind reflect-cpp](#the-team-behind-reflect-cpp)
- [License](#license)

### More in our [documentation](https://munich-data-engineering.github.io/reflect-cpp):
- [Installation ↗](https://munich-data-engineering.github.io/reflect-cpp/install/#option-2-compilation-using-cmake)
- [Installation ↗](https://munich-data-engineering.github.io/reflect-cpp/install/#option-3-compilation-using-cmake)
- [C++26 reflection ↗](https://munich-data-engineering.github.io/reflect-cpp/cpp26_reflection)
- [Benchmarks ↗](https://munich-data-engineering.github.io/reflect-cpp/benchmarks)
- [How to contribute ↗](https://munich-data-engineering.github.io/reflect-cpp/contributing)
Expand Down Expand Up @@ -373,6 +374,17 @@ struct Config {
// ./app data.csv -o /tmp/out -v --count=10
```

`rfl::cli::usage` generates the help text from the same struct, for instance for `--help`:

```cpp
if (argc > 1 && std::string_view(argv[1]) == "--help") {
std::cout << rfl::cli::usage<Config>(argv[0], true).value();
// Usage: ./app <input-file> -o|--output-dir=<value> -v|--verbose[=<bool>] --count=<value>
//
// Arguments: ...
}
```

Nested structs, `std::optional`, `std::vector`, enums, `rfl::Flatten` and `rfl::Rename` are all supported. Refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/cli) for details.

### Error messages
Expand Down Expand Up @@ -671,6 +683,7 @@ In addition, it supports the following custom containers:
- `rfl::Tuple`: An alternative to `std::tuple` that compiles considerably faster.
- `rfl::Validator`: Allows for automatic input validation.
- `rfl::Variant`: An alternative to `std::variant` that compiles considerably faster.
- `rfl::json::Raw`: Holds a raw JSON value for passthrough serialization and deserialization (JSON only; [details](https://munich-data-engineering.github.io/reflect-cpp/supported_formats/json/#raw-json-passthrough-rfljsonraw)).

#### Custom classes

Expand All @@ -687,6 +700,29 @@ The following compilers are supported for C++-20:
The following compilers are supported for C++-26:
- GCC 16.2 or higher

### Using CMake FetchContent

JSON-only (zero external dependencies — `yyjson`, `ctre`, and `enchantum` are bundled):

```cmake
include(FetchContent)
FetchContent_Declare(reflectcpp
GIT_REPOSITORY https://github.com/munich-data-engineering/reflect-cpp.git
GIT_TAG main # replace with a release tag containing CMake 3.20 / subproject support
GIT_SHALLOW TRUE
GIT_SUBMODULES "")
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

To enable additional formats (for example YAML), set the corresponding `REFLECTCPP_*` option **before** `FetchContent_MakeAvailable(reflectcpp)` (non-JSON format libraries are resolved via `find_package` from system packages, vcpkg, or Conan because `REFLECTCPP_USE_VCPKG` defaults to `OFF` when consumed as a subproject):

```cmake
set(REFLECTCPP_YAML ON)
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

### Using vcpkg

https://vcpkg.io/en/package/reflectcpp
Expand Down Expand Up @@ -722,7 +758,7 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

For other installation methods, refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/docs-readme).
For other installation methods, refer to the [documentation](https://munich-data-engineering.github.io/reflect-cpp/install).

### Compiling with C++-26 reflection

Expand Down Expand Up @@ -752,3 +788,5 @@ reflect-cpp includes [YYJSON](https://github.com/ibireme/yyjson), the fastest JS
reflect-cpp includes [compile-time-regular-expressions](https://github.com/hanickadot/compile-time-regular-expressions). CTRE is written by Hana Dusíková and released under the Apache-2.0 License with LLVM exceptions.

reflect-cpp includes [enchantum](https://github.com/ZXShady/enchantum/tree/main). enchantum is written by ZXShady and also released under the MIT License.

See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for full third-party license texts, SPDX identifiers, and CMake/feature inclusion conditions.
322 changes: 322 additions & 0 deletions THIRD_PARTY_NOTICES.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
elseif (REFLECTCPP_STRICT_WARNINGS)
# Restore /W3 for benchmark targets after top-level CMakeLists strips /W3 before setting /W4 on reflectcpp.
add_compile_options(/W3)
endif ()

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20 -O2")
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(reflect-cpp-all-format-benchmarks)
project(reflect-cpp-all-format-benchmarks LANGUAGES CXX)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(reflect-cpp-json-benchmarks)
project(reflect-cpp-json-benchmarks LANGUAGES CXX)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

Expand Down
23 changes: 23 additions & 0 deletions docs/content/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,26 @@ constexpr auto enumerator_array = rfl::get_enumerator_array<Color>();

In case it's more convenient to get the enumerator values as values of the enum's underlying type rather than values of the enum type itself,
there is also `rfl::get_underlying_enumerators<EnumType>()` and `rfl::get_underlying_enumerator_array<EnumType>()`.

## Custom wire names (`rfl::EnumNames` and `rfl::TransformEnumNames`)

To customize serialized enum wire names across JSON, CLI, Generic, XML, YAML, and JSON Schema without duplicating enumerators as `rfl::Literal<...>`, specialize `rfl::EnumNames<E>` and/or pass a `rfl::TransformEnumNames<...>` processor (`rfl::EnumSnakeCaseToKebabCase`, `rfl::EnumSnakeCaseToCamelCase`, `rfl::EnumSnakeCaseToPascalCase`, `rfl::EnumCamelCaseToSnakeCase`, `rfl::EnumToLowerCase`, `rfl::EnumToUpperCase`):

```cpp
enum class OptimizationLevel { no_opt, size_opt, speed_opt, cxx_standard };

template <>
struct rfl::EnumNames<OptimizationLevel> {
static constexpr rfl::EnumNameTransform transform =
rfl::EnumNameTransform::snake_to_kebab;
static constexpr std::array<rfl::EnumOverride<OptimizationLevel>, 1>
overrides = {{
{OptimizationLevel::cxx_standard, "c++20"},
}};
};
```

- `overrides` (either a static contiguous range or a static `overrides()` returning a borrowed contiguous range such as `std::span<const rfl::EnumOverride<E>>`) takes precedence over `transform`, and also supports enumerators outside the default reflected range.
- `transform` can be either a `rfl::EnumNameTransform` constant or a static callable `transform(std::string_view)` returning `std::string` or `std::string_view`.
- If `rfl::EnumNames<E>` only defines `overrides` (without `transform`), non-overridden enumerators still receive any `rfl::TransformEnumNames<...>` processor passed to `read`, `write`, or `to_schema`.
- Use `rfl::get_enum_wire_names<E, Processors...>()` to inspect resolved `(wire_name, enumerator)` pairs.
45 changes: 41 additions & 4 deletions docs/content/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ Simply use [this recipe](https://conan.io/center/recipes/reflect-cpp).

## Option 3: Compilation using cmake

### Using FetchContent

To consume reflect-cpp directly from a CMake project with JSON support only (zero external dependencies — `yyjson`, `ctre`, and `enchantum` are bundled):

```cmake
include(FetchContent)
FetchContent_Declare(reflectcpp
GIT_REPOSITORY https://github.com/munich-data-engineering/reflect-cpp.git
GIT_TAG main # replace with a release tag containing CMake 3.20 / subproject support
GIT_SHALLOW TRUE
GIT_SUBMODULES "")
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

To enable additional serialization formats (for example YAML), set the corresponding `REFLECTCPP_*` option **before** `FetchContent_MakeAvailable(reflectcpp)`:

```cmake
set(REFLECTCPP_YAML ON)
FetchContent_MakeAvailable(reflectcpp)
target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp)
```

When reflect-cpp is consumed as a subproject, `REFLECTCPP_USE_VCPKG` defaults to `OFF`, so each non-JSON format's underlying library (such as `yaml-cpp`) is resolved via `find_package` from your system packages, vcpkg toolchain, or Conan generator.

### Subproject packaging options & `reflectcpp::headers`

When embedding reflect-cpp inside larger projects or shared libraries, additional CMake controls are available:

- **`REFLECTCPP_USE_BUNDLED_YYJSON`** (defaults to `REFLECTCPP_USE_BUNDLED_DEPENDENCIES`) and **`REFLECTCPP_YYJSON_TARGET`** (defaults to `yyjson::yyjson` when `REFLECTCPP_USE_BUNDLED_YYJSON=OFF`): reuse an existing external `yyjson` target without disabling bundled `ctre`/`enchantum`. *(Note: if you mix `REFLECTCPP_USE_BUNDLED_DEPENDENCIES=OFF` with `REFLECTCPP_USE_BUNDLED_YYJSON=ON`, ensure no external `<yyjson.h>` on your include path shadows the bundled header.)*
- **`REFLECTCPP_HIDDEN_VISIBILITY`** (default `OFF`): compiles static `reflectcpp` with hidden symbol visibility (`-fvisibility=hidden` / `-fvisibility-inlines-hidden`). Bundled `yyjson_*` symbols are already hidden by default on static non-Windows builds so consumer shared libraries never re-export them.
- **`reflectcpp::headers`**: an exported `INTERFACE` target propagating core reflection (`ctre`/`enchantum`) and JSON (`yyjson`) headers, compile features, and compile definitions without linking compiled `reflectcpp` objects (useful for header-only reflection or intermediate `OBJECT` libraries; final binaries/DSOs using out-of-line symbols still link `reflectcpp::reflectcpp`, and non-JSON backends are not propagated through `reflectcpp::headers`).

### Building standalone

This will compile reflect-cpp with JSON support only. You can then include reflect-cpp in your project and link to the binary.

```bash
Expand All @@ -44,6 +79,8 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

> **Tip (Windows multi-config installs):** When installing both `Debug` and `Release` configurations into the same prefix with Visual Studio, pass `-DCMAKE_DEBUG_POSTFIX=d` so Debug (`reflectcppd.lib`) and Release (`reflectcpp.lib`) libraries coexist without overwriting each other.

## Option 4: Include source files into your own build

Simply copy the contents of the folders `include` and `src` into your source repository or add it to your include path and also add `src/reflectcpp.cpp` and `src/reflectcpp_json.cpp` and `src/yyjson.c` to your source files for compilation.
Expand Down Expand Up @@ -72,11 +109,9 @@ cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
```

To use reflect-cpp in your project:
To use reflect-cpp in your project as a subdirectory, set any optional format flags **before** `add_subdirectory`:

```cmake
add_subdirectory(reflect-cpp) # Add this project as a subdirectory

set(REFLECTCPP_AVRO ON) # Optional
set(REFLECTCPP_BSON ON) # Optional
set(REFLECTCPP_CBOR ON) # Optional
Expand All @@ -87,7 +122,9 @@ set(REFLECTCPP_UBJSON ON) # Optional
set(REFLECTCPP_XML ON) # Optional
set(REFLECTCPP_YAML ON) # Optional

target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
add_subdirectory(reflect-cpp) # Add this project as a subdirectory

target_link_libraries(your_project PRIVATE reflectcpp::reflectcpp) # Link against the library
```

### Troubleshooting vcpkg
Expand Down
25 changes: 25 additions & 0 deletions docs/content/json_schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ This will result in the following JSON schema:

You can insert this into the tools mentioned above and see the generated code.

## Variants and tagged unions

`rfl::TaggedUnion` becomes `oneOf`: every alternative has a different tag, so a value
matches exactly one of them.

`rfl::Variant` and `std::variant` become `anyOf`, because their alternatives can overlap:
`1` is both an `integer` and a `number`, and `{"width": 1, "height": 2}` matches both
`Square` and `Rectangle` from the example in [variants](../variants_and_tagged_unions).
`oneOf` would reject such values, even though reflect-cpp reads them without problems.

If you know that the alternatives of your variants never overlap, you can pass
`rfl::VariantsAsOneOf` to get `oneOf` for `rfl::Variant` and `std::variant` as well:

```cpp
const std::string json_schema =
rfl::json::to_schema<rfl::Variant<int, std::string>, rfl::VariantsAsOneOf>();
```

Warning: `oneOf` rejects values that match more than one alternative, so with this
processor the schema rejects `1` for `rfl::Variant<int, double>`. Structs can overlap
as well, for instance when additional properties are allowed (see `rfl::NoExtraFields`).

`std::optional` and `rfl::Generic` stay `anyOf` either way. `std::optional` is not
a variant, and the alternatives of `rfl::Generic` overlap (`1` is both an `integer` and a `number`).

## Adding descriptions

JSON schemata also often contain descriptions. reflect-cpp supports this as well.
Expand Down
50 changes: 50 additions & 0 deletions docs/content/processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ reflect-cpp currently supports the following processors:
- `rfl::NoFieldNames`
- `rfl::NoOptionals`
- `rfl::UnderlyingEnums`
- `rfl::VariantsAsOneOf`
- `rfl::SnakeCaseToCamelCase`
- `rfl::SnakeCaseToPascalCase`

Expand Down Expand Up @@ -492,6 +493,19 @@ The resulting JSON string looks like this:
{"radius":2.0,"color":1}
```

### `rfl::VariantsAsOneOf`

By default, the JSON schema describes `rfl::Variant` and `std::variant` as `anyOf`.
By passing the processor `rfl::VariantsAsOneOf` to `rfl::json::to_schema`, they
become `oneOf`:

```cpp
rfl::json::to_schema<rfl::Variant<int, std::string>, rfl::VariantsAsOneOf>();
```

It only changes the schema, not reading or writing. Please refer to
the [JSON schema documentation](../json_schema) for details.

### `rfl::SnakeCaseToCamelCase`

Please refer to the example above.
Expand Down Expand Up @@ -549,6 +563,42 @@ The resulting JSON string looks like this:
{"type":"Person","firstName":"Homer","lastName":"Simpson","age":45}
```

## `rfl::TransformEnumNames` (`EnumSnakeCaseToKebabCase`, etc.)

Applies a whole-enum wire-name casing transform to enum fields during reading,
writing, and JSON Schema generation. Resolved wire-name tables are cached once
per `(EnumType, EnumNameTransform)` pair.

Built-in aliases:
- `rfl::EnumSnakeCaseToKebabCase`
- `rfl::EnumSnakeCaseToCamelCase`
- `rfl::EnumSnakeCaseToPascalCase`
- `rfl::EnumCamelCaseToSnakeCase`
- `rfl::EnumToLowerCase`
- `rfl::EnumToUpperCase`

```cpp
enum class CostModel { t_count, two_qubit_gate_count, gate_count };
struct Config { CostModel cost_model; };

const auto json_str = rfl::json::write<rfl::EnumSnakeCaseToKebabCase>(
Config{.cost_model = CostModel::two_qubit_gate_count});
// {"cost_model":"two-qubit-gate-count"}
```

## `rfl::IntegerBounds`

Opt-in schema processor that emits C++ integer width `minimum` and `maximum`
keywords in JSON Schema for signed and unsigned integer types (`int8_t`–`int64_t`,
`uint8_t`–`uint64_t`, etc.), excluding `bool`, character types (`char`, `wchar_t`,
`char8_t`, `char16_t`, `char32_t`), and `rfl::UnderlyingEnums`.

```cpp
struct NetConfig { uint16_t port; };
const auto schema = rfl::json::to_schema<NetConfig, rfl::IntegerBounds>();
// "port": {"type":"integer","minimum":0,"maximum":65535}
```

## Writing your own processors

In principle, writing your own processors is not very difficult. You need to define a struct, which takes has a static method called `process` taking a named tuple as an input and then returning a modified named tuple. The `process` method should accept the type of the original struct as a template parameter.
Expand Down
28 changes: 28 additions & 0 deletions docs/content/supported_formats/capnproto.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ rfl::capnproto::write(person, std::cout) << std::endl;

(Since Cap'n Proto is a binary format, the readability of this will be limited, but it might be useful for debugging).

## Reader options

Cap'n Proto enforces a default traversal limit of 64 MiB (`8 * 1024 * 1024` words) and a default nesting limit of 64 when reading messages. You can pass a `capnp::ReaderOptions` struct to any `rfl::capnproto::read` overload (byte buffers, containers, explicit schemas, or `std::istream`) or `rfl::capnproto::read_unpacked` overload to raise the limit for large messages or tighten it for untrusted input:

```cpp
capnp::ReaderOptions options;
options.traversalLimitInWords = 64ULL * 1024 * 1024; // 512 MiB

const rfl::Result<Person> result = rfl::capnproto::read<Person>(bytes, options);
const rfl::Result<Person> from_stream = rfl::capnproto::read<Person>(my_istream, options);
```

Limit violations and corrupt or truncated messages are reported as `rfl::Error` via `rfl::Result` rather than throwing uncaught exceptions.

## Unpacked flat-array reading and writing

By default, `rfl::capnproto::write` and `rfl::capnproto::read` use Cap'n Proto's packed wire format. When exchanging messages in memory, over shared memory, or from `mmap`-backed buffers, you can skip packing and unpacking with `rfl::capnproto::write_unpacked` and `rfl::capnproto::read_unpacked`:

```cpp
const kj::Array<capnp::word> words = rfl::capnproto::write_unpacked(person);

// Read directly from kj::Array<capnp::word>, kj::ArrayPtr<const capnp::word>,
// std::span<const capnp::word>, or (const capnp::word*, size_t).
const rfl::Result<Person> result = rfl::capnproto::read_unpacked<Person>(words);
```

Both `write_unpacked` and `read_unpacked` accept an optional explicit `rfl::capnproto::Schema<T>`, and `read_unpacked` also accepts an optional `capnp::ReaderOptions`.

## Custom constructors

One of the great things about C++ is that it gives you control over
Expand Down
Loading
Loading