Home / Type/ RedisMessageType Type — netty Architecture

RedisMessageType Type — netty Architecture

Architecture documentation for the RedisMessageType type/interface in RedisMessageType.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2845bace_bdbb_2d45_ceae_a6915fa9c87b["RedisMessageType"]
  b2585548_f38d_ea10_4cdc_3f955a9d40e3["RedisMessageType.java"]
  2845bace_bdbb_2d45_ceae_a6915fa9c87b -->|defined in| b2585548_f38d_ea10_4cdc_3f955a9d40e3
  style 2845bace_bdbb_2d45_ceae_a6915fa9c87b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-redis/src/main/java/io/netty/handler/codec/redis/RedisMessageType.java lines 24–99

@UnstableApi
public enum RedisMessageType {

    INLINE_COMMAND(null, true),
    SIMPLE_STRING((byte) '+', true),
    ERROR((byte) '-', true),
    INTEGER((byte) ':', true),
    BULK_STRING((byte) '$', false),
    ARRAY_HEADER((byte) '*', false);

    private final Byte value;
    private final boolean inline;

    RedisMessageType(Byte value, boolean inline) {
        this.value = value;
        this.inline = inline;
    }

    /**
     * Returns length of this type.
     */
    public int length() {
        return value != null ? RedisConstants.TYPE_LENGTH : 0;
    }

    /**
     * Returns {@code true} if this type is inline type, or returns {@code false}. If this is {@code true},
     * this type doesn't have length field.
     */
    public boolean isInline() {
        return inline;
    }

    /**
     * Determine {@link RedisMessageType} based on the type prefix {@code byte} read from given the buffer.
     */
    public static RedisMessageType readFrom(ByteBuf in, boolean decodeInlineCommands) {
        final int initialIndex = in.readerIndex();
        final RedisMessageType type = valueOf(in.readByte());
        if (type == INLINE_COMMAND) {
            if (!decodeInlineCommands) {
                throw new RedisCodecException("Decoding of inline commands is disabled");
            }
            // reset index to make content readable again
            in.readerIndex(initialIndex);
        }
        return type;
    }

    /**
     * Write the message type's prefix to the given buffer.
     */
    public void writeTo(ByteBuf out) {
        if (value == null) {
            return;
        }
        out.writeByte(value.byteValue());
    }

    private static RedisMessageType valueOf(byte value) {
        switch (value) {
        case '+':
            return SIMPLE_STRING;
        case '-':
            return ERROR;
        case ':':
            return INTEGER;
        case '$':
            return BULK_STRING;
        case '*':
            return ARRAY_HEADER;
        default:
            return INLINE_COMMAND;
        }
    }
}

Frequently Asked Questions

What is the RedisMessageType type?
RedisMessageType is a type/interface in the netty codebase, defined in codec-redis/src/main/java/io/netty/handler/codec/redis/RedisMessageType.java.
Where is RedisMessageType defined?
RedisMessageType is defined in codec-redis/src/main/java/io/netty/handler/codec/redis/RedisMessageType.java at line 24.

Analyze Your Own Codebase

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

Try Supermodel Free