Skip to content

Documentation

The basics

Structs - Recaps the motivating example in the README. A struct is the equivalent of an AND statement or a product type in type theory.

Optional fields - For defining fields in your serialized format that might be absent in some cases.

Struct flattening - For making struct A "inherit" the fields of struct B.

Processors - For modifying the structs before serialization and deserialization. For instance, processors can be used to transform all field names from snake_case to camelCase.

The rfl::Field-syntax - Describes an alternative syntax which requires slightly more effort, but allows for some powerful functionalities.

String literals - For representing strings that can only assume a limited number of enumerated values.

Enums - Describes how reflect-cpp handles C++ enums.

std::variant and rfl::TaggedUnion - For structs that can be one of several formats. This is the equivalent of an OR statement or a sum type in type theory.

rfl::Box and rfl::Ref - For defining recursive structures.

rfl::Timestamp - For serializing and deserializing timestamps.

rfl::Skip - For skipping fields during serialization and/or deserialization.

rfl::Result - For error handling without exceptions.

Standard containers - Describes how reflect-cpp treats containers in the standard library.

C arrays and inheritance - Describes how reflect-cpp handles C arrays and inheritance.

rfl::Bytestring - Describes how reflect-cpp handles binary strings for formats that support them.

rfl::Binary, rfl::Hex and rfl::Oct- For expressing numbers in different formats.

Validation

Regex patterns - For requiring that strings follow used-defined regex patterns.

Validating numbers - For imposing constraints on numbers.

Composing validators - For defining more complex validators using operators such as rfl::AllOf or rfl::AnyOf.

Size validation - For imposing size constraints on containers such as std::vector or std::string.

JSON schema - For validating your schema before you even send it to your C++ backend.

Generic elements

rfl::Object - A map-like type representing a object with field names that are unknown at compile time.

rfl::Generic - A catch-all type that can represent (almost) anything.

rfl::ExtraFields - For adding extra fields to your structs, the names of which are unknown at compile time.

Custom classes

Custom classes - For custom classes with private fields.

Custom parsers for your classes - For custom classes with private fields that you want to leave absolutely untouched.

Useful helper functions and classes

rfl::replace - For replacing one or several fields in a struct.

rfl::as - For casting structs as other structs.

rfl::NamedTuple - For structural typing.

rfl::Tuple - An alternative to std::tuple that compiles more quickly.

rfl::to_view - For accessing fields of a struct by index or name.

Advanced topics

Supporting your own format - For supporting your own serialization and deserialization formats.

Maintaining backwards compatability - Instructions on how to ensure that your API is backwards-compatible with older versions.

Benchmarks - Extensive benchmarks of popular libraries for serialization, deserialization.