Package io.lettuce.core.codec
Interface ToByteBufEncoder<K,V>
-
- All Known Implementing Classes:
ByteArrayCodec
,StringCodec
,Utf8StringCodec
public interface ToByteBufEncoder<K,V>
Optimized encoder that encodes keys and values directly on aByteBuf
. This encoder does not allocate buffers, it just encodes data to existing buffers.Classes implementing
ToByteBufEncoder
are required to implementRedisCodec
as well. You should implement also theRedisCodec.encodeKey(Object)
andRedisCodec.encodeValue(Object)
methods to ensure compatibility for users that access theRedisCodec
API only.- Since:
- 4.3
- Author:
- Mark Paluch, shikharid
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
encodeKey(K key, ByteBuf target)
Encode the key for output to redis.void
encodeValue(V value, ByteBuf target)
Encode the value for output to redis.int
estimateSize(Object keyOrValue)
Estimates the size of the resulting byte stream.default boolean
isEstimateExact()
Returnstrue
ifestimateSize(Object)
returns exact size This is used as an optimization to reduce memory allocations when encoding data.
-
-
-
Method Detail
-
encodeKey
void encodeKey(K key, ByteBuf target)
Encode the key for output to redis.- Parameters:
key
- the key, may benull
.target
- the target buffer, must not benull
.
-
encodeValue
void encodeValue(V value, ByteBuf target)
Encode the value for output to redis.- Parameters:
value
- the value, may benull
.target
- the target buffer, must not benull
.
-
estimateSize
int estimateSize(Object keyOrValue)
Estimates the size of the resulting byte stream. This method is called for keys and values to estimate the size for the temporary buffer to allocate.- Parameters:
keyOrValue
- the key or value, may benull
.- Returns:
- the estimated number of bytes in the encoded representation.
-
isEstimateExact
default boolean isEstimateExact()
Returnstrue
ifestimateSize(Object)
returns exact size This is used as an optimization to reduce memory allocations when encoding data.- Returns:
true
ifestimateSize(Object)
returns exact size.- Since:
- 6.3.2
-
-