Module lettuce.core

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 a ByteBuf. This encoder does not allocate buffers, it just encodes data to existing buffers.

Classes implementing ToByteBufEncoder are required to implement RedisCodec as well. You should implement also the RedisCodec.encodeKey(Object) and RedisCodec.encodeValue(Object) methods to ensure compatibility for users that access the RedisCodec API only.

Since:
4.3
Author:
Mark Paluch
  • Method Summary

    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.
  • Method Details

    • encodeKey

      void encodeKey​(K key, ByteBuf target)
      Encode the key for output to redis.
      Parameters:
      key - the key, may be null.
      target - the target buffer, must not be null.
    • encodeValue

      void encodeValue​(V value, ByteBuf target)
      Encode the value for output to redis.
      Parameters:
      value - the value, may be null.
      target - the target buffer, must not be null.
    • 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 be null.
      Returns:
      the estimated number of bytes in the encoded representation.