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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include "optick.config.h"
#if USE_OPTICK
#include "optick_common.h"
#include "optick_serialization.h"
namespace Optick
{
string OutputDataStream::GetData()
{
flush();
return str();
}
OutputDataStream & OutputDataStream::Write(const char * buffer, size_t size)
{
write(buffer, size);
return *this;
}
OutputDataStream OutputDataStream::Empty;
OutputDataStream &operator << ( OutputDataStream &stream, const char* val )
{
uint32 length = val == nullptr ? 0 : (uint32)strlen(val);
stream << length;
if (length > 0)
{
stream.write( val, length );
}
return stream;
}
OutputDataStream &operator << ( OutputDataStream &stream, int val )
{
stream.write( (char*)&val, sizeof(int) );
return stream;
}
OutputDataStream &operator << ( OutputDataStream &stream, int64 val )
{
stream.write( (char*)&val, sizeof(int64) );
return stream;
}
OutputDataStream &operator << ( OutputDataStream &stream, char val )
{
stream.write( (char*)&val, sizeof(char) );
return stream;
}
OutputDataStream &operator << (OutputDataStream &stream, int8 val)
{
stream.write((char*)&val, sizeof(val));
return stream;
}
OutputDataStream &operator << ( OutputDataStream &stream, byte val )
{
stream.write( (char*)&val, sizeof(byte) );
return stream;
}
OutputDataStream & operator<<(OutputDataStream &stream, uint64 val)
{
stream.write( (char*)&val, sizeof(uint64) );
return stream;
}
OutputDataStream & operator<<(OutputDataStream &stream, uint32 val)
{
stream.write( (char*)&val, sizeof(uint32) );
return stream;
}
OutputDataStream & operator<<(OutputDataStream &stream, float val)
{
stream.write((char*)&val, sizeof(float));
return stream;
}
OutputDataStream & operator<<(OutputDataStream &stream, const string& val)
{
stream << (uint32)val.length();
if (!val.empty())
stream.write(&val[0], sizeof(val[0]) * val.length());
return stream;
}
OutputDataStream & operator<<(OutputDataStream &stream, const wstring& val)
{
size_t count = val.length() * sizeof(wchar_t);
stream << (uint32)count;
if (!val.empty())
stream.write((char*)(&val[0]), count);
return stream;
}
InputDataStream &operator >> (InputDataStream &stream, int16 &val)
{
stream.read((char*)&val, sizeof(int16));
return stream;
}
InputDataStream &operator >> ( InputDataStream &stream, int32 &val )
{
stream.read( (char*)&val, sizeof(int) );
return stream;
}
InputDataStream &operator >> ( InputDataStream &stream, int64 &val )
{
stream.read( (char*)&val, sizeof(int64) );
return stream;
}
InputDataStream & operator>>( InputDataStream &stream, byte &val )
{
stream.read( (char*)&val, sizeof(byte) );
return stream;
}
InputDataStream & operator >> (InputDataStream &stream, uint16 &val)
{
stream.read((char*)&val, sizeof(uint16));
return stream;
}
InputDataStream & operator>>( InputDataStream &stream, uint32 &val )
{
stream.read( (char*)&val, sizeof(uint32) );
return stream;
}
InputDataStream & operator>>( InputDataStream &stream, uint64 &val )
{
stream.read( (char*)&val, sizeof(uint64) );
return stream;
}
InputDataStream & operator >> ( InputDataStream &stream, string &val)
{
int32 length = 0;
stream >> length;
val.resize(length + 1);
stream.read( (char*)&val[0], length);
return stream;
}
InputDataStream::InputDataStream() :
stringstream( ios_base::in | ios_base::out )
{
}
void InputDataStream::Append(const char *buffer, size_t length)
{
write( buffer, length );
}
size_t InputDataStream::Length()
{
return (size_t)(tellp() - tellg());
}
bool InputDataStream::Skip(size_t length)
{
bool result = Length() <= length;
seekg(length, ios_base::cur);
return result;
}
}
#endif //USE_OPTICK
|