-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBinarySerializer.h
More file actions
44 lines (36 loc) · 938 Bytes
/
StringBinarySerializer.h
File metadata and controls
44 lines (36 loc) · 938 Bytes
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
/*
* File: StringBinarySerializer.h
* Author: michal
*
* Created on March 1, 2016, 3:45 AM
*/
#ifndef STRINGBINARYSERIALIZER_H
#define STRINGBINARYSERIALIZER_H
#include <string>
namespace Serialize
{
struct StringSerializer
{
void serialize(IOutputStream &os, const std::string &s)
{
BinaryLengthFormat l = s.length();
os.write(&l, sizeof(l));
os.write(s.data(), l);
}
};
struct StringDeserializer
{
void serialize(IInputStream &os, std::string &s)
{
BinaryLengthFormat l;
os.read(&l, sizeof(l));
s.resize(l);
os.read(&s[0], l);
}
};
template <>
struct Serializer<BinaryFormat, std::string> : StringSerializer {};
template <>
struct Deserializer<BinaryFormat, std::string> : StringDeserializer {};
}
#endif /* STRINGBINARYSERIALIZER_H */