OleksandrKvl / sbepp

C++ implementation of the FIX Simple Binary Encoding

Home Page:https://oleksandrkvl.github.io/sbepp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbepp

sbepp is a zero-overhead C++ implementation of Simple Binary Encoding (SBE). It consists of two parts:

  • sbeppc, schema compiler which generates header-only C++ code
  • sbepp, header-only supporting library

This project was created in Ukraine during the invasion of Russian terrorist forces. Please consider donating to the UNITED24 platform to help us withstand.

Features

  • fast, generates the same assembly as a hand-written code
  • generated code needs only C++11 and has no dependencies beyond sbepp itself
  • random access API to access fields in any order
  • cursor-based API for efficient work with complex messages in a forward-only way
  • lightweight, never allocates, most objects store only a single pointer
  • convenient, STL-like interface
  • supports constexpr encoding/decoding in C++20
  • never changes schema names, no get_FieldName()-like functions
  • provides all XML schema information via traits

Examples

Decoding example:

#include <schema_name/messages/msg1.hpp>

auto m = sbepp::make_view<schema_name::messages:msg1>(dataPtr, dataSize);
// read top-level fields
std::cout << *m.required();

if(m.optional())
{
    std::cout << *m.field2();
}

if(m.bitset().A())
{
    std::cout << "bitset.A";
}

// read composite field
std::cout << *m.composite().field();

// read group
for(auto entry : m.group())
{
    std::cout << sbepp::to_underlying(entry.enum_field());
}

// read data
auto d = m.data();
std::cout.write(d.data(), d.size());

Encoding example:

#include <schema_name/messages/msg1.hpp>

std::array<char, 1024> buf{};
auto m = sbepp::make_view<schema_name::messages:msg1>(buf.data(), buf.size());
sbepp::fill_message_header(m);
// fill top-level fields
m.required(1);
m.optional(2);
m.bitset(schema_name::types::set{}.A(true));

// fill composite field
m.composite().field(1);

// fill group
auto g = m.group();
const auto group_size = 3;
sbepp::fill_group_header(g, group_size);
for(auto entry : g)
{
    g.enum_field(schema_name::types::my_enum::A);
}

// fill data
auto d = m.data();
d.assign_string("hi");

const auto msg_size = sbepp::size_bytes(m); // get final message size
send(buf.data(), mgs_size);

Documentation

See full documentation here.

Feedback

Feel free to create an issue, send me an email, or contact me on Cpplang slack channel if you have questions or ideas related to this project.

License

Distributed under the MIT license.

About

C++ implementation of the FIX Simple Binary Encoding

https://oleksandrkvl.github.io/sbepp/

License:MIT License


Languages

Language:C++ 98.3%Language:CMake 1.7%