lufthansa747
lufthansa747

Reputation: 2061

c++ nanopb Protobuff without <iostream>

I have a protoBuff3 specification which looks something like

message MSG {
   string name = 1;
   repeated string data = 2;
}

And a options file that sets "MSG.data max_count:20"

I am trying to encode and decode protobuffs without using .

I am currently using pb_ostream_from_buffer and pb_encode however I when trying to link i get an error saying pb_ostream_..., pb_encode, pb_decode,... external symbols do not exist. I am able to find these functions defined in pb_encode.h and pb_decode.h

.Online i see reference to functions like ParseFromString and SerializeToString, however I can not find these function anywhere.

What is the proper way to serialize and serialize my message without iostreams?

Upvotes: 0

Views: 893

Answers (1)

jpa
jpa

Reputation: 12176

There are many protobuf libraries that are separate from each other. Generally you'd pick one and use that:

Either of these can be used for serializing and parsing messages from memory buffers. Additionally Google's library supports C++ iostreams, while nanopb supports a similar stream system implemented in C.

The error about "external symbols do not exist" suggests that you are not linking against the nanopb library code (pb_encode.c, pb_decode.c and pb_common.c). As usual, the .h files only contain function declaration, while you need to link against the .c files to provide the function definition.

Upvotes: 1

Related Questions