private static final byte OPCODE_PONG = 0xA;
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
if (msg instanceof WebSocketFrame) {
WebSocketFrame frame = (WebSocketFrame) msg;
ChannelBuffer data = frame.getBinaryData();
ChannelBuffer encoded =
channel.getConfig().getBufferFactory().getBuffer(
data.order(), data.readableBytes() + 6);
byte opcode;
if(frame instanceof Ping) {
opcode = OPCODE_PING;
} else if(frame instanceof Pong) {
opcode = OPCODE_PONG;
} else {
opcode = frame.isText() ? OPCODE_TEXT : OPCODE_BINARY;
}
encoded.writeByte(0x80 | opcode);
int length = data.readableBytes();
if (length < 126) {