-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunpackd.c
More file actions
114 lines (70 loc) · 2.07 KB
/
unpackd.c
File metadata and controls
114 lines (70 loc) · 2.07 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
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
#include <stdio.h>
#include "dmessage.pb-c.h"
#define MAX_MSG_SIZE 4096
int main (int argc, const char * argv[])
{
DMessage *msg;
ReqGetSlotInfo *sub1;
ReqGetSlotList *sub2;
char c; int i=0; // Data holders
uint8_t buf[MAX_MSG_SIZE]; // Input data container for bytes
unsigned len;
fread (&len, sizeof(len), 1, stdin);
printf("len %d\n", len);
while (fread(&c,1,1,stdin) != 0)
{
if (i >= MAX_MSG_SIZE)
{
fprintf(stderr,"message too long for allocated buffer\n");
return 1;
}
buf[i++] = c;
if ( i == len)
break;
}
msg = dmessage__unpack(NULL,i,buf); // Deserialize the serialized input
if (msg == NULL)
{ // Something failed
fprintf(stderr,"error unpacking incoming message\n");
return 1;
}
sub1 = msg->getslotinfo;
sub2 = msg->getslotlist;
uint64_t code = msg->code;
printf("Received: code=%lu\n",msg->code);
if (msg->getslotinfo != NULL) printf("getslotinfo slotID=%d",sub1->slotid);
printf("\n");
if (msg->getslotlist != NULL) printf("getslotlist tokenPresent=%d ulCount=%d",sub2->tokenpresent, sub2->ulcount);
printf("\n");
dmessage__free_unpacked(msg,NULL);
fread (&len, sizeof(len), 1, stdin);
printf("len %d\n", len);
i = 0;
while (fread(&c,1,1,stdin) != 0)
{
if (i >= MAX_MSG_SIZE)
{
fprintf(stderr,"message too long for allocated buffer\n");
return 1;
}
buf[i++] = c;
if ( i == len)
break;
}
msg = dmessage__unpack(NULL,i,buf); // Deserialize the serialized input
if (msg == NULL)
{ // Something failed
fprintf(stderr,"error unpacking incoming message\n");
return 1;
}
sub1 = msg->getslotinfo;
sub2 = msg->getslotlist;
code = msg->code;
printf("Received: code=%lu\n",msg->code);
if (msg->getslotinfo != NULL) printf("getslotinfo slotID=%d",sub1->slotid);
printf("\n");
if (msg->getslotlist != NULL) printf("getslotlist tokenPresent=%d ulCount=%d",sub2->tokenpresent, sub2->ulcount);
printf("\n");
dmessage__free_unpacked(msg,NULL);
return 0;
}