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
| 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
| 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
| 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
| 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
| // 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
| #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
| # 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
| %code requires | |
| { | |
| #include <string> | |
| } | |
| %{ | |
| #include <iostream> | |
| void yyerror(const char *s) | |
| { |
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
| cmake_minimum_required (VERSION 2.8) | |
| project (blog) | |
| # CHECKs if a C++11 compiler is available | |
| if(CMAKE_COMPILER_IS_GNUCXX) | |
| execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) | |
| if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7) | |
| message(STATUS "C++11 activated.") | |
| add_definitions("-std=c++11") | |
| else () |