@Override
protected boolean onEncode(Buffer outbuf)
{
BufferHelper.writeVarInt(outbuf, type.getValue());
Buffer content = new Buffer(256);
ev.encode(content);
byte[] raw = content.getRawBuffer();
switch (type)
{
case NONE:
{
BufferHelper.writeVarInt(outbuf, content.readableBytes());
outbuf.write(raw,content.getReadIndex(), content.readableBytes());
break;
}
case QUICKLZ:
{
try
{
byte[] newbuf = QuickLZ.compress(raw,
content.getReadIndex(), content.readableBytes(), 1);
BufferHelper.writeVarInt(outbuf, newbuf.length);
outbuf.write(newbuf);
}
catch (Exception e)
{
//logger.error("Failed to compress by QuickLZ.", e);
return false;
}
break;
}
case FASTLZ:
{
byte[] newbuf = new byte[raw.length];
JFastLZ fastlz = new JFastLZ();
int afterCompress;
try
{
afterCompress = fastlz.fastlzCompress(raw,
content.getReadIndex(), content.readableBytes(),
newbuf, 0, newbuf.length);
BufferHelper.writeVarInt(outbuf, afterCompress);
outbuf.write(newbuf, 0, afterCompress);
}
catch (IOException e)
{
//logger.error("Failed to compress by FastLZ.", e);
return false;
}
break;
}
case SNAPPY:
{
try
{
byte[] newbuf = new byte[Snappy.maxCompressedLength(content.readableBytes())];
int len = Snappy.compress(raw,
content.getReadIndex(), content.readableBytes(), newbuf, 0);
// SnappyBuffer newbuf = SnappyCompressor.compress(raw,
// content.getReadIndex(), content.readableBytes());
BufferHelper.writeVarInt(outbuf, len);
outbuf.write(newbuf, 0, len);
}
catch (Exception e)
{
//logger.error("Failed to compress by Snappy.", e);
return false;
}
break;
}
case LZF:
{
try
{
byte[] newbuf = LZFEncoder.encode(raw,
content.readableBytes());
BufferHelper.writeVarInt(outbuf, newbuf.length);
outbuf.write(newbuf);
}
catch (Exception e)
{