public final class DefaultCodecs extends Object implements Codecs, CodecRegistry
Codec
implementation. Delegates to type-specific codec implementations.
Codecs can be configured to prefer or avoid attached buffers for certain data types. Using attached buffers is more memory-efficient as data doesn't need to be copied. In turn, attached buffers require release or consumption to avoid memory leaks. By default, codecs don't use attached buffers to minimize the risk of memory leaks.
Constructor and Description |
---|
DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator)
Create a new instance of
DefaultCodecs preferring detached (copied buffers). |
DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator,
boolean preferAttachedBuffers)
Create a new instance of
DefaultCodecs preferring detached (copied buffers). |
Modifier and Type | Method and Description |
---|---|
void |
addFirst(Codec<?> codec)
Register codec before all other codecs.
|
void |
addLast(Codec<?> codec)
Register codec after all other codecs.
|
<T> T |
decode(io.netty.buffer.ByteBuf buffer,
int dataType,
io.r2dbc.postgresql.message.Format format,
Class<? extends T> type)
Decode a data to a value.
|
io.r2dbc.postgresql.client.Parameter |
encode(Object value)
Encode a value.
|
io.r2dbc.postgresql.client.Parameter |
encodeNull(Class<?> type)
Encode a
null value. |
Iterator<Codec<?>> |
iterator() |
Class<?> |
preferredType(int dataType,
io.r2dbc.postgresql.message.Format format)
Returns the preferred Java type for a given data type and format.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator)
DefaultCodecs
preferring detached (copied buffers).byteBufAllocator
- the ByteBufAllocator
to use for encodingpublic DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers)
DefaultCodecs
preferring detached (copied buffers).byteBufAllocator
- the ByteBufAllocator
to use for encodingpreferAttachedBuffers
- whether to prefer attached (pooled) buffers
. Use false
(default) to use detached buffers which minimize the risk of memory leaks.public void addFirst(Codec<?> codec)
CodecRegistry
addFirst
in interface CodecRegistry
codec
- the codec to registerpublic void addLast(Codec<?> codec)
CodecRegistry
addLast
in interface CodecRegistry
codec
- the codec to register@Nullable public <T> T decode(@Nullable io.netty.buffer.ByteBuf buffer, int dataType, io.r2dbc.postgresql.message.Format format, Class<? extends T> type)
Codecs
public io.r2dbc.postgresql.client.Parameter encode(Object value)
Codecs
public io.r2dbc.postgresql.client.Parameter encodeNull(Class<?> type)
Codecs
null
value.encodeNull
in interface Codecs
type
- the type to encodepublic Class<?> preferredType(int dataType, io.r2dbc.postgresql.message.Format format)
Codecs
preferredType
in interface Codecs
dataType
- the data type fo the dataformat
- the format of the dataCopyright © 2021. All rights reserved.