-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinarySerializer.h
73 lines (56 loc) · 1.68 KB
/
BinarySerializer.h
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
/*
* File: BinarySerializer.h
* Author: michal
*
* Created on March 1, 2016, 2:43 AM
*/
#ifndef BINARYSERIALIZER_H
#define BINARYSERIALIZER_H
#include "Serialize.h"
#include "BinaryFormat.h"
namespace Serialize
{
typedef ISerializable<BinaryFormat> IBinarySerializable;
typedef IDeserializable<BinaryFormat> IBinaryDeserializable;
typedef std::uint32_t BinaryLengthFormat;
template <class T>
using BinarySerializer = Serializer<BinaryFormat, T>;
template <class T>
using BinaryDeserializer = Deserializer<BinaryFormat, T>;
template <class T>
struct RawBinarySerializer
{
void serialize(IOutputStream &output, const T &data)
{
output.write(&data, sizeof(data));
}
};
template <class T>
struct RawBinaryDeserializer
{
void serialize(IOutputStream &output, const T &data)
{
output.write(&data, sizeof(data));
}
};
template <class T>
struct DefaultSerializer<BinaryFormat, T> : RawBinarySerializer<T>
{};
template <class T>
struct DefaultDeserializer<BinaryFormat, T> : RawBinaryDeserializer<T>
{};
template <class T>
struct is_raw_binary_serializable
{
static const bool value = std::is_base_of<RawBinarySerializer<T>, Serializer<BinaryFormat, T>>::value;
};
template <class T>
struct is_raw_binary_deserializable
{
static const bool value = std::is_base_of<RawBinaryDeserializer<T>, Deserializer<BinaryFormat, T>>::value;
};
}
#include "VectorBinarySerializer.h"
#include "ArrayBinarySerializer.h"
#include "StringBinarySerializer.h"
#endif /* BINARYSERIALIZER_H */