Can I use proto2 generated code stubs with libprotobuf3.x?

358 views Asked by At

I have a legacy application using proto2 with libprotobuf2.x. There is another application application that I would like this application to talk to with proto3.

I checked on possible solutions and the discussion in this thread says that libprotobuf3.x provides compatibility with proto2.

Does this mean that I can use the same proto(with proto2) and the same code stubs pb.h/pb.cpp generated for proto2 and just link my legacy application with libprotobuf3.x instead and it would work like a charm?

I don't want to update legacy protos to proto3 as it might require major refactoring in the legacy code.

1

There are 1 answers

0
rustyx On BEST ANSWER

No, you can't link .pb.* files generated with protoc 2.0 against libprotobuf 3.0. Just like with any shared library, an increment in the major version number means a breaking API change.

Compatibility with proto2 means that Proto 2 syntax is supported (syntax = "proto2"). Also proto3 is binary-compatible with proto2 on the wire.

I don't want to update legacy protos to proto3 as it might require major refactoring in the legacy code.

Chances are, if you re-generate your .pb files with protoc 3 and recompile, it'll work without refactoring (the default syntax is still proto2).