Package io.grpc.protobuf
Class ProtoUtils
- java.lang.Object
-
- io.grpc.protobuf.ProtoUtils
-
public final class ProtoUtils extends Object
Utility methods for using protobuf with grpc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Message>
Metadata.Key<T>keyForProto(T instance)
Produce a metadata key for a generated protobuf type.static <T extends Message>
MethodDescriptor.Marshaller<T>marshaller(T defaultInstance)
Create aMethodDescriptor.Marshaller
for protos of the same type asdefaultInstance
.static <T extends Message>
MethodDescriptor.Marshaller<T>marshallerWithRecursionLimit(T defaultInstance, int recursionLimit)
Creates aMethodDescriptor.Marshaller
for protos of the same type asdefaultInstance
and a custom limit for the recursion depth.static <T extends Message>
Metadata.BinaryMarshaller<T>metadataMarshaller(T instance)
Produce a metadata marshaller for a protobuf type.static void
setExtensionRegistry(ExtensionRegistry registry)
Sets the global registry for proto marshalling shared across all servers and clients.
-
-
-
Method Detail
-
setExtensionRegistry
public static void setExtensionRegistry(ExtensionRegistry registry)
Sets the global registry for proto marshalling shared across all servers and clients.Warning: This API will likely change over time. It is not possible to have separate registries per Process, Server, Channel, Service, or Method. This is intentional until there is a more appropriate API to set them.
Warning: Do NOT modify the extension registry after setting it. It is thread safe to call
setExtensionRegistry(com.google.protobuf.ExtensionRegistry)
, but not to modify the underlying object.If you need custom parsing behavior for protos, you will need to make your own
MethodDescriptor.Marshaller
for the time being.- Since:
- 1.16.0
-
marshaller
public static <T extends Message> MethodDescriptor.Marshaller<T> marshaller(T defaultInstance)
Create aMethodDescriptor.Marshaller
for protos of the same type asdefaultInstance
.- Since:
- 1.0.0
-
marshallerWithRecursionLimit
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10108") public static <T extends Message> MethodDescriptor.Marshaller<T> marshallerWithRecursionLimit(T defaultInstance, int recursionLimit)
Creates aMethodDescriptor.Marshaller
for protos of the same type asdefaultInstance
and a custom limit for the recursion depth. Any negative number will leave the limit to its default value as defined by the protobuf library.- Since:
- 1.56.0
-
keyForProto
public static <T extends Message> Metadata.Key<T> keyForProto(T instance)
Produce a metadata key for a generated protobuf type.- Since:
- 1.0.0
-
metadataMarshaller
public static <T extends Message> Metadata.BinaryMarshaller<T> metadataMarshaller(T instance)
Produce a metadata marshaller for a protobuf type.- Since:
- 1.13.0
-
-