a3500d7d68b2b4bd24962b92f552e33fc04def05
[apps/agl-service-can-low-level.git] / tests / test_encode_extensions.c
1 /* Tests extension fields.
2  */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <pb_encode.h>
8 #include "alltypes.pb.h"
9 #include "extensions.pb.h"
10
11 int main(int argc, char **argv)
12 {
13     AllTypes alltypes = {0};
14     int32_t extensionfield1 = 12345;
15     pb_extension_t ext1 = {&AllTypes_extensionfield1, &extensionfield1, NULL};
16     
17     alltypes.extensions = &ext1;
18     
19     uint8_t buffer[1024];
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, AllTypes_fields, &alltypes))
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 }
34