0

I have to serialize std::queue that contains boost::variant. Variant has about 20 different structures. What is better/prefered way of representing variant in proto3? I mean, should I use oneof or any? How about their performance?

I do not ask how to do that I do not know what is the best solution.

1

1 Answer 1

0

You start the other way round. You write a .proto file that defines (in Google's protobuf schema language) the "messages" you wish to define. One of these can be a 'oneof' containing lots of others. You then compile that .proto file using the Protocol Buffers compiler, and you end up with C++ source code that implements those messages as C++ classes derived from a library of base classes. These classes have serialisation routines built in. At no point do you use Boost or hand written C++ classes.

Boost::variant might very well be the equivalent of protobuf's 'oneof', but you'd not use it to contain different protobuf messages, because that's what 'oneof' does for you. Mixing Boost::variant with GPB's own style of doing things is likely asking for confusing code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.