-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataPacketHandler.cpp
53 lines (48 loc) · 1.17 KB
/
DataPacketHandler.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
//disable warning compiler
#pragma warning(disable : 4996)
#include "DataPacketHandler.h"
extern const char* PATH;
void DataPacketHandler::MainProcess() {
Deserialize();
Trace();
}
void DataPacketHandler::Deserialize() {
FILE* file = fopen(PATH, "rb");
if (!file) {
printf("Deserialize. Error! Can't open file!\n");
return;
}
while (!feof(file)) {
DataPacket data_packet;
memset(&data_packet, 0, sizeof(DataPacketHead));
if (!fread(&data_packet, sizeof(DataPacketHead), 1, file)) {
break;
}
if (data_packet.start_marker != DataPackeHeadConst::START_MARKER) {
break;
}
if (data_packet.size < 1) {
break;
}
data_packet.data.resize(data_packet.size);
if (!fread(&data_packet.data[0], data_packet.size, 1, file)) {
break;
}
buffer.push_back(data_packet);
}
fclose(file);
}
void DataPacketHandler::Trace() {
printf("Handle DataPacket:\n");
for (DataPacket& data_packet : buffer) {
unsigned char* head = (unsigned char*)&data_packet;
for (unsigned int i = 0; i < sizeof(DataPacketHead); i++) {
printf("%02x ", head[i]);
}
for (unsigned char data : data_packet.data) {
printf("%02x ", data);
}
printf("\n");
}
printf("\n");
}