1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <pb_encode.h>
5 #include <pb_decode.h>
6 #include "test.pb.h"
7 #include "unittests.h"
8 
main(int argc,char ** argv)9 int main(int argc, char **argv)
10 {
11     int status = 0;
12     uint8_t buffer[512] = {0};
13     int i;
14     pb_ostream_t ostream;
15 
16     Reply reply = Reply_init_zero;
17     Reply_Result request_result = Reply_Result_OK;
18 
19     ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
20     reply.result = request_result;
21     if (!pb_encode(&ostream, Reply_fields, &reply)) {
22         fprintf(stderr, "Encode failed: %s\n", PB_GET_ERROR(&ostream));
23         return 1;
24     }
25 
26     printf("response payload (%d):", (int)ostream.bytes_written);
27     for (i = 0; i < ostream.bytes_written; i++) {
28         printf("%02X", buffer[i]);
29     }
30     printf("\n");
31 
32     TEST(ostream.bytes_written == 2);
33     TEST(buffer[0] == 0x08);
34     TEST(buffer[1] == 0x01);
35 
36     return status;
37 }
38 
39