MOS Source Code
Loading...
Searching...
No Matches
multiple_oneof.c
Go to the documentation of this file.
1#include "multiple_oneof.pb.h"
2#include <unittests.h>
3#include <pb_encode.h>
4#include <pb_decode.h>
5
6int main()
7{
8 int status = 0;
9 uint8_t buf[128];
10 size_t msglen;
11
12 {
13 pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
14 MainMessage msg = MainMessage_init_zero;
15 msg.which_oneof1 = MainMessage_oneof1_uint32_tag;
16 msg.oneof1.oneof1_uint32 = 1234;
17 msg.which_oneof2 = MainMessage_oneof2_uint32_tag;
18 msg.oneof2.oneof2_uint32 = 5678;
19 TEST(pb_encode(&stream, MainMessage_fields, &msg));
20 msglen = stream.bytes_written;
21 }
22
23 {
24 pb_istream_t stream = pb_istream_from_buffer(buf, msglen);
25 MainMessage msg = MainMessage_init_zero;
26 TEST(pb_decode(&stream, MainMessage_fields, &msg));
27 TEST(msg.which_oneof1 == MainMessage_oneof1_uint32_tag);
28 TEST(msg.oneof1.oneof1_uint32 == 1234);
29 TEST(msg.which_oneof2 == MainMessage_oneof2_uint32_tag);
30 TEST(msg.oneof2.oneof2_uint32 == 5678);
31 }
32
33 return status;
34}
35
int main()
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
Definition pb_decode.c:143
pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
Definition pb_encode.c:63
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
Definition pb_encode.c:512
unsigned char uint8_t
Definition pb_syshdr.h:20
#define TEST(x)
Definition test.h:3