5 bool print_person(pb_istream_t *stream)
10 if (!pb_decode(stream, Person_fields, &person))
13 printf("name: \"%s\"\n", person.name);
14 printf("id: %d\n", person.id);
17 printf("email: \"%s\"\n", person.email);
19 for (i = 0; i < person.phone_count; i++)
21 Person_PhoneNumber *phone = &person.phone[i];
23 printf(" number: \"%s\"\n", phone->number);
27 case Person_PhoneType_WORK:
28 printf(" type: WORK\n");
31 case Person_PhoneType_HOME:
32 printf(" type: HOME\n");
35 case Person_PhoneType_MOBILE:
36 printf(" type: MOBILE\n");
45 bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
47 FILE *file = (FILE*)stream->state;
52 while (count-- && fgetc(file) != EOF);
56 status = (fread(buf, 1, count, file) == count);
59 stream->bytes_left = 0;
66 pb_istream_t stream = {&callback, stdin, SIZE_MAX};
67 if (!print_person(&stream))
68 printf("Parsing failed.\n");