2

I'm currently trying to work through the c++ basic tutorial for google Protocol Buffers. I'm not using the .proto files included in the tutorial, but the OpenStreetMap PBF file .proto definition files. I've also tested using the example provided in the tutorial but I'm seeing the same result.

I'm able to compile my .proto files successfully using the following command: protoc -I=./doc/ --cpp_out=./src/mongosm/proto_messages/ ./doc/fileformat.proto

After referencing the correct header file, and trying to open it, the generated classes do not contain a ParseFromIstream method (including the compiled tutorial .proto classes).

I'm not sure if the tutorial is out of date or not, but I'm using v2.5.0 of the protocol buffers library.

Can someone please shed some light on why this might be happening, or how I can parse a file into a generated object?

Cheers, Justin

0

1 Answer 1

1

"Can someone please shed some light on why this might be happening, or how I can parse a file into a generated object?"

The ParseFromIstream() method is implemented in the Message base class, which is inherited by all of the generated classes. Thus it's not necessary the generator provides any code for it.

As from protobuf's documentation:

bool Message::ParseFromIstream( istream * input)

Parse a protocol buffer from a C++ istream.
If successful, the entire input will be consumed.

Sign up to request clarification or add additional context in comments.

3 Comments

So does that mean I need to implement that method myself, or use another method to read the file??
@Juzzbott "So does that mean I need to implement that method myself" No, it's already implemented as mentioned. Do you have any particular problems using this function? Did you miss to link the libprotobuf.a to your program?
Thanks. I didn't realise I had to link to the libprotobuf.a file, as I was including the header (this is my first c++ linking to third party libraries).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.