Package io.lettuce.core.codec
Class ByteArrayCodec
- java.lang.Object
-
- io.lettuce.core.codec.ByteArrayCodec
-
- All Implemented Interfaces:
RedisCodec<byte[],byte[]>
,ToByteBufEncoder<byte[],byte[]>
public class ByteArrayCodec extends Object implements RedisCodec<byte[],byte[]>, ToByteBufEncoder<byte[],byte[]>
ARedisCodec
that uses plain byte arrays without further transformations.- Since:
- 3.3
- Author:
- Mark Paluch, shikharid
-
-
Field Summary
Fields Modifier and Type Field Description static ByteArrayCodec
INSTANCE
-
Constructor Summary
Constructors Constructor Description ByteArrayCodec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
decodeKey(ByteBuffer bytes)
Decode the key output by redis.byte[]
decodeValue(ByteBuffer bytes)
Decode the value output by redis.ByteBuffer
encodeKey(byte[] key)
Encode the key for output to redis.void
encodeKey(byte[] key, ByteBuf target)
Encode the key for output to redis.ByteBuffer
encodeValue(byte[] value)
Encode the value for output to redis.void
encodeValue(byte[] value, ByteBuf target)
Encode the value for output to redis.int
estimateSize(Object keyOrValue)
Estimates the size of the resulting byte stream.boolean
isEstimateExact()
Returnstrue
ifToByteBufEncoder.estimateSize(Object)
returns exact size This is used as an optimization to reduce memory allocations when encoding data.
-
-
-
Field Detail
-
INSTANCE
public static final ByteArrayCodec INSTANCE
-
-
Method Detail
-
encodeKey
public void encodeKey(byte[] key, ByteBuf target)
Description copied from interface:ToByteBufEncoder
Encode the key for output to redis.- Specified by:
encodeKey
in interfaceToByteBufEncoder<byte[],byte[]>
- Parameters:
key
- the key, may benull
.target
- the target buffer, must not benull
.
-
encodeValue
public void encodeValue(byte[] value, ByteBuf target)
Description copied from interface:ToByteBufEncoder
Encode the value for output to redis.- Specified by:
encodeValue
in interfaceToByteBufEncoder<byte[],byte[]>
- Parameters:
value
- the value, may benull
.target
- the target buffer, must not benull
.
-
estimateSize
public int estimateSize(Object keyOrValue)
Description copied from interface:ToByteBufEncoder
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.- Specified by:
estimateSize
in interfaceToByteBufEncoder<byte[],byte[]>
- Parameters:
keyOrValue
- the key or value, may benull
.- Returns:
- the estimated number of bytes in the encoded representation.
-
isEstimateExact
public boolean isEstimateExact()
Description copied from interface:ToByteBufEncoder
Returnstrue
ifToByteBufEncoder.estimateSize(Object)
returns exact size This is used as an optimization to reduce memory allocations when encoding data.- Specified by:
isEstimateExact
in interfaceToByteBufEncoder<byte[],byte[]>
- Returns:
true
ifToByteBufEncoder.estimateSize(Object)
returns exact size.
-
decodeKey
public byte[] decodeKey(ByteBuffer bytes)
Description copied from interface:RedisCodec
Decode the key output by redis.- Specified by:
decodeKey
in interfaceRedisCodec<byte[],byte[]>
- Parameters:
bytes
- Raw bytes of the key, must not benull
.- Returns:
- The decoded key, may be
null
.
-
decodeValue
public byte[] decodeValue(ByteBuffer bytes)
Description copied from interface:RedisCodec
Decode the value output by redis.- Specified by:
decodeValue
in interfaceRedisCodec<byte[],byte[]>
- Parameters:
bytes
- Raw bytes of the value, must not benull
.- Returns:
- The decoded value, may be
null
.
-
encodeKey
public ByteBuffer encodeKey(byte[] key)
Description copied from interface:RedisCodec
Encode the key for output to redis.- Specified by:
encodeKey
in interfaceRedisCodec<byte[],byte[]>
- Parameters:
key
- the key, may benull
.- Returns:
- The encoded key, never
null
.
-
encodeValue
public ByteBuffer encodeValue(byte[] value)
Description copied from interface:RedisCodec
Encode the value for output to redis.- Specified by:
encodeValue
in interfaceRedisCodec<byte[],byte[]>
- Parameters:
value
- the value, may benull
.- Returns:
- The encoded value, never
null
.
-
-