Documenting and improving stream behaviour
[apps/low-level-can-service.git] / tests / test_encode1.c
1 #include <stdio.h>
2 #include <pb_encode.h>
3 #include "person.h"
4
5 /* This test has only one source file anyway.. */
6 #include "person.c"
7
8 bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
9 {
10     FILE *file = (FILE*) stream->state;
11     return fwrite(buf, 1, count, file) == count;
12 }
13
14 int main()
15 {
16     Person person = {"Test Person 99", 99, true, "test@person.com",
17         1, {{"555-12345678", true, Person_PhoneType_MOBILE}}};
18     
19     pb_ostream_t stream = {&streamcallback, stdout, SIZE_MAX, 0};
20     
21     pb_encode(&stream, Person_fields, &person);
22     
23     return 0;
24 }