Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with protobuf and POCOs in C++

I would like to use protobuf with a C++ project I'm working on. However, I don't like to work with the auto-generated classes protoc creates and prefer to stick with the POCOs I already have. This is because the POCOs are already in use in other parts of the code and I want to be able to switch the serialization mechanism with ease later on. But manually writing converters between POCOs and protobuf message classes seems tedious and wrong.

I want to know if there's a way to use protobuf to create a serializer - an auto-generated class that will be able to serialize and deserialize my POCOs, without bugging me with internals.

Thanks.

like image 359
Vadim Avatar asked Nov 12 '22 02:11

Vadim


1 Answers

First, you may like Cap'n Proto better, it was created by one of Google's former Google Protocol Buffer maintainers. Worth looking into, anyway.

But otherwise, you really need to consider why you're using Google Protocol Buffers.

If you want to achieve the forward and backward compatibility, and to be able to open, then edit, then save an object that possibly a different person created, with a different version of your protocol buffer declaration, and then sent along to yet another person with an even different version of the declaration... then you need to just bite the bullet and use the generated C++ from the Google Protocol Buffer Compiler.

It's really not just a serialization format. It's specifically designed to make it easy living with different versions of your serialization, over time.

If you don't need that flexibility, and you don't like the generated code, you may want to consider a different serialization tool.

like image 159
Matt Cruikshank Avatar answered Nov 15 '22 04:11

Matt Cruikshank