com.github.fmjsjx.libnetty.resp.RedisRequestDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libnetty-resp Show documentation
Show all versions of libnetty-resp Show documentation
A set of some useful libraries based on netty4.1.x.
package com.github.fmjsjx.libnetty.resp;
import static com.github.fmjsjx.libnetty.resp.RespConstants.EOL_LENGTH;
import static com.github.fmjsjx.libnetty.resp.RespConstants.RESP_MESSAGE_MAX_LENGTH;
import java.util.ArrayList;
import java.util.List;
import com.github.fmjsjx.libnetty.resp.exception.RespDecoderException;
import io.netty.buffer.ByteBuf;
import io.netty.util.ByteProcessor;
/**
* Decodes {@link ByteBuf}s to {@link RedisRequest}s.
*
* @since 1.0
*
* @author MJ Fang
*/
public class RedisRequestDecoder extends RespMessageDecoder {
private static final RespDecoderException REDIS_REQUEST_ELEMENTS_ONLY_SUPPORT_BULK_STRINGS = new RespDecoderException(
"redis request elements only support Bulk Strings");
private final boolean supportInlineCommand;
private int arraySize;
private int currentBulkStringLength;
private ArrayList bulkStrings;
/**
* Constructs a new {@link RedisRequestDecoder} using default
* {@code maxInlineMessageLength} ({@code 65536}) and does not support inline
* command.
*/
public RedisRequestDecoder() {
this(false);
}
/**
* Constructs a new {@link RedisRequestDecoder} using default
* {@code maxInlineMessageLength} ({@code 65536}).
*
* @param supportInlineCommand if {@code true} then this decoder will support
* inline command
*/
public RedisRequestDecoder(boolean supportInlineCommand) {
this(supportInlineCommand, RespConstants.RESP_INLINE_MESSAGE_MAX_LENGTH);
}
/**
* Constructs a new {@link RedisRequestDecoder} using specified
* {@code maxInlineMessageLength}.
*
* @param supportInlineCommand if {@code true} then this decoder will support
* inline command
* @param maxInlineMessageLength the maximum length of in-line messages
*/
public RedisRequestDecoder(boolean supportInlineCommand, int maxInlineMessageLength) {
super(maxInlineMessageLength);
this.supportInlineCommand = supportInlineCommand;
}
@Override
protected boolean decodeInline(ByteBuf in, List