Skip to content

Commit 3b5fd4e

Browse files
committed
Add zpp_bits to the comparison table #4
1 parent 7a18748 commit 3b5fd4e

36 files changed

Lines changed: 240 additions & 49 deletions

.github/workflows/build-windows-vs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
- name: "Build"
2626
env:
27-
JAVA_HOME: $JAVA_HOME_21_X64
27+
JAVA_HOME: ${{ env.JAVA_HOME_21_X64 }}
2828
run: |
2929
cd build
3030
./vs.bat

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ file(GLOB_RECURSE LIB_INLINE_FILES "include/*.inl" "source/*.inl")
4747
file(GLOB_RECURSE LIB_SOURCE_FILES "include/*.cpp" "source/*.cpp")
4848
add_library(cppserialization ${LIB_HEADER_FILES} ${LIB_INLINE_FILES} ${LIB_SOURCE_FILES})
4949
set_target_properties(cppserialization PROPERTIES COMPILE_FLAGS "${PEDANTIC_COMPILE_FLAGS}" FOLDER "libraries")
50-
target_include_directories(cppserialization PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/proto" PUBLIC ${capnproto} PUBLIC ${flatbuf} PUBLIC ${protobuf} PUBLIC ${rapidjson})
50+
target_include_directories(cppserialization PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/proto" PUBLIC ${capnproto} PUBLIC ${flatbuf} PUBLIC ${protobuf} PUBLIC ${rapidjson} PUBLIC ${zpp_bits})
5151
target_link_libraries(cppserialization ${LINKLIBS})
5252
list(APPEND INSTALL_TARGETS cppserialization)
5353
list(APPEND LINKLIBS cppserialization)

examples/capnproto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(int argc, char** argv)
1818
account.Orders.emplace_back(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100);
1919
account.Orders.emplace_back(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10);
2020

21-
// Serialize the account to the Cap'n'Proto stream
21+
// Serialize the account to the Cap'n'Proto buffer
2222
capnp::MallocMessageBuilder output;
2323
Trade::capnproto::Account::Builder builder = output.initRoot<Trade::capnproto::Account>();
2424
account.Serialize(builder);
@@ -29,7 +29,7 @@ int main(int argc, char** argv)
2929
std::cout << "Original size: " << account.size() << std::endl;
3030
std::cout << "Cap'n'Proto size: " << buffer.getArray().size() << std::endl;
3131

32-
// Deserialize the account from the Cap'n'Proto stream
32+
// Deserialize the account from the Cap'n'Proto buffer
3333
kj::ArrayInputStream array(buffer.getArray());
3434
capnp::InputStreamMessageReader input(array);
3535
TradeProto::Account deserialized;

examples/fbe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(int argc, char** argv)
1818
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
1919
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
2020

21-
// Serialize the account to the FBE stream
21+
// Serialize the account to the FBE buffer
2222
FBE::trade::AccountModel writer;
2323
size_t model_begin = writer.create_begin();
2424
account.Serialize(writer.model);
@@ -29,7 +29,7 @@ int main(int argc, char** argv)
2929
std::cout << "Original size: " << account.size() << std::endl;
3030
std::cout << "FBE size: " << serialized << std::endl;
3131

32-
// Deserialize the account from the FBE stream
32+
// Deserialize the account from the FBE buffer
3333
TradeProto::Account deserialized;
3434
FBE::trade::AccountModel reader;
3535
reader.attach(writer.buffer());

examples/flatbuffers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ int main(int argc, char** argv)
1818
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
1919
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
2020

21-
// Serialize the account to the FlatBuffer stream
21+
// Serialize the account to the FlatBuffer buffer
2222
flatbuffers::FlatBufferBuilder builder;
2323
builder.Finish(account.Serialize(builder));
2424

2525
// Show original and FlatBuffer serialized sizes
2626
std::cout << "Original size: " << account.size() << std::endl;
2727
std::cout << "FlatBuffer size: " << builder.GetSize() << std::endl;
2828

29-
// Deserialize the account from the FlatBuffer stream
29+
// Deserialize the account from the FlatBuffer buffer
3030
TradeProto::Account deserialized;
3131
deserialized.Deserialize(*Trade::flatbuf::GetAccount(builder.GetBufferPointer()));
3232

examples/json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
2020
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
2121
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
2222

23-
// Serialize the account to the JSON stream
23+
// Serialize the account to the JSON buffer
2424
CppSerialization::JSON::StringBuffer buffer;
2525
CppSerialization::JSON::Serializer<CppSerialization::JSON::StringBuffer> serializer(buffer);
2626
account.Serialize(serializer);
@@ -33,7 +33,7 @@ int main(int argc, char** argv)
3333
// Parse JSON string
3434
CppSerialization::JSON::Document json = CppSerialization::JSON::Parser::Parse(buffer.GetString());
3535

36-
// Deserialize the account from the JSON stream
36+
// Deserialize the account from the JSON buffer
3737
TradeProto::Account deserialized;
3838
deserialized.Deserialize(json);
3939

examples/protobuf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(int argc, char** argv)
1818
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
1919
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
2020

21-
// Serialize the account to the Protobuf stream
21+
// Serialize the account to the Protobuf buffer
2222
Trade::protobuf::Account output;
2323
account.Serialize(output);
2424
auto buffer = output.SerializeAsString();
@@ -27,7 +27,7 @@ int main(int argc, char** argv)
2727
std::cout << "Original size: " << account.size() << std::endl;
2828
std::cout << "Protobuf size: " << buffer.size() << std::endl;
2929

30-
// Deserialize the account from the Protobuf stream
30+
// Deserialize the account from the Protobuf buffer
3131
Trade::protobuf::Account input;
3232
input.ParseFromString(buffer);
3333
TradeProto::Account deserialized;

examples/sbe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(int argc, char** argv)
1818
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
1919
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
2020

21-
// Serialize the account to the SBE stream
21+
// Serialize the account to the SBE buffer
2222
char buffer[1024];
2323
sbe::MessageHeader header;
2424
header.wrap(buffer, 0, 1, sizeof(buffer))
@@ -34,7 +34,7 @@ int main(int argc, char** argv)
3434
std::cout << "Original size: " << account.size() << std::endl;
3535
std::cout << "SBE size: " << header.encodedLength() + message.encodedLength() << std::endl;
3636

37-
// Deserialize the account from the SBE stream
37+
// Deserialize the account from the SBE buffer
3838
header.wrap(buffer, 0, 1, sizeof(buffer));
3939
int actingVersion = header.version();
4040
int actingBlockLength = header.blockLength();

examples/zpp_bits.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*!
2+
\file zpp_bits.cpp
3+
\brief zpp::bits serialization example
4+
\author Ivan Shynkarenka
5+
\date 16.07.2025
6+
\copyright MIT License
7+
*/
8+
9+
#include "../proto/trade.h"
10+
11+
#include <iostream>
12+
13+
int main(int argc, char** argv)
14+
{
15+
// Create a new account with some orders
16+
TradeProto::Account account(1, "Test", "USD", 1000);
17+
account.Orders.emplace_back(TradeProto::Order(1, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::MARKET, 1.23456, 1000));
18+
account.Orders.emplace_back(TradeProto::Order(2, "EURUSD", TradeProto::OrderSide::SELL, TradeProto::OrderType::LIMIT, 1.0, 100));
19+
account.Orders.emplace_back(TradeProto::Order(3, "EURUSD", TradeProto::OrderSide::BUY, TradeProto::OrderType::STOP, 1.5, 10));
20+
21+
// Serialize the account to the zpp::bits buffer
22+
auto [buffer, out] = zpp::bits::data_out();
23+
(void) out(account);
24+
25+
// Show original and zpp::bits serialized sizes
26+
std::cout << "Original size: " << account.size() << std::endl;
27+
std::cout << "zpp::bits size: " << buffer.size() << std::endl;
28+
29+
// Deserialize the account from the zpp::bits buffer
30+
TradeProto::Account deserialized;
31+
(void) zpp::bits::in{buffer}(deserialized);
32+
33+
// Show account content
34+
std::cout << std::endl;
35+
std::cout << "Account.Id = " << deserialized.Id << std::endl;
36+
std::cout << "Account.Name = " << deserialized.Name << std::endl;
37+
std::cout << "Account.Wallet.Currency = " << deserialized.Wallet.Currency << std::endl;
38+
std::cout << "Account.Wallet.Amount = " << deserialized.Wallet.Amount << std::endl;
39+
for (const auto& order : deserialized.Orders)
40+
{
41+
std::cout << "Account.Order => Id: " << order.Id
42+
<< ", Symbol: " << order.Symbol
43+
<< ", Side: " << (int)order.Side
44+
<< ", Type: " << (int)order.Type
45+
<< ", Price: " << order.Price
46+
<< ", Volume: " << order.Volume
47+
<< std::endl;
48+
}
49+
50+
return 0;
51+
}

modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ include("CppCommon.cmake")
55
include("flatbuffers.cmake")
66
include("protobuf.cmake")
77
include("rapidjson.cmake")
8+
include("zpp_bits.cmake")

0 commit comments

Comments
 (0)