use of org.rx.io.MemoryStream in project rxlib by RockyLOMO.
the class Udp2rawHandler method zip.
private void zip(ByteBuf outBuf, ByteBuf inBuf) {
if (inBuf.readableBytes() < gzipMinLength) {
outBuf.writeByte(1);
outBuf.writeBytes(inBuf);
return;
}
outBuf.writeByte(2);
int w = outBuf.writerIndex();
int unzipLen = inBuf.readableBytes();
try (GZIPStream stream = new GZIPStream(new MemoryStream(outBuf, true), true)) {
stream.write(inBuf);
}
outBuf.readerIndex(0);
log.info("UDP2RAW ZIP {} => {}", unzipLen, outBuf.writerIndex() - w);
}
use of org.rx.io.MemoryStream in project rxlib by RockyLOMO.
the class UdpClient method serialize.
DatagramPacket serialize(InetSocketAddress remoteAddress, Object message) {
MemoryStream stream = new MemoryStream(true);
Serializer.DEFAULT.serialize(message, stream);
ByteBuf buf = stream.getBuffer().readerIndex(0);
if (buf.readableBytes() > 1024) {
log.warn("Too large packet size 4 udp. {} > 1024", buf.readableBytes());
}
return new DatagramPacket(buf, remoteAddress);
}
Aggregations