This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1 "main.c" | |
| # 1 "<command-line>" | |
| # 1 "/usr/include/stdc-predef.h" 1 3 4 | |
| # 1 "<command-line>" 2 | |
| # 1 "main.c" | |
| typedef enum | |
| { | |
| # 1 "operators.def" 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <array> | |
| typedef enum | |
| { | |
| #define OPERATOR(NAME,...) NAME, | |
| #include "operators.def" | |
| } operator_t; | |
| typedef enum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // OPERATOR(NAME, ARITY, OPERAND_TYPES) | |
| #ifndef OPTION | |
| #define OPTION(...) | |
| #endif | |
| #ifndef OPERATOR | |
| #define OPERATOR(...) | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TEST(Performance, Water) { | |
| auto t1 = std::tuple<int,uint64_t,std::vector<uint8_t>,std::string>( | |
| 10, 20, std::vector<uint8_t>{0,1,2,3,4,5,6,7,8,9},"hello cpp-love!"); | |
| auto start = std::chrono::high_resolution_clock::now(); | |
| for (size_t i=0; i<500000; ++i) { | |
| StreamType res; | |
| serialize(t1,res); | |
| auto t2 = deserialize<decltype(t1)>(res); | |
| if (t1!=t2) { std::cerr << "BIG PROBLEMS!!!.. call MUM!" << std::endl; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TEST(Deserialize, Ints) { | |
| int v1 = deserialize<uint32_t>({0xA, 0, 0, 0}); | |
| EXPECT_EQ(v1, 10); | |
| auto v2 = deserialize<uint64_t>({0x40, 0, 0, 0, 0, 0, 0, 0}); | |
| EXPECT_EQ(v2, 64u); | |
| auto v3 = deserialize<int>({0xFF, 0xFF, 0xFF, 0xFF}); | |
| EXPECT_EQ(v3, -1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace detail { | |
| template <class T> | |
| struct deserialize_helper; | |
| template <class T> | |
| struct deserialize_helper { | |
| /** | |
| * Deserialization for integral types and POD data types. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| std::tuple<int,int,std::vector<uint8_t>> t(10, 20, {0,1,2,3,4,5,6,7,8,9}); | |
| TEST(Performance, Water) { | |
| auto start = std::chrono::high_resolution_clock::now(); | |
| for (size_t i=0; i<500000; ++i) { | |
| StreamType res; | |
| serialize(t,res); | |
| } | |
| auto tot_time = std::chrono::duration_cast<std::chrono::microseconds>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TEST(Serialize, Ints) { | |
| uint32_t v1 = 10; | |
| StreamType res; | |
| serialize(v1,res); | |
| EXPECT_EQ(sizeof(uint32_t), res.size()); | |
| EXPECT_EQ(res, std::vector<uint8_t>({0xA, 0, 0, 0})); | |
| res.clear(); | |
| uint64_t v2 = 64; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace detail { | |
| template <class T> | |
| class serialize_helper; | |
| template <class T> | |
| void serializer(const T& obj, StreamType::iterator&); | |
| template <class tuple_type> | |
| inline void serialize_tuple(const tuple_type& obj, StreamType::iterator& res, int_<0>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <gtest/gtest.h> | |
| #include "utils/serialize.h" | |
| TEST(get_size, Ints) { | |
| uint16_t v1 = 2u; | |
| EXPECT_EQ(sizeof(decltype(v1)), get_size(v1)); | |
| EXPECT_EQ(2u, get_size(v1)); | |
| uint32_t v2 = 10u; | |
| EXPECT_EQ(sizeof(decltype(v2)), get_size(v2)); |