df1ec4fcccbf67dacb78999cc338dfd529baa9a9
[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.
3  */
4
5 #include <stdio.h>
6 #include <pb_encode.h>
7 #include "person.pb.h"
8
9 bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
10 {
11     FILE *file = (FILE*) stream->state;
12     return fwrite(buf, 1, count, file) == count;
13 }
14
15 int main()
16 {
17     Person person = {"Test Person 99", 99, true, "test@person.com",
18         1, {{"555-12345678", true, Person_PhoneType_MOBILE}}};
19     
20     pb_ostream_t stream = {&streamcallback, stdout, SIZE_MAX, 0};
21     
22     pb_encode(&stream, Person_fields, &person);
23     
24     return 0;
25 }