public static RequestHeader parse(ByteBuffer buffer) {
        short apiKey = -1;
        try {
            // We derive the header version from the request api version, so we read that first.
            // The request api version is part of `RequestHeaderData`, so we reset the buffer position after the read.
            int bufferStartPositionForHeader = buffer.position();
            apiKey = buffer.getShort();
            short apiVersion = buffer.getShort();
            short headerVersion = ApiKeys.forId(apiKey).requestHeaderVersion(apiVersion);
            buffer.position(bufferStartPositionForHeader);
            final RequestHeaderData headerData = new RequestHeaderData(new ByteBufferAccessor(buffer), headerVersion);
            // Due to a quirk in the protocol, client ID is marked as nullable.
            // However, we treat a null client ID as equivalent to an empty client ID.
            if (headerData.clientId() == null) {
                headerData.setClientId("");
            }
            final RequestHeader header = new RequestHeader(headerData, headerVersion);
            // Size of header is calculated by the shift in the position of buffer's start position during parsing.
            // Prior to parsing, the buffer's start position points to header data and after the parsing operation
            // the buffer's start position points to api message. For more information on how the buffer is
            // constructed, see RequestUtils#serialize()
            header.size = Math.max(buffer.position() - bufferStartPositionForHeader, 0);
            return header;
        } catch (UnsupportedVersionException e) {
            throw new InvalidRequestException("Unknown API key " + apiKey, e);
        } catch (Throwable ex) {
            throw new InvalidRequestException("Error parsing request header. Our best guess of the apiKey is: " +
                    apiKey, ex);
        }
    }
Returns the size of {@link RequestHeader} in bytes.

Calls to this method are idempotent and inexpensive since it returns the cached value of size after the first
invocation.
clients/src/main/java/org/apache/kafka/common/requests/RequestHeader.java