MOS Source Code
Loading...
Searching...
No Matches
padding.c
Go to the documentation of this file.
1#include <pb_encode.h>
2#include <unittests.h>
3#include <string.h>
4#include "padding.pb.h"
5
6int main()
7{
8 int status = 0;
9
10 TestMessage msg;
11
12 /* Set padding bytes to garbage */
13 memset(&msg, 0xAA, sizeof(msg));
14
15 /* Set all meaningful fields to 0 */
16 msg.submsg.boolfield = false;
17 msg.submsg.intfield = 0;
18
19 /* Test encoding */
20 {
21 pb_byte_t buf[128] = {0};
22 pb_ostream_t stream = pb_ostream_from_buffer(buf, sizeof(buf));
23 TEST(pb_encode(&stream, TestMessage_fields, &msg));
24
25 /* Because all fields have zero values, proto3 encoder
26 * shouldn't write out anything. */
27 TEST(stream.bytes_written == 0);
28 }
29
30 return status;
31}
32
int main()
Definition padding.c:6
uint_least8_t pb_byte_t
Definition pb.h:227
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
static void * memset(void *s, int c, size_t n)
Definition pb_syshdr.h:101
#define TEST(x)
Definition test.h:3