Class ProtoLiteUtils
- java.lang.Object
-
- io.grpc.protobuf.lite.ProtoLiteUtils
-
@ExperimentalApi("Will remain experimental as protobuf lite API is not stable") public final class ProtoLiteUtils extends java.lang.Object
Utility methods for using protobuf with grpc.Note that this class will remain experimental for the foreseeable future as the proto lite API, which this class depends on, is not guaranteed to be stable. This is explained in protobuf documentation at: https://github.com/protocolbuffers/protobuf/blob/main/java/lite.md
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ProtoLiteUtils.MessageMarshaller<T extends com.google.protobuf.MessageLite>
private static class
ProtoLiteUtils.MetadataMarshaller<T extends com.google.protobuf.MessageLite>
-
Field Summary
Fields Modifier and Type Field Description private static int
BUF_SIZE
(package private) static int
DEFAULT_MAX_MESSAGE_SIZE
The same value asGrpcUtil.DEFAULT_MAX_MESSAGE_SIZE
.(package private) static com.google.protobuf.ExtensionRegistryLite
globalRegistry
-
Constructor Summary
Constructors Modifier Constructor Description private
ProtoLiteUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static long
copy(java.io.InputStream from, java.io.OutputStream to)
Copies the data from input stream to output stream.static <T extends com.google.protobuf.MessageLite>
MethodDescriptor.Marshaller<T>marshaller(T defaultInstance)
Creates aMethodDescriptor.Marshaller
for protos of the same type asdefaultInstance
.static <T extends com.google.protobuf.MessageLite>
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 com.google.protobuf.MessageLite>
Metadata.BinaryMarshaller<T>metadataMarshaller(T defaultInstance)
Produce a metadata marshaller for a protobuf type.static void
setExtensionRegistry(com.google.protobuf.ExtensionRegistryLite newRegistry)
Sets the global registry for proto marshalling shared across all servers and clients.
-
-
-
Field Detail
-
globalRegistry
static volatile com.google.protobuf.ExtensionRegistryLite globalRegistry
-
BUF_SIZE
private static final int BUF_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_MAX_MESSAGE_SIZE
static final int DEFAULT_MAX_MESSAGE_SIZE
The same value asGrpcUtil.DEFAULT_MAX_MESSAGE_SIZE
.- See Also:
- Constant Field Values
-
-
Method Detail
-
setExtensionRegistry
public static void setExtensionRegistry(com.google.protobuf.ExtensionRegistryLite newRegistry)
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.ExtensionRegistryLite)
, 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.0.0
-
marshaller
public static <T extends com.google.protobuf.MessageLite> MethodDescriptor.Marshaller<T> marshaller(T defaultInstance)
Creates 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 com.google.protobuf.MessageLite> 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
-
metadataMarshaller
public static <T extends com.google.protobuf.MessageLite> Metadata.BinaryMarshaller<T> metadataMarshaller(T defaultInstance)
Produce a metadata marshaller for a protobuf type.- Since:
- 1.0.0
-
copy
static long copy(java.io.InputStream from, java.io.OutputStream to) throws java.io.IOException
Copies the data from input stream to output stream.- Throws:
java.io.IOException
-
-