git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@21 00440858-1255-0410-a3e6-75ea37f81c3a

This commit is contained in:
lahiker42 2008-08-22 22:15:42 +00:00
parent 6ab9b2d6d0
commit a9c16cc839
7 changed files with 114 additions and 0 deletions

1
Makefile.am Normal file
View File

@ -0,0 +1 @@
SUBDIRS = src

14
TODO Normal file
View File

@ -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

5
bootstrap Executable file
View File

@ -0,0 +1,5 @@
#! /bin/sh -e
libtoolize
aclocal
autoconf
automake -a --foreign

10
configure.ac Normal file
View File

@ -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 )

17
src/test/Makefile.am Normal file
View File

@ -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

View File

@ -0,0 +1,39 @@
#include "generated-code/test.pb-c.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
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;
}

28
src/test/test.proto Normal file
View File

@ -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);
}