public class ProtobufDecoder extends ProtobufCodecSupport implements org.springframework.core.codec.Decoder<com.google.protobuf.Message>
Decoder
that reads Message
s using
Google Protocol Buffers.
Flux deserialized via
decode(Publisher, ResolvableType, MimeType, Map)
are expected to use
delimited Protobuf messages with the size of each message specified before
the message itself. Single values deserialized via
decodeToMono(Publisher, ResolvableType, MimeType, Map)
are expected
to use regular Protobuf message format (without the size prepended before
the message).
Notice that default instance of Protobuf message produces empty byte
array, so Mono.just(Msg.getDefaultInstance())
sent over the network
will be deserialized as an empty Mono
.
To generate Message
Java classes, you need to install the
protoc
binary.
This decoder requires Protobuf 3 or higher, and supports
"application/x-protobuf"
and "application/octet-stream"
with
the official "com.google.protobuf:protobuf-java"
library.
ProtobufEncoder
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_MESSAGE_MAX_SIZE
The default max size for aggregating messages.
|
Constructor and Description |
---|
ProtobufDecoder()
Construct a new
ProtobufDecoder . |
ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry)
Construct a new
ProtobufDecoder with an initializer that allows the
registration of message extensions. |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecode(org.springframework.core.ResolvableType elementType,
org.springframework.util.MimeType mimeType) |
reactor.core.publisher.Flux<com.google.protobuf.Message> |
decode(org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer> inputStream,
org.springframework.core.ResolvableType elementType,
org.springframework.util.MimeType mimeType,
Map<String,Object> hints) |
reactor.core.publisher.Mono<com.google.protobuf.Message> |
decodeToMono(org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer> inputStream,
org.springframework.core.ResolvableType elementType,
org.springframework.util.MimeType mimeType,
Map<String,Object> hints) |
List<org.springframework.util.MimeType> |
getDecodableMimeTypes() |
int |
getMaxMessageSize()
Return the
configured message size limit. |
void |
setMaxMessageSize(int maxMessageSize)
The max size allowed per message.
|
getMimeTypes, supportsMimeType
protected static final int DEFAULT_MESSAGE_MAX_SIZE
public ProtobufDecoder()
ProtobufDecoder
.public ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry)
ProtobufDecoder
with an initializer that allows the
registration of message extensions.extensionRegistry
- a message extension registrypublic void setMaxMessageSize(int maxMessageSize)
By default in 5.1 this is set to 64K. In 5.2 the default for this limit is set to 256K.
maxMessageSize
- the max size per message, or -1 for unlimitedpublic int getMaxMessageSize()
configured
message size limit.public boolean canDecode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType)
canDecode
in interface org.springframework.core.codec.Decoder<com.google.protobuf.Message>
public reactor.core.publisher.Flux<com.google.protobuf.Message> decode(org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer> inputStream, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)
decode
in interface org.springframework.core.codec.Decoder<com.google.protobuf.Message>
public reactor.core.publisher.Mono<com.google.protobuf.Message> decodeToMono(org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer> inputStream, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)
decodeToMono
in interface org.springframework.core.codec.Decoder<com.google.protobuf.Message>
public List<org.springframework.util.MimeType> getDecodableMimeTypes()
getDecodableMimeTypes
in interface org.springframework.core.codec.Decoder<com.google.protobuf.Message>