codec-memcache: increase default buffer size and only encode extras if set.

This commit is contained in:
Michael Nitschinger 2013-12-05 13:36:29 +01:00 committed by Trustin Lee
parent bea2acdf12
commit 215e75c7d9

View File

@ -27,9 +27,14 @@ import io.netty.util.CharsetUtil;
public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader> public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage<H>, H extends BinaryMemcacheMessageHeader>
extends MemcacheObjectEncoder<M> { extends MemcacheObjectEncoder<M> {
/**
* Every binary memcache message has at least a 24 bytes header.
*/
public static final int DEFAULT_BUFFER_SIZE = 24;
@Override @Override
protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) { protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) {
ByteBuf buf = ctx.alloc().buffer(); ByteBuf buf = ctx.alloc().buffer(DEFAULT_BUFFER_SIZE);
encodeHeader(buf, msg.getHeader()); encodeHeader(buf, msg.getHeader());
encodeExtras(buf, msg.getExtras()); encodeExtras(buf, msg.getExtras());
@ -45,7 +50,7 @@ public abstract class BinaryMemcacheEncoder<M extends BinaryMemcacheMessage<H>,
* @param extras the extras to encode. * @param extras the extras to encode.
*/ */
private static void encodeExtras(ByteBuf buf, ByteBuf extras) { private static void encodeExtras(ByteBuf buf, ByteBuf extras) {
if (extras == null) { if (extras == null || extras.readableBytes() == 0) {
return; return;
} }