public Packet readFrom(ByteBuffer src) {
        if (!headerComplete) {
            if (src.remaining() < HEADER_SIZE) {
                return null;
            }

            byte version = src.get();
            if (VERSION != version) {
                throw new IllegalArgumentException("Packet versions are not matching! Expected -> "
                        + VERSION + ", Incoming -> " + version);
            }

            flags = src.getChar();
            partitionId = src.getInt();
            size = src.getInt();
            headerComplete = true;
        }

        if (readValue(src)) {
            Packet packet = new Packet(payload, partitionId).resetFlagsTo(flags);
            reset();
            return packet;
        } else {
            return null;
        }
    }
public Packet readFrom ( ByteBuffer src ) { if ( ! headerComplete ) { if ( src . remaining ( ) < HEADER_SIZE ) { return null ; } byte version = src . get ( ) ; if ( VERSION != version ) { throw new IllegalArgumentException ( "Packet versions are not matching! Expected -> " + VERSION + ", Incoming -> " + version ) ; } flags = src . getChar ( ) ; partitionId = src . getInt ( ) ; size = src . getInt ( ) ; headerComplete = true ; } if ( readValue ( src ) ) { Packet packet = new Packet ( payload , partitionId ) . resetFlagsTo ( flags ) ; reset ( ) ; return packet ; } else { return null ; } }
Reads the packet data from the supplied {@code ByteBuffer}. The buffer may not contain the complete packet.
If this method returns {@code false}, it should be called again to read more packet data.

@param src the source byte buffer
@return the read Packet if all the packet's data is now read; {@code null} otherwise.