6#include "msgid_example.pb.h"
14 if (!
pb_read(stream, &prefix, 1))
25 MyMessage1 msg = MyMessage1_init_default;
27 if (!
pb_decode(stream, MyMessage1_fields, &msg))
30 printf(
"Got MyMessage1: intvalue = %d\n", (
int)msg.intvalue);
36 MyMessage2 msg = MyMessage2_init_default;
38 if (!
pb_decode(stream, MyMessage2_fields, &msg))
41 printf(
"Got MyMessage2: intvalue = %d, strvalue = %s\n",
42 (
int)msg.intvalue, msg.strvalue);
48 MyMessage3 msg = MyMessage3_init_default;
50 if (!
pb_decode(stream, MyMessage3_fields, &msg))
53 printf(
"Got MyMessage3: boolvalue = %d\n", (
int)msg.boolvalue);
71 printf(
"Message does not fit in buffer\n");
79 printf(
"Failed to read prefix: %s\n",
PB_GET_ERROR(&stream));
91 #define PB_MSG(id,len,name) case id: status = handle_ ## name(&stream); break;
92 MSGID_EXAMPLE_MESSAGES
95 default: printf(
"Unknown prefix: %d\n", prefix);
return 1;
bool read_prefix(pb_istream_t *stream, int *msgid)
bool handle_MyMessage1(pb_istream_t *stream)
bool handle_MyMessage3(pb_istream_t *stream)
bool handle_MyMessage2(pb_istream_t *stream)
size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream)
#define PB_GET_ERROR(stream)
bool pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count)
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
#define SET_BINARY_MODE(file)