Source:
protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 1) { return null; } if (buf.getByte(buf.readerIndex()) == 0x7F) { return buf.readRetainedSlice(1); } if (protocolDecoder.getFlexDataSize() > 0) { if (buf.readableBytes() > MAX_FRAME_LENGTH) { throw new TooLongFrameException(); } if (buf.readableBytes() > FLEX_HEADER_LENGTH) { int length = 0; String type = buf.toString(buf.readerIndex(), 2, StandardCharsets.US_ASCII); switch (type) { case "~A": length = protocolDecoder.getFlexDataSize() * buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH) + 1 + 1; break; case "~T": length = protocolDecoder.getFlexDataSize() + 4 + 1; break; case "~C": length = protocolDecoder.getFlexDataSize() + 1; break; case "~E": length++; for (int i = 0; i < buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH); i++) { if (buf.readableBytes() > FLEX_HEADER_LENGTH + length + 1) { length += buf.getUnsignedShort(length + FLEX_HEADER_LENGTH) + 2; } else { return null; } } length++; break; case "~X": length = buf.getUnsignedShortLE(buf.readerIndex() + FLEX_HEADER_LENGTH) + 4 + 1; break; default: return null; } if (buf.readableBytes() >= FLEX_HEADER_LENGTH + length) { return buf.readRetainedSlice(buf.readableBytes()); } } } else { if (buf.readableBytes() < NTCB_HEADER_LENGTH) { return null; } int length = buf.getUnsignedShortLE(buf.readerIndex() + NTCB_LENGTH_OFFSET); if (buf.readableBytes() >= NTCB_HEADER_LENGTH + length) { if (buf.readableBytes() > MAX_FRAME_LENGTH) { throw new TooLongFrameException(); } return buf.readRetainedSlice(NTCB_HEADER_LENGTH + length); } } return null; }

Target:
protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 1) { return null; } if (buf.readableBytes() > MAX_FRAME_LENGTH) { throw new TooLongFrameException(); } if (buf.getByte(buf.readerIndex()) == 0x7F) { return buf.readRetainedSlice(1); } if (ctx != null) { NavisProtocolDecoder protocolDecoder = BasePipelineFactory.getHandler(ctx.pipeline(), NavisProtocolDecoder.class); if (protocolDecoder != null) { flexDataSize = protocolDecoder.getFlexDataSize(); } } if (flexDataSize > 0) { if (buf.readableBytes() > FLEX_HEADER_LENGTH) { int length = 0; String type = buf.toString(buf.readerIndex(), 2, StandardCharsets.US_ASCII); switch (type) { case "~A": length = flexDataSize * buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH) + 1 + 1; break; case "~T": length = flexDataSize + 4 + 1; break; case "~C": length = flexDataSize + 1; break; case "~E": length++; for (int i = 0; i < buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH); i++) { if (buf.readableBytes() > FLEX_HEADER_LENGTH + length + 1) { length += buf.getUnsignedShort(length + FLEX_HEADER_LENGTH) + 2; } else { return null; } } length++; break; case "~X": length = buf.getUnsignedShortLE(buf.readerIndex() + FLEX_HEADER_LENGTH) + 4 + 1; break; default: return null; } if (buf.readableBytes() >= FLEX_HEADER_LENGTH + length) { return buf.readRetainedSlice(buf.readableBytes()); } } } else { if (buf.readableBytes() < NTCB_HEADER_LENGTH) { return null; } int length = buf.getUnsignedShortLE(buf.readerIndex() + NTCB_LENGTH_OFFSET); if (buf.readableBytes() >= NTCB_HEADER_LENGTH + length) { return buf.readRetainedSlice(NTCB_HEADER_LENGTH + length); } } return null; }