Package io.servicetalk.data.protobuf
Class ProtobufSerializerFactory
java.lang.Object
io.servicetalk.data.protobuf.ProtobufSerializerFactory
Caches instances of
SerializerDeserializer and StreamingSerializerDeserializer for
protocol buffer.
Use PROTOBUF for the default configuration, or construct an instance via
ProtobufSerializerFactory(int) to bound the maximum size of streaming (VarInt length-prefixed) messages.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ProtobufSerializerFactorySingleton instance which creates protocol buffer serializers, applying the default maximum streaming message size. -
Constructor Summary
ConstructorsConstructorDescriptionProtobufSerializerFactory(int maxMessageSize) Create a factory that bounds the maximum size of messages accepted by its streaming deserializers. -
Method Summary
Modifier and TypeMethodDescription<T extends com.google.protobuf.MessageLite>
SerializerDeserializer<T>serializerDeserializer(com.google.protobuf.Parser<T> parser) Get aSerializerDeserializer.<T extends com.google.protobuf.MessageLite>
SerializerDeserializer<T>serializerDeserializer(Class<T> clazz) Get aSerializerDeserializer.<T extends com.google.protobuf.MessageLite>
StreamingSerializerDeserializer<T>streamingSerializerDeserializer(com.google.protobuf.Parser<T> parser) Get aStreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming.<T extends com.google.protobuf.MessageLite>
StreamingSerializerDeserializer<T>streamingSerializerDeserializer(Class<T> clazz) Get aStreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming.
-
Field Details
-
PROTOBUF
Singleton instance which creates protocol buffer serializers, applying the default maximum streaming message size.
-
-
Constructor Details
-
ProtobufSerializerFactory
public ProtobufSerializerFactory(int maxMessageSize) Create a factory that bounds the maximum size of messages accepted by its streaming deserializers.- Parameters:
maxMessageSize- The maximum length (in bytes) declared by a streaming frame's length prefix that will be accepted during deserialization. A frame declaring a larger length is rejected before any of its bytes are buffered.0disables the limit;-1warns at the default threshold without rejecting; other negative values are rejected. This applies only to streaming deserialization; single-message serialization is not length-prefixed and is unaffected.
-
-
Method Details
-
serializerDeserializer
public <T extends com.google.protobuf.MessageLite> SerializerDeserializer<T> serializerDeserializer(com.google.protobuf.Parser<T> parser) Get aSerializerDeserializer.- Type Parameters:
T- The type to serialize and deserialize.- Parameters:
parser- TheParserused to serialize and deserialize.- Returns:
- a
SerializerDeserializer.
-
serializerDeserializer
public <T extends com.google.protobuf.MessageLite> SerializerDeserializer<T> serializerDeserializer(Class<T> clazz) Get aSerializerDeserializer.- Type Parameters:
T- The type to serialize and deserialize.- Parameters:
clazz- Used to obtain aParserwhich is used to serialize and deserialize.- Returns:
- a
SerializerDeserializer.
-
streamingSerializerDeserializer
public <T extends com.google.protobuf.MessageLite> StreamingSerializerDeserializer<T> streamingSerializerDeserializer(com.google.protobuf.Parser<T> parser) Get aStreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming. The deserialized message size is limited to this factory's configured maximum (the default forPROTOBUF, configurable viaProtobufSerializerFactory(int)).- Type Parameters:
T- The type to serialize and deserialize.- Parameters:
parser- TheParserused to serialize and deserialize.- Returns:
- a
StreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming. - See Also:
-
streamingSerializerDeserializer
public <T extends com.google.protobuf.MessageLite> StreamingSerializerDeserializer<T> streamingSerializerDeserializer(Class<T> clazz) Get aStreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming. The deserialized message size is limited to this factory's configured maximum (the default forPROTOBUF, configurable viaProtobufSerializerFactory(int)).- Type Parameters:
T- The type to serialize and deserialize.- Parameters:
clazz- Used to obtain aParserwhich is used to serialize and deserialize.- Returns:
- a
StreamingSerializerDeserializerwhich supports <VarInt length, value> encoding as described in Protobuf Streaming. - See Also:
-