类 ProtobufDecoder
- java.lang.Object
- org.springframework.http.codec.protobuf.ProtobufCodecSupport
- org.springframework.http.codec.protobuf.ProtobufDecoder
- 所有已实现的接口:
Decoder<com.google.protobuf.Message>
public class ProtobufDecoder extends ProtobufCodecSupport implements Decoder<com.google.protobuf.Message>
ADecoderthat readsMessages 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 viadecodeToMono(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 emptyMono.To generate
MessageJava classes, you need to install theprotocbinary.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.- 从以下版本开始:
- 5.1
- 作者:
- S茅bastien Deleuze
- 另请参阅:
ProtobufEncoder
字段概要
字段 修饰符和类型 字段 说明 protected static intDEFAULT_MESSAGE_MAX_SIZEThe default max size for aggregating messages.
构造器概要
构造器 构造器 说明 ProtobufDecoder()Construct a newProtobufDecoder.ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry)Construct a newProtobufDecoderwith an initializer that allows the registration of message extensions.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleancanDecode(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(org.reactivestreams.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(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)Decode aDataBufferinput stream into a Mono ofT.List<MimeType>getDecodableMimeTypes()Return the list of MIME types this decoder supports.intgetMaxMessageSize()Return theconfiguredmessage size limit.voidsetMaxMessageSize(int maxMessageSize)The max size allowed per message.从类继承的方法 org.springframework.http.codec.protobuf.ProtobufCodecSupport
getMimeTypes, supportsMimeType
字段详细资料
DEFAULT_MESSAGE_MAX_SIZE
protected static final int DEFAULT_MESSAGE_MAX_SIZE
The default max size for aggregating messages.- 另请参阅:
- 常量字段值
构造器详细资料
ProtobufDecoder
public ProtobufDecoder()
Construct a newProtobufDecoder.
ProtobufDecoder
public ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry)
Construct a newProtobufDecoderwith an initializer that allows the registration of message extensions.- 参数:
extensionRegistry- a message extension registry
方法详细资料
setMaxMessageSize
public void setMaxMessageSize(int maxMessageSize)
The max size allowed per message.By default, this is set to 256K.
- 参数:
maxMessageSize- the max size per message, or -1 for unlimited
getMaxMessageSize
public int getMaxMessageSize()
Return theconfiguredmessage size limit.- 从以下版本开始:
- 5.1.11
canDecode
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
从接口复制的说明:DecoderWhether the decoder supports the given target element type and the MIME type of the source stream.
decode
public reactor.core.publisher.Flux<com.google.protobuf.Message> decode(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
从接口复制的说明:DecoderDecode aDataBufferinput stream into a Flux ofT.- 指定者:
decode在接口中Decoder<com.google.protobuf.Message>- 参数:
inputStream- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returnedtrue.mimeType- the MIME type associated with the input stream (optional)hints- additional information about how to do encode- 返回:
- the output stream with decoded elements
decodeToMono
public reactor.core.publisher.Mono<com.google.protobuf.Message> decodeToMono(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
从接口复制的说明:DecoderDecode aDataBufferinput stream into a Mono ofT.- 指定者:
decodeToMono在接口中Decoder<com.google.protobuf.Message>- 参数:
inputStream- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returnedtrue.mimeType- the MIME type associated with the input stream (optional)hints- additional information about how to do encode- 返回:
- the output stream with the decoded element
decode
public com.google.protobuf.Message decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints) throws DecodingException
从接口复制的说明: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.- 指定者:
decode在接口中Decoder<com.google.protobuf.Message>- 参数:
dataBuffer- theDataBufferto decodetargetType- the expected output typemimeType- the MIME type associated with the datahints- additional information about how to do encode- 返回:
- the decoded value, possibly
null - 抛出:
DecodingException
getDecodableMimeTypes
public List<MimeType> getDecodableMimeTypes()
从接口复制的说明:DecoderReturn the list of MIME types this decoder supports.- 指定者:
getDecodableMimeTypes在接口中Decoder<com.google.protobuf.Message>