Class DefaultCodecs
java.lang.Object
io.r2dbc.postgresql.codec.DefaultCodecs
- All Implemented Interfaces:
CodecRegistry, Codecs, Iterable<Codec<?>>
The default
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 Summary
ConstructorsConstructorDescriptionDefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator) Create a new instance ofDefaultCodecspreferring detached (copied buffers).DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers) Create a new instance ofDefaultCodecspreferring detached (copied buffers).DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers, CodecConfiguration configuration) Create a new instance ofDefaultCodecs. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister codec before all other codecs.voidRegister codec after all other codecs.<T> @Nullable Tdecode(@Nullable 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.EncodedParameterEncode a value.io.r2dbc.postgresql.client.EncodedParameterencodeNull(Class<?> type) Encode anullvalue.iterator()Class<?> preferredType(int dataType, io.r2dbc.postgresql.message.Format format) Returns the preferred Java type for a given data type and format.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
DefaultCodecs
public DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator) Create a new instance ofDefaultCodecspreferring detached (copied buffers).- Parameters:
byteBufAllocator- theByteBufAllocatorto use for encoding
-
DefaultCodecs
public DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers) Create a new instance ofDefaultCodecspreferring detached (copied buffers).- Parameters:
byteBufAllocator- theByteBufAllocatorto use for encodingpreferAttachedBuffers- whether to prefer attached (pooled)buffers. Usefalse(default) to use detached buffers which minimize the risk of memory leaks.
-
DefaultCodecs
public DefaultCodecs(io.netty.buffer.ByteBufAllocator byteBufAllocator, boolean preferAttachedBuffers, CodecConfiguration configuration) Create a new instance ofDefaultCodecs.- Parameters:
byteBufAllocator- theByteBufAllocatorto use for encodingpreferAttachedBuffers- whether to prefer attached (pooled)buffers. Usefalse(default) to use detached buffers which minimize the risk of memory leaks.configuration- theCodecConfigurationto use for encoding/decoding
-
-
Method Details
-
addFirst
Description copied from interface:CodecRegistryRegister codec before all other codecs.- Specified by:
addFirstin interfaceCodecRegistry- Parameters:
codec- the codec to register
-
addLast
Description copied from interface:CodecRegistryRegister codec after all other codecs.- Specified by:
addLastin interfaceCodecRegistry- Parameters:
codec- the codec to register
-
decode
-
encode
-
encodeNull
Description copied from interface:CodecsEncode anullvalue.- Specified by:
encodeNullin interfaceCodecs- Parameters:
type- the type to encode- Returns:
- the encoded value
-
preferredType
Description copied from interface:CodecsReturns the preferred Java type for a given data type and format.- Specified by:
preferredTypein interfaceCodecs- Parameters:
dataType- the data type fo the dataformat- the format of the data- Returns:
- the preferred Java type for a given data type and format
-
iterator
-