-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackd.c
More file actions
50 lines (34 loc) · 1.51 KB
/
packd.c
File metadata and controls
50 lines (34 loc) · 1.51 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
#include <stdio.h>
#include <stdlib.h>
#include "dmessage.pb-c.h"
int main (int argc, const char * argv[])
{
DMessage msg = DMESSAGE__INIT;
ReqGetSlotInfo sub1 = REQ_GET_SLOT_INFO__INIT;
ReqGetSlotList sub2 = REQ_GET_SLOT_LIST__INIT;
void *buf;
unsigned len;
sub1.slotid = 12;
msg.getslotinfo = &sub1;
msg.code = 5;
len = dmessage__get_packed_size (&msg); // This is the calculated packing length
buf = malloc (len); // Allocate memory
dmessage__pack (&msg, buf); // Pack msg, including submessages
fprintf(stderr,"Writing %d serialized bytes\n",len); // See the length of message
fwrite (&len, sizeof(len), 1, stdout); // Write to stdout to allow direct command line piping
fwrite (buf, len, 1, stdout); // Write to stdout to allow direct command line piping
free(buf); // Free the allocated serialized buffer
dmessage__init(&msg);
sub2.tokenpresent = 1;
sub2.ulcount = 10;
msg.getslotlist = &sub2;
msg.code = 4;
len = dmessage__get_packed_size (&msg); // This is the calculated packing length
buf = malloc (len); // Allocate memory
dmessage__pack (&msg, buf); // Pack msg, including submessages
fprintf(stderr,"Writing %d serialized bytes\n",len); // See the length of message
fwrite (&len, sizeof(len), 1, stdout);
fwrite (buf, len, 1, stdout); // Write to stdout to allow direct command line piping
free(buf); // Free the allocated serialized buffer
return 0;
}