import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
public class MessageDecoder extends ReplayingDecoder<DecoderState> {
private int length;
public MessageDecoder()
{
super(DecoderState.READ_LENGTH);
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception{
System.out.println(buf.readableBytes());
switch(state()){
case READ_LENGTH:
length=buf.readInt();
System.out.println("length is: "+length);
checkpoint(DecoderState.READ_CONTENT);
case READ_CONTENT:
ByteBuf frame = buf.readBytes(length);
checkpoint(DecoderState.READ_LENGTH);
out.add(frame);
break;
default:
throw new Error("Shouldn't reach here");
}
}
}And when the remote peer sends only 4 bytes, in Eclipse console i see that System.out.println(buf.readableBytes()); shows me that 2147483647 bytes are available. Without replaying decoder all is good.
Why it so?--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/926ac24f-4100-491e-bdcd-a9784ce31606%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/f68d7f6e-b0fa-4d56-8dba-7fd6331a7a90%40googlegroups.com.
public class Test {
public static void main(String[] args) {
System.err.println(ByteBufUtil.swapInt(1));
}
}
--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/534ac82f-2c3c-47bc-bf08-a3963df8b4fa%40googlegroups.com.
Hey there, I use ReplayingDecoder from the official Netty tutorial, here is the code