How to determine protobuf version of Protobuf object?

Viewed 13449

My project assumes Proto3 Objects as input. But, sometimes users provide Proto2 Object as input. In those cases, we want to throw exception as our code works with only Proto3 classes.

How can we check if input Protobuf object provided is Proto2 or Proto3 ?

Checking for method presence or default values is kind of a Hack. Is there any proper method to check version of Protobuf Object ?

2 Answers

Need to Define Your Protocol Format in .proto file. The .proto file starts with

 syntax = "proto3";

I found answer:

proto_verison = protobufObject.getDescriptorForType().getFile().getSyntax().name()

Check if its "PROTO3"

Related