Handle unsupported extension field types more gracefully.
[apps/agl-service-can-low-level.git] / tests / test_encode1.c
1 /* A very simple encoding test case using person.proto.
2  * Just puts constant data in the fields and encodes into
3  * buffer, which is then written to stdout.
4  */
5
6 #include <stdio.h>
7 #include <pb_encode.h>
8 #include "person.pb.h"
9
10 int main()
11 {
12     /* Initialize the structure with constants */
13     Person person = {"Test Person 99", 99, true, "test@person.com",
14         3, {{"555-12345678", true, Person_PhoneType_MOBILE},
15             {"99-2342", false, 0},
16             {"1234-5678", true, Person_PhoneType_WORK},
17         }};
18
19     uint8_t buffer[512];
20     pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
21     
22     /* Now encode it and check if we succeeded. */
23     if (pb_encode(&stream, Person_fields, &person))
24     {
25         fwrite(buffer, 1, stream.bytes_written, stdout);
26         return 0; /* Success */
27     }
28     else
29     {
30         fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream));
31         return 1; /* Failure */
32     }
33 }