-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathtestmsg.cpp
More file actions
55 lines (54 loc) · 1.42 KB
/
testmsg.cpp
File metadata and controls
55 lines (54 loc) · 1.42 KB
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
#include "testmsg.h"
#include "ByteBuffer.h"
bool testmsg::read(ByteBuffer * buffer)
{
if(sizeof(id) + buffer->rpos() > buffer->wpos()) return false;
*buffer >> id;
if(play.read(buffer) == false) return false;
int len_array;
if(sizeof(len_array) + buffer->rpos() > buffer->wpos()) return false;
*buffer >> len_array;
for( int i = 0; i< len_array; ++i) {
int32 temp_array;
if(sizeof(temp_array) + buffer->rpos() > buffer->wpos()) return false;
*buffer >> temp_array;
array.push_back(temp_array);
}
int len_attrs;
if(sizeof(len_attrs) + buffer->rpos() > buffer->wpos()) return false;
*buffer >> len_attrs;
for( int i = 0; i< len_attrs; ++i) {
Attr temp_attrs;
if(temp_attrs.read(buffer) == false) return false;
attrs.push_back(temp_attrs);
}
int len_vstr;
if(sizeof(len_vstr) + buffer->rpos() > buffer->wpos()) return false;
*buffer >> len_vstr;
for( int i = 0; i< len_vstr; ++i) {
std::string temp_vstr;
*buffer >> temp_vstr;
vstr.push_back(temp_vstr);
}
return true;
}
void testmsg::write(ByteBuffer * buffer)
{
*buffer << id;
play.write(buffer);
int len_array = array.size();
*buffer << len_array;
for( int i = 0; i< len_array; ++i) {
*buffer << array[i];
}
int len_attrs = attrs.size();
*buffer << len_attrs;
for( int i = 0; i< len_attrs; ++i) {
attrs[i].write(buffer);
}
int len_vstr = vstr.size();
*buffer << len_vstr;
for( int i = 0; i< len_vstr; ++i) {
*buffer << vstr[i];
}
}