Decoder that reads com.google.protobuf.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 | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| protected static final int | DEFAULT_MESSAGE_MAX_SIZE
The default max size for aggregating messages. |
| private final ExtensionRegistry | |
| private int | |
| private static final ConcurrentMap |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ProtobufDecoder(ExtensionRegistry
a message extension registry extensionRegistry)Construct a new |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | canDecode(ResolvableType
the target element type for the output stream elementType, MimeType the mime type associated with the stream to decode
(can be mimeType)null if not specified)Implements org. |
| public Flux | decode(Publisher<DataBuffer>
the inputStream, ResolvableType DataBuffer input stream to decodethe expected type of elements in the output stream;
this type must have been previously passed to the elementType, MimeType canDecode
method and it must have returned true.the MIME type associated with the input stream (optional) mimeType, Map<String, Object> additional information about how to do decode hints)Implements org. DataBuffer input stream into a Flux of T.
|
| public Message | decode(DataBuffer
the dataBuffer, ResolvableType DataBuffer to decodethe expected output type targetType, MimeType the MIME type associated with the data mimeType, Map<String, Object> additional information about how to do decode hints)Overrides default org. |
| public Mono | decodeToMono(Publisher<DataBuffer>
the inputStream, ResolvableType DataBuffer input stream to decodethe expected type of elements in the output stream;
this type must have been previously passed to the elementType, MimeType canDecode
method and it must have returned true.the MIME type associated with the input stream (optional) mimeType, Map<String, Object> additional information about how to do decode hints)Implements org. DataBuffer input stream into a Mono of T.
|
| public List | getDecodableMimeTypes()
Implements org. |
| public int | |
| private static Message. | |
| public void | setMaxMessageSize(int
the max size per message, or -1 for unlimited maxMessageSize)The max size allowed per message. |
| DEFAULT_MESSAGE_MAX_SIZE | back to summary |
|---|---|
| protected static final int DEFAULT_MESSAGE_MAX_SIZE The default max size for aggregating messages. | |
| extensionRegistry | back to summary |
|---|---|
| private final ExtensionRegistry extensionRegistry | |
| maxMessageSize | back to summary |
|---|---|
| private int maxMessageSize | |
| methodCache | back to summary |
|---|---|
| private static final ConcurrentMap<Class<?>, Method> methodCache | |
| ProtobufDecoder | back to summary |
|---|---|
| public ProtobufDecoder() Construct a new | |
| ProtobufDecoder | back to summary |
|---|---|
| public ProtobufDecoder(ExtensionRegistry extensionRegistry) Construct a new
| |
| canDecode | back to summary |
|---|---|
| public boolean canDecode(ResolvableType elementType, MimeType mimeType) Implements org. Doc from org. Whether the decoder supports the given target element type and the MIME type of the source stream.
| |
| decode | back to summary |
|---|---|
| public Flux Implements org. Doc from org. Decode a
| |
| decode | back to summary |
|---|---|
| public Message decode(DataBuffer dataBuffer, ResolvableType targetType, MimeType mimeType, Map<String, Object> hints) throws DecodingException Overrides default org. Doc from org. Decode 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.
| |
| decodeToMono | back to summary |
|---|---|
| public Mono Implements org. Doc from org. Decode a
| |
| getDecodableMimeTypes | back to summary |
|---|---|
| public List Implements org. Doc from org. Return 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 via | |
| getMaxMessageSize | back to summary |
|---|---|
| public int getMaxMessageSize() Return the
| |
| getMessageBuilder | back to summary |
|---|---|
| private static Message. Create a new This method uses a ConcurrentHashMap for caching method lookups. | |
| setMaxMessageSize | back to summary |
|---|---|
| public void setMaxMessageSize(int maxMessageSize) The max size allowed per message. By default, this is set to 256K.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ResolvableType | |
| private final int | |
| private int | |
| private int | |
| private DataBuffer |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Iterable | apply(DataBuffer
the function argument input)Implements java. |
| public void | |
| private boolean | Returns: true when the message size is parsed successfully, false when the message size is
truncatedParse message size as a varint from the input stream, updating |
| elementType | back to summary |
|---|---|
| private final ResolvableType elementType | |
| maxMessageSize | back to summary |
|---|---|
| private final int maxMessageSize | |
| messageBytesToRead | back to summary |
|---|---|
| private int messageBytesToRead | |
| offset | back to summary |
|---|---|
| private int offset | |
| output | back to summary |
|---|---|
| private DataBuffer output
| |
| MessageDecoderFunction | back to summary |
|---|---|
| public MessageDecoderFunction(ResolvableType elementType, int maxMessageSize) | |
| apply | back to summary |
|---|---|
| public Iterable Implements java. Doc from java. Applies this function to the given argument.
| |
| discard | back to summary |
|---|---|
| public void discard() | |
| readMessageSize | back to summary |
|---|---|
| private boolean readMessageSize(DataBuffer input) Parse message size as a varint from the input stream, updating
| |