5 /* This test has only one source file anyway.. */
8 bool print_person(pb_istream_t *stream)
13 if (!pb_decode(stream, Person_fields, &person))
16 printf("Person: name '%s' id '%d' email '%s'\n", person.name, person.id, person.email);
18 for (i = 0; i < person.phone_count; i++)
20 Person_PhoneNumber *phone = &person.phone[i];
21 printf("PhoneNumber: number '%s' type '%d'\n", phone->number, phone->type);
27 bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
29 FILE *file = (FILE*)stream->state;
34 while (count-- && fgetc(file) != EOF);
38 status = (fread(buf, 1, count, file) == count);
41 stream->bytes_left = 0;
48 pb_istream_t stream = {&callback, stdin, SIZE_MAX};
49 if (!print_person(&stream))
50 printf("Parsing failed.\n");