MOS Source Code
Loading...
Searching...
No Matches
test.c
Go to the documentation of this file.
1#include <pb_decode.h>
2#include <stdio.h>
3#include <string.h>
4#include <assert.h>
5#include "test_helpers.h"
6#include "test.pb.h"
7
8bool stream_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
9{
10 FILE *file = (FILE*)stream->state;
11 size_t len = fread(buf, 1, count, file);
12
13 if (len == count)
14 {
15 return true;
16 }
17 else
18 {
19 stream->bytes_left = 0;
20 return false;
21 }
22}
23
24int main()
25{
26 pb_istream_t stream = {&stream_callback, NULL, SIZE_MAX};
27 MyMessage msg = MyMessage_init_default;
28 bool status;
29 stream.state = stdin;
31
33
34 status = pb_decode(&stream, MyMessage_fields, &msg);
35 assert(!status);
36 assert(strcmp(stream.errmsg, "realloc failed") == 0);
37 return 0;
38}
39
bool stream_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
Definition test.c:8
int main()
Definition test.c:24
MOSAPI s32 strcmp(const char *str1, const char *str2)
Definition mos_string.c:24
size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream)
struct _FILE FILE
Definition mos_stdio.h:24
#define stdin
Definition mos_stdio.h:30
void set_max_alloc_bytes(size_t max_bytes)
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
#define NULL
Definition pb_syshdr.h:46
unsigned char uint8_t
Definition pb_syshdr.h:20
#define SET_BINARY_MODE(file)