18 if (istream && field->tag == SubMsg3_strvalue_tag)
26 int strlen = istream->bytes_left;
36 printf(
" strvalue: \"%s\"\n",
buffer);
51 printf((
char*)*arg, (
int)value);
58 int strlen = stream->bytes_left;
71 printf((
char*)*arg,
buffer);
87 OneOfMessage *topmsg = field->message;
88 printf(
"prefix: %d\n", (
int)topmsg->prefix);
90 if (field->tag == OneOfMessage_submsg1_tag)
92 SubMsg1 *msg = field->pData;
93 printf(
"submsg1 {\n");
95 msg->array.arg =
" array: %d\n";
97 else if (field->tag == OneOfMessage_submsg2_tag)
99 SubMsg2 *msg = field->pData;
100 printf(
"submsg2 {\n");
102 msg->strvalue.arg =
" strvalue: \"%s\"\n";
104 else if (field->tag == OneOfMessage_submsg3_tag)
110 printf(
"submsg3 {\n");
124 OneOfMessage msg = OneOfMessage_init_zero;
133 fprintf(
stderr,
"Message does not fit in buffer\n");
141 if (!
pb_decode(&stream, OneOfMessage_fields, &msg))
148 if (msg.which_values == OneOfMessage_intvalue_tag)
150 printf(
"prefix: %d\n", (
int)msg.prefix);
151 printf(
"intvalue: %d\n", (
int)msg.values.intvalue);
153 else if (msg.which_values == OneOfMessage_strvalue_tag)
155 printf(
"prefix: %d\n", (
int)msg.prefix);
156 printf(
"strvalue: \"%s\"\n", msg.values.strvalue);
158 else if (msg.which_values == OneOfMessage_submsg3_tag &&
159 msg.values.submsg3.which_values == SubMsg3_intvalue_tag)
161 printf(
" intvalue: %d\n", (
int)msg.values.submsg3.values.intvalue);
168 printf(
"suffix: %d\n", (
int)msg.suffix);
170 assert(msg.prefix == 123);
171 assert(msg.suffix == 321);
size_t fread(void *__restrict ptr, size_t size, size_t nmemb, FILE *__restrict stream)
bool print_string(pb_istream_t *stream, const pb_field_t *field, void **arg)
bool msg_callback(pb_istream_t *stream, const pb_field_t *field, void **arg)
bool SubMsg3_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field)
bool print_int32(pb_istream_t *stream, const pb_field_t *field, void **arg)
#define PB_GET_ERROR(stream)
pb_field_iter_t pb_field_t
bool pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count)
bool pb_decode_varint(pb_istream_t *stream, uint64_t *dest)
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)
static size_t strlen(const char *s)
unsigned long long uint64_t
#define SET_BINARY_MODE(file)