Files
nanopb/tests/test_encode1.c
Petteri Aimonen d4abb63c05 Tests for callback fields
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@974 e3a754e5-d11d-0410-8d38-ebb782a927b9
2011-09-12 18:53:33 +00:00

26 lines
628 B
C

/* A very simple encoding test case using person.proto.
* Just puts constant data in the fields.
*/
#include <stdio.h>
#include <pb_encode.h>
#include "person.pb.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;
}