mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-22 02:07:26 +07:00
Moved ByteToMessageDecoder to it's own declared class
This commit is contained in:
parent
e05e9bebc6
commit
70cf9d016a
@ -75,19 +75,7 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
||||
Main.this.endpoint = endpoint;
|
||||
ch.pipeline()
|
||||
.addFirst(connectionLimiter)
|
||||
.addLast(new ByteToMessageDecoder() {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (in.readableBytes() < 4) return;
|
||||
in.markReaderIndex();
|
||||
final int length = in.readIntLE();
|
||||
if (in.readableBytes() < length) {
|
||||
in.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
out.add(in.readRetainedSlice(length));
|
||||
}
|
||||
})
|
||||
.addLast(new SizePrefixedDecoder())
|
||||
.addLast(new EndpointedChannelHandler<>(ByteBuf.class, endpoint))
|
||||
;
|
||||
}
|
||||
@ -253,4 +241,18 @@ public class Main extends ApplicationAdapter implements PacketProcessor {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SizePrefixedDecoder extends ByteToMessageDecoder {
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (in.readableBytes() < 4) return;
|
||||
in.markReaderIndex();
|
||||
final int length = in.readIntLE();
|
||||
if (in.readableBytes() < length) {
|
||||
in.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
out.add(in.readRetainedSlice(length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user