public RemotingCommand decode()

in impl/src/main/java/org/apache/rocketmq/remoting/impl/netty/handler/Decoder.java [75:97]


    public RemotingCommand decode(final RemotingBuffer wrapper, final int originReaderIndex) {
        // Full message isn't available yet, return nothing for now
        if (wrapper.readableBytes() < CodecHelper.MIN_PROTOCOL_LEN - 1 /*MagicCode*/) {
            wrapper.setReaderIndex(originReaderIndex);
            return null;
        }

        int totalLength = wrapper.readInt();

        if (totalLength <= 0) {
            throw new RemotingCodecException("Illegal total length " + totalLength);
        }

        if (totalLength > CodecHelper.PACKET_MAX_LEN) {
            throw new RemotingCodecException(String.format("Total length %d is more than limit %d", totalLength, CodecHelper.PACKET_MAX_LEN));
        }

        if (wrapper.readableBytes() < totalLength - 1 /*MagicCode*/ - 4 /*TotalLen*/) {
            wrapper.setReaderIndex(originReaderIndex);
            return null;
        }
        return CodecHelper.decode(wrapper);
    }