Home / Class/ RedisDecoder Class — netty Architecture

RedisDecoder Class — netty Architecture

Architecture documentation for the RedisDecoder class in RedisDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2421b439_cffa_67ca_b872_bb582dd0dbf2["RedisDecoder"]
  b9aeddc0_c06c_00a2_5cad_700bb9950817["RedisDecoder.java"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|defined in| b9aeddc0_c06c_00a2_5cad_700bb9950817
  082de522_bf3e_4bf9_c830_8d69c8698510["RedisDecoder()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 082de522_bf3e_4bf9_c830_8d69c8698510
  04cf8633_8ce7_e5aa_352b_1b23a309052f["decode()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 04cf8633_8ce7_e5aa_352b_1b23a309052f
  fe09be93_7a87_7d9a_a4e2_1f26488d2f56["resetDecoder()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| fe09be93_7a87_7d9a_a4e2_1f26488d2f56
  512a30b0_3427_a559_4bf5_8b6b149fe4ea["decodeType()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 512a30b0_3427_a559_4bf5_8b6b149fe4ea
  f0bc4d3a_0846_bfbf_3cb8_e1666750a218["decodeInline()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| f0bc4d3a_0846_bfbf_3cb8_e1666750a218
  6d8b9b4b_2072_a961_76cb_8954875e821b["decodeLength()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 6d8b9b4b_2072_a961_76cb_8954875e821b
  1d4f1b51_c148_ce38_593c_4e951cf4f9b6["decodeBulkString()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 1d4f1b51_c148_ce38_593c_4e951cf4f9b6
  ac6bea2c_1fc9_64fa_127b_cc90adfb0557["decodeBulkStringEndOfLine()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| ac6bea2c_1fc9_64fa_127b_cc90adfb0557
  4dcee4b2_7f61_d951_b580_50f0852e5732["decodeBulkStringContent()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 4dcee4b2_7f61_d951_b580_50f0852e5732
  2960bd56_d12c_72f0_fad4_c3d3018db618["readEndOfLine()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 2960bd56_d12c_72f0_fad4_c3d3018db618
  ed1d2f76_8564_f576_4432_ddafa832113c["RedisMessage()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| ed1d2f76_8564_f576_4432_ddafa832113c
  5564d30e_5a08_eca2_76db_56705e5ba72a["ByteBuf()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 5564d30e_5a08_eca2_76db_56705e5ba72a
  24e865f9_bdd6_9dd8_56dc_9edb5828f082["parseRedisNumber()"]
  2421b439_cffa_67ca_b872_bb582dd0dbf2 -->|method| 24e865f9_bdd6_9dd8_56dc_9edb5828f082

Relationship Graph

Source Code

codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java lines 34–332

@UnstableApi
public final class RedisDecoder extends ByteToMessageDecoder {

    private final ToPositiveLongProcessor toPositiveLongProcessor = new ToPositiveLongProcessor();

    private final boolean decodeInlineCommands;
    private final int maxInlineMessageLength;
    private final RedisMessagePool messagePool;

    // current decoding states
    private State state = State.DECODE_TYPE;
    private RedisMessageType type;
    private int remainingBulkLength;

    private enum State {
        DECODE_TYPE,
        DECODE_INLINE, // SIMPLE_STRING, ERROR, INTEGER
        DECODE_LENGTH, // BULK_STRING, ARRAY_HEADER
        DECODE_BULK_STRING_EOL,
        DECODE_BULK_STRING_CONTENT,
    }

    /**
     * Creates a new instance with default {@code maxInlineMessageLength} and {@code messagePool}
     * and inline command decoding disabled.
     */
    public RedisDecoder() {
        this(false);
    }

    /**
     * Creates a new instance with default {@code maxInlineMessageLength} and {@code messagePool}.
     * @param decodeInlineCommands if {@code true}, inline commands will be decoded.
     */
    public RedisDecoder(boolean decodeInlineCommands) {
        this(RedisConstants.REDIS_INLINE_MESSAGE_MAX_LENGTH, FixedRedisMessagePool.INSTANCE, decodeInlineCommands);
    }

    /**
     * Creates a new instance with inline command decoding disabled.
     * @param maxInlineMessageLength the maximum length of inline message.
     * @param messagePool the predefined message pool.
     */
    public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool) {
        this(maxInlineMessageLength, messagePool, false);
    }

    /**
     * Creates a new instance.
     * @param maxInlineMessageLength the maximum length of inline message.
     * @param messagePool the predefined message pool.
     * @param decodeInlineCommands if {@code true}, inline commands will be decoded.
     */
    public RedisDecoder(int maxInlineMessageLength, RedisMessagePool messagePool, boolean decodeInlineCommands) {
        if (maxInlineMessageLength <= 0 || maxInlineMessageLength > RedisConstants.REDIS_MESSAGE_MAX_LENGTH) {
            throw new RedisCodecException("maxInlineMessageLength: " + maxInlineMessageLength +
                                          " (expected: <= " + RedisConstants.REDIS_MESSAGE_MAX_LENGTH + ")");
        }
        this.maxInlineMessageLength = maxInlineMessageLength;
        this.messagePool = messagePool;
        this.decodeInlineCommands = decodeInlineCommands;
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        try {
            for (;;) {
                switch (state) {
                case DECODE_TYPE:
                    if (!decodeType(in)) {
                        return;
                    }
                    break;
                case DECODE_INLINE:
                    if (!decodeInline(in, out)) {
                        return;
                    }
                    break;
                case DECODE_LENGTH:
                    if (!decodeLength(in, out)) {
                        return;

Frequently Asked Questions

What is the RedisDecoder class?
RedisDecoder is a class in the netty codebase, defined in codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java.
Where is RedisDecoder defined?
RedisDecoder is defined in codec-redis/src/main/java/io/netty/handler/codec/redis/RedisDecoder.java at line 34.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free