Encoder
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@951 e3a754e5-d11d-0410-8d38-ebb782a927b9
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
CFLAGS=-ansi -Wall -Werror -I .. -g -O0
|
||||
DEPS=../pb_decode.c ../pb_decode.h ../pb.h person.h
|
||||
TESTS=test_decode1 decode_unittests
|
||||
DEPS=../pb_decode.c ../pb_decode.h ../pb_encode.c ../pb_encode.h ../pb.h person.h
|
||||
TESTS=test_decode1 test_encode1 decode_unittests
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
clean:
|
||||
rm -f test_decode1
|
||||
rm -f $(TESTS)
|
||||
|
||||
%: %.c $(DEPS)
|
||||
$(CC) $(CFLAGS) -o $@ $< ../pb_decode.c
|
||||
$(CC) $(CFLAGS) -o $@ $< ../pb_decode.c ../pb_encode.c
|
||||
|
||||
run_unittests: decode_unittests
|
||||
./decode_unittests
|
||||
|
||||
@@ -4,7 +4,7 @@ message Person {
|
||||
required string name = 1 [(nanopb).max_size = 40];
|
||||
required int32 id = 2;
|
||||
optional string email = 3 [(nanopb).max_size = 40];
|
||||
optional bytes test = 5 [default = "abc\x00\x01\x02"];
|
||||
optional bytes test = 5 [default="\x00\x01\x02", (nanopb).max_size = 20];
|
||||
|
||||
enum PhoneType {
|
||||
MOBILE = 0;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <pb_decode.h>
|
||||
#include "person.h"
|
||||
|
||||
/* This test has only one source file anyway.. */
|
||||
#include "person.c"
|
||||
|
||||
bool print_person(pb_istream_t *stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
23
tests/test_encode1.c
Normal file
23
tests/test_encode1.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <pb_encode.h>
|
||||
#include "person.h"
|
||||
|
||||
/* This test has only one source file anyway.. */
|
||||
#include "person.c"
|
||||
|
||||
bool callback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
|
||||
{
|
||||
return fwrite(buf, 1, count, stdout) == count;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Person person = {"Test Person 99", 99, true, "test@person.com",
|
||||
1, {{"555-12345678", true, Person_PhoneType_MOBILE}}};
|
||||
|
||||
pb_ostream_t stream = {&callback, 0, SIZE_MAX, 0};
|
||||
|
||||
pb_encode(&stream, Person_fields, &person);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user