SkillAgentSearch skills...

CppSerialization

Performance comparison of the most popular C++ serialization protocols such as Cap'n'Proto, FastBinaryEncoding, Flatbuffers, Protobuf, JSON

Install / Use

/learn @chronoxor/CppSerialization
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

CppSerialization

License Release <br/> Linux (clang) Linux (gcc) MacOS <br/> Windows (Cygwin) Windows (MSYS2) Windows (MinGW) Windows (Visual Studio)

C++ Serialization Library provides functionality to serialize/deserialize objects using different protocols such as Cap'n'Proto, FastBinaryEncoding, Flatbuffers, Protobuf, SimpleBinaryEncoding, zpp::bits, JSON.

Performance comparison based on the Domain model with one account, one wallet and three orders total size of 128 bytes:

| Protocol | Message size | Serialization time | Deserialization time | | :--------------------------------------------------------------------------: | -----------: | -----------------: | -------------------: | | Cap'n'Proto | 208 bytes | 247 ns | 184 ns | | FastBinaryEncoding | 234 bytes | 77 ns | 84 ns | | FlatBuffers | 280 bytes | 272 ns | 81 ns | | Protobuf | 120 bytes | 322 ns | 351 ns | | SimpleBinaryEncoding | 138 bytes | 35 ns | 52 ns | | zpp::bits | 130 bytes | 34 ns | 37 ns | | JSON | 301 bytes | 696 ns | 291 ns |

CppSerialization API reference

Contents

Features

Requirements

Optional:

How to build?

Linux: install required packages

sudo apt-get install -y binutils-dev uuid-dev

Install gil (git links) tool

pip3 install gil

Setup repository

git clone https://github.com/chronoxor/CppSerialization.git
cd CppSerialization
gil update

Linux

cd build
./unix.sh

MacOS

cd build
./unix.sh

Windows (Cygwin)

cd build
unix.bat

Windows (MSYS2)

cd build
unix.bat

Windows (MinGW)

cd build
mingw.bat

Windows (Visual Studio)

cd build
vs.bat

Domain model

The first step you should perform to use CppSerialization library is to provide a domain model (aka business objects). Domain model is a set of structures or classes that related to each other and might be aggregated in some hierarchy.

There is an example domain model which describes Account-Balance-Orders relation of some abstract trading platform:

#include <string>
#include <vector>

namespace TradeProto {

enum class OrderSide : uint8_t
{
    BUY,
    SELL
};

enum class OrderType : uint8_t
{
    MARKET,
    LIMIT,
    STOP
};

struct Order
{
    int Id;
    char Symbol[10];
    OrderSide Side;
    OrderType Type;
    double Price;
    double Volume;

    Order() : Order(0, "<\?\?\?>", OrderSide::BUY, OrderType::MARKET, 0.0, 0.0) {}
    Order(int id, const std::string& symbol, OrderSide side, OrderType type, double price, double volume)
    {
        Id = id;
        std::memcpy(Symbol, symbol.c_str(), std::min(symbol.size() + 1, sizeof(Symbol)));
        Side = side;
        Type = type;
        Price = price;
        Volume = volume;
    }
};

struct Balance
{
    char Currency[10];
    double Amount;

    Balance() : Balance("<\?\?\?>", 0.0) {}
    Balance(const std::string& currency, double amount)
    {
        std::memcpy(Currency, currency.c_str(), std::min(currency.size() + 1, sizeof(Currency)));
        Amount = amount;
    }
};

struct Account
{
    int Id;
    std::string Name;
    Balance Wallet;
    std::vector<Order> Orders;

    Account() : Account(0, "<\?\?\?>", "<\?\?\?>", 0.0) {}
    Account(int id, const char* name, const char* currency, double amount) : Wallet(currency, amount)
    {
        Id = id;
        Name = name;
    }
};

} // namespace TradeProto

The next step you should provide serialization methods for the domain model.

Cap'n'Proto serialization

Cap'n'Proto serialization is based on Cap'n'Proto library.

Cap'n'Proto schema

Cap'n'Proto serialization starts with describing a model schema. For our domain model the schema will be the following:

# Unique file ID, generated by 'capnp id'
@0xd4b6e00623bed170;

using Cxx = import "/capnp/c++.capnp";
$Cxx.namespace("Trade::capnproto");

enum OrderSide
{
    buy @0;
    sell @1;
}

enum OrderType
{
    market @0;
    

Related Skills

View on GitHub
GitHub Stars161
CategoryDevelopment
Updated5d ago
Forks43

Languages

C++

Security Score

100/100

Audited on Mar 21, 2026

No findings