Example usage for io.netty.handler.codec TooLongFrameException TooLongFrameException

List of usage examples for io.netty.handler.codec TooLongFrameException TooLongFrameException

Introduction

In this page you can find the example usage for io.netty.handler.codec TooLongFrameException TooLongFrameException.

Prototype

public TooLongFrameException() 

Source Link

Document

Creates a new instance.

Usage

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);
}