-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (63 loc) · 1.2 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* File: main.cpp
* Author: michal
*
* Created on February 20, 2016, 10:47 PM
*/
#include <iostream>
#include <cstdint>
#include <stdio.h>
#include <tuple>
#include "Serialize.h"
#include "BinarySerializer.h"
using namespace std;
struct HexStream : Serialize::IOutputStream
{
void write(const void *data, size_t len) override
{
for (size_t i = 0; i < len; i++)
{
printf("%02x", ((uint8_t*)data)[i]);
}
printf(" ");
}
};
struct A : Serialize::IBinarySerializable
{
A(int x) : x(x) {}
virtual void serialize(Serialize::IOutputStream &out) const
{
binary(out) << x;
}
int x;
};
struct X : Serialize::IBinarySerializable
{
virtual void serialize(Serialize::IOutputStream &out) const
{
std::vector<int> x = { 1, 2, 3 };
binary(out) << x;
}
};
struct S
{
int x, y, z;
string s;
};
SERIALIZE_MEMBERS(Serialize::BinaryFormat, S, x, y, z, s);
struct SS
{
int a, b, c;
S s;
};
SERIALIZE_MEMBERS(Serialize::BinaryFormat, SS, a, b, c, s);
/*
*
*/
int main(int argc, char** argv)
{
HexStream hs;
SS s = { 101, 102, 103, { 1, 2, 3, "ala ma kota" } };
binary(hs) << s;
return 0;
}