List of usage examples for io.netty.handler.codec TooLongFrameException TooLongFrameException
public TooLongFrameException()
From source file:io.awacs.protocol.binary.BinaryMessageDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int readable = in.readableBytes(); if (readable > BinaryMessage.MAX_PACKET_SIZE) { in.skipBytes(readable);//from w w w . j ava 2s. co m throw new TooLongFrameException(); } //??? if (readable < 16) { return; } byte[] headerBytes = new byte[16]; in.readBytes(headerBytes, 0, 16); int bodyLength = BinaryMessage.bodyLength(headerBytes); //body??body if (in.readableBytes() < bodyLength) { in.resetReaderIndex(); return; } byte[] bodyBytes = new byte[bodyLength]; in.readBytes(bodyBytes, 0, bodyLength); // byte[] copy = new byte[16 + bodyLength]; // System.arraycopy(headerBytes, 0, copy, 0, 16); // System.arraycopy(bodyBytes, 0, copy, 16, bodyLength); Message m = BinaryMessage.parse(headerBytes, bodyBytes); in.markReaderIndex(); out.add(m); }