Skip to content

mattih11/SeRTial

Repository files navigation

SeRTial Logo

SeRTial

Serialization for Real-Time - A high-performance, zero-allocation C++20 binary serialization library using compile-time reflection.

License: GPL v2


Key Features

  • Zero Allocation: Stack-only buffers with compile-time size computation
  • Compile-Time Reflection: Automatic struct analysis via reflect-cpp
  • Bounded Containers: fixed_vector<T,N>, fixed_string<N>, RingBuffer<T,N> with runtime sizes
  • Compile-Time Strings: Full constexpr support with auto size deduction ("text"_fs, CTAD, NTTP)
  • Block-Based Serialization: Optimal memory copying via StructLayout<T> analysis
  • Interactive Viewer: HTML-based schema visualization tool
  • Simple API: serialize(obj) / deserialize<T>(data) - zero boilerplate

Quick Start

#include <sertial/sertial.hpp>

struct Position {
    float x, y, z;
};

int main() {
    Position pos{1.5f, 2.5f, 3.5f};
    
    // Serialize
    auto buffer = sertial::serialize(pos);
    
    // Deserialize
    auto restored = sertial::deserialize<Position>(buffer.view());
    
    std::cout << "Position: (" << restored->x << ", " 
              << restored->y << ", " << restored->z << ")\n";
}

Installation

Prerequisites

  • CMake 3.20+
  • C++20 compiler (GCC 10+, Clang 12+, MSVC 2019+)
  • reflect-cpp

Install reflect-cpp

git clone https://github.com/getml/reflect-cpp.git
cd reflect-cpp && mkdir build && cd build
cmake .. && cmake --build . && sudo cmake --install .

Build SeRTial

git clone https://github.com/mattih11/SeRTial.git
cd SeRTial && mkdir build && cd build
cmake .. && cmake --build .

Install System-Wide

sudo cmake --install .

Installs to:

  • /usr/local/include/sertial/ - Headers
  • /usr/local/bin/sertial-inspect - CLI tool
  • /usr/local/share/sertial/ - HTML viewer

Use in Your Project

find_package(SeRTial REQUIRED)
target_link_libraries(your_target PRIVATE SeRTial::SeRTial)

Documentation

API Documentation

  • API Reference - Auto-generated from source (run make docs after building)
    • Browse: docs/api/html/index.html
    • Requires: Doxygen

User Guides

Developer Guides

Technical References

API Documentation

  • Doxygen API Reference - Complete API documentation (auto-generated)
  • Local build: Run make docs in build directory (requires Doxygen)

Tools


Containers

SeRTial provides bounded containers for real-time safe serialization:

Container Purpose Capacity Size Compile-Time
fixed_vector<T, N> Dynamic list Fixed Variable -
fixed_string<N> Text Fixed Variable Full constexpr
RingBuffer<T, N> Circular buffer Fixed Variable -
static_buffer<N> Raw bytes Fixed Variable -
std::array<T, N> Fixed-size array Fixed Fixed Full constexpr

NEW: fixed_string now supports full compile-time construction:

constexpr fixed_string name{"SeRTial"};  // Auto-deduces fixed_string<7>
using namespace sertial::literals;
auto msg = "RealTime"_fs;                // User-defined literal

See: Container Guide for complete reference


Schema Viewer

Visualize your message layouts interactively:

Live Demo: https://mattih11.github.io/SeRTial/tools/sertial-inspect/viewer.html?schema=https://raw.githubusercontent.com/mattih11/SeRTial/main/examples/schemas/example_schemas.json

Generate schemas:

cd build
./schema_example my_schemas.json
# Open viewer.html with my_schemas.json

See: Schema Viewer Guide for details


Project Structure

include/sertial/           # Public API headers
├── sertial.hpp           # Main entry point
├── containers/           # Bounded containers (fixed_vector, fixed_string, RingBuffer)
├── core/                 # Type analysis (StructLayout, traits, concepts)
├── io/                   # Serialization API (serialize/deserialize)
├── integration/          # Schema export
└── reflector/            # reflect-cpp integrations

docs/                     # Documentation
├── USER_GUIDE.md
├── CONTAINER_GUIDE.md
├── EXAMPLES.md
└── ...

examples/                 # Runnable examples
├── serialization_example.cpp
├── schema_example.cpp
└── ring_buffer_example.cpp

test/                     # Unit tests
├── test_serialization.cpp
├── test_foundation.cpp
├── test_ring_buffer.cpp
└── ...

tools/sertial-inspect/    # Visualization tools
├── main.cpp             # CLI tool
├── viewer.html          # Interactive browser viewer
└── README.md

Examples

With Containers

#include <sertial/sertial.hpp>
#include <sertial/containers/fixed_vector.hpp>

struct SensorData {
    uint64_t timestamp;
    uint32_t sensor_id;
    sertial::fixed_vector<float, 100> readings;
};

SensorData data;
data.timestamp = 1234567890;
data.sensor_id = 42;
data.readings.push_back(25.5f);
data.readings.push_back(26.0f);

auto buffer = sertial::serialize(data);
// Size: 8 + 4 + 4 + 2*4 = 24 bytes (not 8 + 4 + 404!)

With Compile-Time Strings (NEW)

#include <sertial/sertial.hpp>
#include <sertial/containers/fixed_string.hpp>

// CTAD - auto size deduction
constexpr sertial::fixed_string device{"Sensor_42"};  // fixed_string<9>

// User-defined literals
using namespace sertial::literals;

struct Config {
    decltype(device) name;
    uint32_t rate_hz;
};

Config config{
    .name = "Sensor_42"_fs,  // Compile-time construction
    .rate_hz = 100
};

auto buffer = sertial::serialize(config);

See: Examples Guide for more patterns


Current Status

Version: 2.0.0 (Released February 2026)

Phase 4 Complete (Reflector-Based Introspection):

  • Reflector-based schema export (zero boilerplate)
  • Interactive HTML viewer (browser-based, zero dependencies)
  • C++ CLI tool (replaces Python scripts)
  • All Python dependencies removed
  • Unified container registration via SerializableContainer concept
  • NEW: Full constexpr support for fixed_string with compile-time string literals

Phase 5 Roadmap:

  • Cross-platform serialization (endianness handling)
  • Nested container support
  • Additional container types
  • Performance profiling tools
  • ROS 2 adapter (separate repository)

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for new features
  4. Ensure all tests pass (ctest)
  5. Submit a pull request

Development guidelines: See .github/copilot-instructions.md


License

Copyright (C) 2026 Matthias Haase mattihaae@proton.me

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

See LICENSE for full details.


Author

Matthias Haase
Email: mattihaase@proton.me
GitHub: https://github.com/mattih11


Acknowledgments

About

A realtime, high-performance, zero-allocation C++20 binary serialization library using compile-time reflection

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors