blob: 362c404a301d74dc3cb423d8d0690459d1b3072d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <pb_decode.h>
#include "person.h"
bool print_person(pb_istream_t *stream)
{
int i;
Person person;
if (!pb_decode(stream, Person_fields, &person))
return false;
printf("Person: name '%s' id '%d' email '%s'\n", person.name, person.id, person.email);
for (i = 0; i < person.phone_count; i++)
{
Person_PhoneNumber *phone = &person.phone[i];
printf("PhoneNumber: number '%s' type '%d'\n", phone->number, phone->type);
}
return true;
}
int main()
{
uint8_t buffer[512];
size_t size = fread(buffer, 1, 512, stdin);
pb_istream_t stream = pb_istream_from_buffer(buffer, size);
if (!print_person(&stream))
printf("Parsing failed.\n");
return 0;
}
|