• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unittests.h>
2 #include <pb_encode.h>
3 #include <pb_decode.h>
4 #include "submsg_array.pb.h"
5 
main()6 int main()
7 {
8     int status = 0;
9 
10     COMMENT("Test encoding for submessage with array");
11     {
12         uint8_t buffer[TestMessage_size] = {0};
13         pb_ostream_t ostream = pb_ostream_from_buffer(buffer, TestMessage_size);
14         TestMessage msg = TestMessage_init_zero;
15 
16         msg.submsg.rep_uint32_count = 3;
17         msg.submsg.rep_uint32[0] = 0;
18         msg.submsg.rep_uint32[1] = 1;
19         msg.submsg.rep_uint32[2] = 2;
20 
21         TEST(pb_encode(&ostream, TestMessage_fields, &msg));
22         TEST(ostream.bytes_written > 0);
23 
24         {
25             pb_istream_t istream = pb_istream_from_buffer(buffer, ostream.bytes_written);
26             TestMessage msg2 = TestMessage_init_zero;
27 
28             TEST(pb_decode(&istream, TestMessage_fields, &msg2));
29             TEST(msg2.submsg.rep_uint32_count == 3);
30             TEST(msg2.submsg.rep_uint32[0] == 0);
31             TEST(msg2.submsg.rep_uint32[1] == 1);
32             TEST(msg2.submsg.rep_uint32[2] == 2);
33         }
34     }
35 
36     return status;
37 }
38 
39