1 /* Same as test_encode1.c, except writes directly to stdout.
8 /* This binds the pb_ostream_t into the stdout stream */
9 bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
11 FILE *file = (FILE*) stream->state;
12 return fwrite(buf, 1, count, file) == count;
17 /* Initialize the structure with constants */
18 Person person = {"Test Person 99", 99, true, "test@person.com",
19 3, {{"555-12345678", true, Person_PhoneType_MOBILE},
20 {"99-2342", false, 0},
21 {"1234-5678", true, Person_PhoneType_WORK},
24 /* Prepare the stream, output goes directly to stdout */
25 pb_ostream_t stream = {&streamcallback, stdout, SIZE_MAX, 0};
27 /* Now encode it and check if we succeeded. */
28 if (pb_encode(&stream, Person_fields, &person))
29 return 0; /* Success */
31 return 1; /* Failure */