1 /* Tests extension fields.
8 #include "alltypes.pb.h"
9 #include "extensions.pb.h"
11 int main(int argc, char **argv)
13 AllTypes alltypes = {0};
14 int32_t extensionfield1 = 12345;
15 pb_extension_t ext1 = {&AllTypes_extensionfield1, &extensionfield1, NULL};
17 alltypes.extensions = &ext1;
20 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
22 /* Now encode it and check if we succeeded. */
23 if (pb_encode(&stream, AllTypes_fields, &alltypes))
25 fwrite(buffer, 1, stream.bytes_written, stdout);
26 return 0; /* Success */
30 fprintf(stderr, "Encoding failed: %s\n", PB_GET_ERROR(&stream));
31 return 1; /* Failure */