Skip to content

Instantly share code, notes, and snippets.

# 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
#include <iostream>
#include <array>
typedef enum
{
#define OPERATOR(NAME,...) NAME,
#include "operators.def"
} operator_t;
typedef enum
// OPERATOR(NAME, ARITY, OPERAND_TYPES)
#ifndef OPTION
#define OPTION(...)
#endif
#ifndef OPERATOR
#define OPERATOR(...)
#endif
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; }
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);
}
namespace detail {
template <class T>
struct deserialize_helper;
template <class T>
struct deserialize_helper {
/**
* Deserialization for integral types and POD data types.
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>(
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;
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>) {
#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));