def lz4_encode(payload):
    data = lz4f.compressFrame(payload)  # pylint: disable-msg=no-member
    # Kafka's LZ4 code has a bug in its header checksum implementation
    header_size = 7
    if isinstance(data[4], int):
        flg = data[4]
    else:
        flg = ord(data[4])
    content_size_bit = ((flg >> 3) & 1)
    if content_size_bit:
        header_size += 8

    # This is the incorrect hc
    hc = xxhash.xxh32(data[0:header_size-1]).digest()[-2:-1]  # pylint: disable-msg=no-member

    return b''.join([
        data[0:header_size-1],
        hc,
        data[header_size:]
    ])
dataset/ETHPy150Open dpkp/kafka-python/kafka/codec.py/lz4_encode/original