类 ProtobufDecoder

java.lang.Object
cn.taketoday.http.codec.protobuf.ProtobufCodecSupport
cn.taketoday.http.codec.protobuf.ProtobufDecoder
所有已实现的接口:
cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>

public class ProtobufDecoder extends ProtobufCodecSupport implements cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>
A 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.

从以下版本开始:
4.0
作者:
Sebastien Deleuze
另请参阅:
  • 字段详细资料

    • DEFAULT_MESSAGE_MAX_SIZE

      protected static final int DEFAULT_MESSAGE_MAX_SIZE
      The default max size for aggregating messages.
      另请参阅:
    • methodCache

      private static final ConcurrentMap<Class<?>,Method> methodCache
    • extensionRegistry

      private final com.google.protobuf.ExtensionRegistry extensionRegistry
    • maxMessageSize

      private int maxMessageSize
  • 构造器详细资料

    • ProtobufDecoder

      public ProtobufDecoder()
      Construct a new ProtobufDecoder.
    • ProtobufDecoder

      public ProtobufDecoder(com.google.protobuf.ExtensionRegistry extensionRegistry)
      Construct a new ProtobufDecoder with 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 the configured message size limit.
    • canDecode

      public boolean canDecode(cn.taketoday.core.ResolvableType elementType, @Nullable cn.taketoday.util.MimeType mimeType)
      指定者:
      canDecode 在接口中 cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>
    • decode

      public reactor.core.publisher.Flux<com.google.protobuf.Message> decode(org.reactivestreams.Publisher<cn.taketoday.core.io.buffer.DataBuffer> inputStream, cn.taketoday.core.ResolvableType elementType, @Nullable cn.taketoday.util.MimeType mimeType, @Nullable Map<String,Object> hints)
      指定者:
      decode 在接口中 cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>
    • decodeToMono

      public reactor.core.publisher.Mono<com.google.protobuf.Message> decodeToMono(org.reactivestreams.Publisher<cn.taketoday.core.io.buffer.DataBuffer> inputStream, cn.taketoday.core.ResolvableType elementType, @Nullable cn.taketoday.util.MimeType mimeType, @Nullable Map<String,Object> hints)
      指定者:
      decodeToMono 在接口中 cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>
    • decode

      public com.google.protobuf.Message decode(cn.taketoday.core.io.buffer.DataBuffer dataBuffer, cn.taketoday.core.ResolvableType targetType, @Nullable cn.taketoday.util.MimeType mimeType, @Nullable Map<String,Object> hints) throws cn.taketoday.core.codec.DecodingException
      指定者:
      decode 在接口中 cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>
      抛出:
      cn.taketoday.core.codec.DecodingException
    • getMessageBuilder

      private static com.google.protobuf.Message.Builder getMessageBuilder(Class<?> clazz) throws Exception
      Create a new Message.Builder instance for the given class.

      This method uses a ConcurrentHashMap for caching method lookups.

      抛出:
      Exception
    • getDecodableMimeTypes

      public List<cn.taketoday.util.MimeType> getDecodableMimeTypes()
      指定者:
      getDecodableMimeTypes 在接口中 cn.taketoday.core.codec.Decoder<com.google.protobuf.Message>