Michael Gopshtein Michael Gopshtein - 2 years ago 140
Java Question

gRPC and ExtensionRegistry

I am using gRPC with Java, and the messages that I'm sending may contain extensions. In the Protobuf docs they say:

When parsing a message that might have extensions, you must provide an ExtensionRegistry in which you have registered any extensions that you want to be able to parse.

The question is how I specify the
in the code which uses gRPC as a client (and the message parsing is performed inside the gRPC-generated code).

UPDATE: support for extensions was added to gRPC


A note from the developer: This API is not stable, and will very likely change once we have a more appropriate long term solution (with custom registries per method, etc.)

more info

Answer Source

Hmm, I can't find anything about ExtensionRegistry in the GRPC code. It's possible that because extensions were removed in proto3, GRPC chose not to support them even if you are using proto2.

However, as a work-around, you can always serialize your proto and then parse it again:

message = MyType.parseFrom(message.toByteString(),

This wastes a bunch of resources to serialize and re-parse, but should get the job done. (This, of course, relies on unknown field preservation, another feature that was removed in proto3, but you're using proto2, so it should work!)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download