Skip to content

Instantly share code, notes, and snippets.

@trustin
Created July 13, 2012 03:47
Show Gist options
  • Save trustin/3102590 to your computer and use it in GitHub Desktop.
Save trustin/3102590 to your computer and use it in GitHub Desktop.
public void inboundBufferUpdated(ChannelHandlerContext ctx) {
Queue<MyMessage> in = ctx.inboundMessageBuffer();
Queue<MyNewMessage> out = ctx.nextInboundMessageBuffer();
for (;;) {
MyMessage m = in.poll();
if (m == null) {
break;
}
MyNewMessage decoded = decode(m);
out.add(decoded);
}
ctx.fireInboundBufferUpdated();
}
public void flush(ChannelHandlerContext ctx, ChannelFuture future) {
Queue<MyNewMessage> in = ctx.outboundMessageBuffer();
Queue<MyMessage> out = ctx.nextOutboundMessageBuffer();
for (;;) {
MyNewMessage m = in.poll();
if (m == null) {
break;
}
MyMessage encoded = encode(m);
out.add(encoded);
}
ctx.flush(future);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment