クライアントが送信するバイトを処理するデコーダを作成しました。ここ はそれがReplayingDecoderがデコード時に例外をスローする
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");
}
}
}
され、クライアントがバイト
io.netty.handler.codec.DecoderException送信するときには、次のエラーがスローされます:java.lang.IllegalArgumentExceptionが:minimumReadableBytes:-603652096は(期待を:> = 0)io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:431) io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:245)の at io.netty .channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafeでio.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962) でio.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278) で。読み取り(AbstractNioByteChannel.java:131)io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)で io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)で でio.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371) at io.netty.util.concurrent.SingleThreadEventExecutor $ 2 .run(SingleThreadEventExecutor.java:112) atコードは、公式ドキュメントhttp://netty.io/4.0/api/io/netty/handler/codec/ReplayingDecoder.htmlからのものであることをjava.lang.Thread.runでio.netty.util.concurrent.DefaultThreadFactory $ DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) (不明なソース)
ので、私は本当にドンなぜそれが動作しないのか理解していない
btw私は4バイトを送ったとき、2147483647バイト – user2686299