Communication between Google protobuf and nanopb

733 views
Skip to first unread message

grundr...@gmail.com

unread,
Nov 2, 2012, 10:31:55 AM11/2/12
to nan...@googlegroups.com
Hi,
I'm trying to evaluate nanopb using a nanopb test program and a c++ test program using the "original" Google protobuf.

I defined a message similar to the person.proto, using String variables with max size and included nanopb.proto

From that proto file I generated the C++ classes and the nanopb c and header files.

When I try to compile my C++ test program, it fails, because a header file named nanopb.pb.h was missing... So I generated the header and C++ Code from the nanopb.proto
It still doesnt work...

I'm asking myself if what I am doing is the right thing? Is it possible to communicate between the Google version and nanopb using max length? Do I need two .proto files - one describing my messages for Google version and one for nanopb?

Any hint for the right way to do this is appreciated :-)
Thanks! Tobias

Petteri Aimonen

unread,
Nov 2, 2012, 12:55:59 PM11/2/12
to nan...@googlegroups.com
Hi,

> I'm asking myself if what I am doing is the right thing? Is it
> possible to communicate between the Google version and nanopb using
> max length? Do I need two .proto files - one describing my messages
> for Google version and one for nanopb?

It is possible. Basically, you need to compile the C++ versions of your
.proto and also nanopb.proto. See the attached file for an example, it
should build with the included build.sh.

However, I agree that the nanopb.proto causes some trouble when
beginning a project, because protoc is quite picky about include paths.
Using those custom options is the "official way" to describe this
information, but I'm starting to think that a separate configuration
file is much easier to use. There is already some limited support for
this in 0.1.7, where you can specify e.g.

python ../generator/nanopb_generator.py -s 'max_size:15' person.pb

but only per-file (not per-msg or per-field) for now.

--
Petteri
test_project.tar.gz

Tobias Scharnberg

unread,
Nov 5, 2012, 2:50:06 AM11/5/12
to nan...@googlegroups.com
Hi Petteri,
thank you for your superfast reply!

Jep, the includes are a bit tricky. But I think I got them right now. Your example still fails to build with:


cpp/nanopb.pb.cc:80:3: Fehler: »protobuf_AddDesc_descriptor_2eproto« ist kein Element von »google::protobuf«

protobuf_AddDesc_descriptor_2eproto« is not an element of »google::protobuf«

which seems to be right, because I can't find the function in protobuf header files.  I'm using protobuf-2.4.1 btw. Maybe its the wrong version?

Tobias

petteri...@gmail.com

unread,
Nov 5, 2012, 3:19:06 AM11/5/12
to nan...@googlegroups.com
Hi,

> cpp/nanopb.pb.cc:80:3: Fehler: �protobuf_AddDesc_descriptor_2eproto� ist
> kein Element von �google::protobuf�
>
> protobuf_AddDesc_descriptor_2eproto� is not an element of �google::protobuf�

Seems strange, considering that the cpp/nanopb.pb.cc is generated by the
protoc compiler. Make sure that your protoc is of the same version as
your Google protobuf include files are.

The code itself should work with any protobuf-2.4.* version.

--
Petteri

Tobias Scharnberg

unread,
Nov 5, 2012, 3:30:03 AM11/5/12
to nan...@googlegroups.com
Hi, I'm sorry, its still my includes, and my fault.

I changed the import path in nanopb.proto, but I forgot to change the include path invocing protoc. The protoc generation went through without errors, but this messed up the includes within the generated files.

Your example works now,
thanks for your help!

Tobias


Am Montag, 5. November 2012 09:19:08 UTC+1 schrieb Petteri Aimonen:
Hi,

> cpp/nanopb.pb.cc:80:3: Fehler: �protobuf_AddDesc_descriptor_2eproto� ist
> kein Element von �google::protobuf�
>
> protobuf_AddDesc_descriptor_2eproto� is not an element of �google::protobuf�
Reply all
Reply to author
Forward
0 new messages