Files
nanopb/tests/test_encode1.c
Petteri Aimonen 7f53c3f748 Example
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@957 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-08-17 19:03:06 +00:00

22 lines
522 B
C

#include <stdio.h>
#include <pb_encode.h>
#include "person.h"
bool streamcallback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
FILE *file = (FILE*) stream->state;
return fwrite(buf, 1, count, file) == count;
}
int main()
{
Person person = {"Test Person 99", 99, true, "test@person.com",
1, {{"555-12345678", true, Person_PhoneType_MOBILE}}};
pb_ostream_t stream = {&streamcallback, stdout, SIZE_MAX, 0};
pb_encode(&stream, Person_fields, &person);
return 0;
}