1 /* A very simple decoding test case, using person.proto.
2 * Produces output compatible with protoc --decode.
9 bool print_person(pb_istream_t *stream)
14 if (!pb_decode(stream, Person_fields, &person))
17 printf("name: \"%s\"\n", person.name);
18 printf("id: %d\n", person.id);
21 printf("email: \"%s\"\n", person.email);
23 for (i = 0; i < person.phone_count; i++)
25 Person_PhoneNumber *phone = &person.phone[i];
27 printf(" number: \"%s\"\n", phone->number);
31 case Person_PhoneType_WORK:
32 printf(" type: WORK\n");
35 case Person_PhoneType_HOME:
36 printf(" type: HOME\n");
39 case Person_PhoneType_MOBILE:
40 printf(" type: MOBILE\n");
49 bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
51 FILE *file = (FILE*)stream->state;
56 while (count-- && fgetc(file) != EOF);
60 status = (fread(buf, 1, count, file) == count);
63 stream->bytes_left = 0;
70 /* Maximum size is specified to prevent infinite length messages from
71 * hanging this in the fuzz test.
73 pb_istream_t stream = {&callback, stdin, 10000};
74 if (!print_person(&stream))
75 printf("Parsing failed.\n");