Class ProtobufDecoder
- All Implemented Interfaces:
- Decoder<com.google.protobuf.Message>
Decoder that reads Messages 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.
- Since:
- 5.1
- Author:
- Sebastien Deleuze
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intThe default max size for aggregating messages.
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newProtobufDecoder.ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry) Construct a newProtobufDecoderwith an initializer that allows the registration of message extensions.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanDecode(ResolvableType elementType, MimeType mimeType) Whether the decoder supports the given target element type and the MIME type of the source stream.reactor.core.publisher.Flux<com.google.protobuf.Message>decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) Decode aDataBufferinput stream into a Flux ofT.com.google.protobuf.Messagedecode(DataBuffer dataBuffer, ResolvableType targetType, MimeType mimeType, Map<String, Object> hints) Decode a data buffer to an Object of type T.reactor.core.publisher.Mono<com.google.protobuf.Message>decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) Decode aDataBufferinput stream into a Mono ofT.Return the list of MIME types supported by this Decoder.intReturn theconfiguredmessage size limit.voidsetMaxMessageSize(int maxMessageSize) The max size allowed per message.Methods inherited from class org.springframework.http.codec.protobuf.ProtobufCodecSupportgetMimeTypes, supportsMimeTypeMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.codec.DecodergetDecodableMimeTypes
- 
Field Details- 
DEFAULT_MESSAGE_MAX_SIZEprotected static final int DEFAULT_MESSAGE_MAX_SIZEThe default max size for aggregating messages.- See Also:
 
 
- 
- 
Constructor Details- 
ProtobufDecoderpublic ProtobufDecoder()Construct a newProtobufDecoder.
- 
ProtobufDecoderpublic ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry) Construct a newProtobufDecoderwith an initializer that allows the registration of message extensions.- Parameters:
- extensionRegistry- a message extension registry
 
 
- 
- 
Method Details- 
setMaxMessageSizepublic void setMaxMessageSize(int maxMessageSize) The max size allowed per message.By default, this is set to 256K. - Parameters:
- maxMessageSize- the max size per message, or -1 for unlimited
 
- 
getMaxMessageSizepublic int getMaxMessageSize()Return theconfiguredmessage size limit.- Since:
- 5.1.11
 
- 
canDecodeDescription copied from interface:DecoderWhether the decoder supports the given target element type and the MIME type of the source stream.
- 
decodepublic reactor.core.publisher.Flux<com.google.protobuf.Message> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:DecoderDecode aDataBufferinput stream into a Flux ofT.- Specified by:
- decodein interface- Decoder<com.google.protobuf.Message>
- Parameters:
- inputStream- the- DataBufferinput stream to decode
- elementType- the expected type of elements in the output stream; this type must have been previously passed to the- Decoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returned- true.
- mimeType- the MIME type associated with the input stream (optional)
- hints- additional information about how to do decode
- Returns:
- the output stream with decoded elements
 
- 
decodeToMonopublic reactor.core.publisher.Mono<com.google.protobuf.Message> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:DecoderDecode aDataBufferinput stream into a Mono ofT.- Specified by:
- decodeToMonoin interface- Decoder<com.google.protobuf.Message>
- Parameters:
- inputStream- the- DataBufferinput stream to decode
- elementType- the expected type of elements in the output stream; this type must have been previously passed to the- Decoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returned- true.
- mimeType- the MIME type associated with the input stream (optional)
- hints- additional information about how to do decode
- Returns:
- the output stream with the decoded element
 
- 
decodepublic com.google.protobuf.Message decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingExceptionDescription copied from interface:DecoderDecode a data buffer to an Object of type T. This is useful for scenarios, that distinct messages (or events) are decoded and handled individually, in fully aggregated form.- Specified by:
- decodein interface- Decoder<com.google.protobuf.Message>
- Parameters:
- dataBuffer- the- DataBufferto decode
- targetType- the expected output type
- mimeType- the MIME type associated with the data
- hints- additional information about how to do decode
- Returns:
- the decoded value, possibly null
- Throws:
- DecodingException
 
- 
getDecodableMimeTypesDescription copied from interface:DecoderReturn the list of MIME types supported by this Decoder. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanDecode(elementType, null). The list may also exclude MIME types supported only for a specific element type. Alternatively, useDecoder.getDecodableMimeTypes(ResolvableType)for a more precise list.- Specified by:
- getDecodableMimeTypesin interface- Decoder<com.google.protobuf.Message>
- Returns:
- the list of supported MIME types
 
 
-