@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
@Override public ByteBuf encode(Object in) throws IOException { ByteBuf buf = innerCodec.getValueEncoder().encode(in); ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); try { int chunksAmount = (int)Math.ceil(buf.readableBytes() / (double)Short.MAX_VALUE); for (int i = 1; i <= chunksAmount; i++) { int chunkSize = Math.min(Short.MAX_VALUE, buf.readableBytes()); ByteBuf chunk = buf.readSlice(chunkSize); int lenIndex = out.writerIndex(); out.writeInt(0); snappyEncoder.get().encode(chunk, out, chunk.readableBytes()); int compressedDataLength = out.writerIndex() - 4 - lenIndex; out.setInt(lenIndex, compressedDataLength); } return out; } finally { buf.release(); snappyEncoder.get().reset(); } } };
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;
ByteBuf slice = in.readSlice(Short.MAX_VALUE); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, Short.MAX_VALUE); setChunkLength(out, lengthIdx); dataLength -= Short.MAX_VALUE; ByteBuf slice = in.readSlice(dataLength); calculateAndWriteChecksum(slice, out); snappy.encode(slice, out, dataLength); setChunkLength(out, lengthIdx); break;