diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/TODO b/TODO new file mode 100644 index 0000000..bb89652 --- /dev/null +++ b/TODO @@ -0,0 +1,14 @@ +- check over documentation again +- handle unknown fields when packing +- test code + +- ensure enums are 32-bit +- support Group (whatever it is) +- almost no code generator options are obeyed +- ISSUE: strings may not contain NULs +- generate Init functions / handle default values +- at least include extensions in Descriptor +- proper support for extensions (not sure i get what's needed) + +- get rid of kThick/ThinSeparator if we decide not to use them +- stop using qsort in the code generator: find some c++ish way to do it diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..07a1ed6 --- /dev/null +++ b/bootstrap @@ -0,0 +1,5 @@ +#! /bin/sh -e +libtoolize +aclocal +autoconf +automake -a --foreign diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..848e85c --- /dev/null +++ b/configure.ac @@ -0,0 +1,10 @@ +AC_INIT(src/google/protobuf-c/protobuf-c.h) +PROTOBUF_C_VERSION=0.0 + +AM_INIT_AUTOMAKE(protobuf-c, $PROTOBUF_C_VERSION) +PACKAGE=protobuf-c +AC_PROG_CC +AC_PROG_CXX +AC_PROG_LIBTOOL + +AC_OUTPUT( Makefile src/Makefile src/test/Makefile ) diff --git a/src/test/Makefile.am b/src/test/Makefile.am new file mode 100644 index 0000000..9f244a1 --- /dev/null +++ b/src/test/Makefile.am @@ -0,0 +1,17 @@ +check_PROGRAMS = test-generated-code +INCLUDES = -I$(srcdir)/.. +test_generated_code_SOURCES = \ +test-generated-code.c \ +generated-code/test.pb-c.c +test_generated_code_LDADD = \ +../libprotobuf-c.la + +generated-code/test.pb-c.c generated-code/test.pb-c.h: ../protoc-c $(srcdir)/test.proto + rm -rf generated-code + mkdir generated-code + ../protoc-c -I$(srcdir) --c_out=generated-code $(srcdir)/test.proto + +BUILT_SOURCES = generated-code/test.pb-c.c generated-code/test.pb-c.h +DISTCLEANFILES = $(BUILT_SOURCES) +TESTS = test-generated-code +EXTRA_DIST = test.proto diff --git a/src/test/test-generated-code.c b/src/test/test-generated-code.c new file mode 100644 index 0000000..4fdb1de --- /dev/null +++ b/src/test/test-generated-code.c @@ -0,0 +1,39 @@ +#include "generated-code/test.pb-c.h" +#include +#include +#include + +int main(int argc, char **argv) +{ + Foo__Person person; + Foo__Person *person2; + unsigned char simple_pad[8]; + size_t size, size2; + unsigned char *packed; + ProtobufCBufferSimple bs = PROTOBUF_C_BUFFER_SIMPLE_INIT (simple_pad); + + memset (&person, 0, sizeof (person)); + person.descriptor = &foo__person__descriptor; + person.name = "dave b"; + person.id = 42; + size = foo__person__get_packed_size (&person); + packed = malloc (size); + assert (packed); + size2 = foo__person__pack (&person, packed); + assert (size == size2); + foo__person__pack_to_buffer (&person, &bs.base); + assert (bs.len == size); + assert (memcmp (bs.data, packed, size) == 0); + PROTOBUF_C_BUFFER_SIMPLE_CLEAR (&bs); + person2 = foo__person__unpack (NULL, size, packed); + assert (person2 != NULL); + assert (person2->id == 42); + assert (strcmp (person2->name, "dave b") == 0); + + foo__person__free_unpacked (person2, NULL); + free (packed); + + printf ("test succeeded.\n"); + + return 0; +} diff --git a/src/test/test.proto b/src/test/test.proto new file mode 100644 index 0000000..46c40df --- /dev/null +++ b/src/test/test.proto @@ -0,0 +1,28 @@ +package foo; + +message Person { + required string name = 1; + required int32 id = 2; + optional string email = 3; + + enum PhoneType { + MOBILE = 0; + HOME = 1; + WORK = 2; + } + + message PhoneNumber { + required string number = 1; + optional PhoneType type = 2 [default = HOME]; + } + + repeated PhoneNumber phone = 4; +} + +message Name { + optional string name = 1; +}; + +service DirLookup { + rpc ByName (Name) returns (Person); +}