SRC
- The type that the codec decodes from and encodes toIN
- The type produced by decodingOUT
- The type consumed by encodingpublic abstract class Codec<SRC,IN,OUT> extends java.lang.Object implements Function<OUT,SRC>
SRC
into an
instance of IN
and passing that to the given Consumer
. A
codec also provides an encoder to take an instance of OUT
and encode to an
instance of SRC
.Modifier and Type | Field and Description |
---|---|
static byte |
DEFAULT_DELIMITER |
protected java.lang.Byte |
delimiter |
Modifier | Constructor and Description |
---|---|
protected |
Codec()
Create a new Codec set with a \0 delimiter to finish any Buffer encoded value or scan for delimited decoded
Buffers.
|
protected |
Codec(java.lang.Byte delimiter)
A delimiter can be used to trail any decoded buffer or to finalize encoding from any incoming value
|
Modifier and Type | Method and Description |
---|---|
protected Buffer |
addDelimiterIfAny(Buffer buffer)
Add a trailing delimiter if defined
|
org.reactivestreams.Publisher<IN> |
decode(org.reactivestreams.Publisher<? extends SRC> publisherToDecode)
Provide the caller with a decoder to turn a source object into an instance of the input
type.
|
Function<SRC,IN> |
decoder()
Provide the caller with a decoder to turn a source object into an instance of the input
type.
|
abstract Function<SRC,IN> |
decoder(Consumer<IN> next)
Provide the caller with a decoder to turn a source object into an instance of the input
type.
|
protected IN |
doBufferDecode(Buffer buffer)
Decode a buffer
|
protected IN |
doDelimitedBufferDecode(Consumer<IN> decoderCallback,
Buffer buffer)
Helper method to scan for delimiting byte the codec might benefit from, e.g.
|
org.reactivestreams.Publisher<SRC> |
encode(org.reactivestreams.Publisher<? extends OUT> publisherToEncode)
Provide the caller with an encoder to turn an output sequence into an sequence of the source
type.
|
Function<OUT,SRC> |
encoder()
Provide the caller with an encoder to turn an output object into an instance of the source
type.
|
protected static <IN> IN |
invokeCallbackOrReturn(Consumer<IN> consumer,
IN v) |
public static final byte DEFAULT_DELIMITER
protected final java.lang.Byte delimiter
protected Codec()
protected Codec(java.lang.Byte delimiter)
delimiter
- delimiter can be left undefined (null) to bypass appending at encode time and scanning at decode
time.public org.reactivestreams.Publisher<IN> decode(org.reactivestreams.Publisher<? extends SRC> publisherToDecode)
public Function<SRC,IN> decoder()
public abstract Function<SRC,IN> decoder(Consumer<IN> next)
next
- The Consumer
to call after the object has been decoded.public org.reactivestreams.Publisher<SRC> encode(org.reactivestreams.Publisher<? extends OUT> publisherToEncode)
public Function<OUT,SRC> encoder()
protected IN doDelimitedBufferDecode(Consumer<IN> decoderCallback, Buffer buffer)
decoderCallback
- buffer
- protected static <IN> IN invokeCallbackOrReturn(Consumer<IN> consumer, IN v)
protected IN doBufferDecode(Buffer buffer)
buffer
-