# Path: aiokafka/record/default_records.py
# class DefaultRecordBase:
# class _DefaultRecordBatchPy(DefaultRecordBase):
# class _DefaultRecordPy:
# class _DefaultRecordBatchBuilderPy(DefaultRecordBase):
# class _DefaultRecordMetadataPy:
#     HEADER_STRUCT = struct.Struct(
#         ">q"  # BaseOffset => Int64
#         "i"  # Length => Int32
#         "i"  # PartitionLeaderEpoch => Int32
#         "b"  # Magic => Int8
#         "I"  # CRC => Uint32
#         "h"  # Attributes => Int16
#         "i"  # LastOffsetDelta => Int32 // also serves as LastSequenceDelta
#         "q"  # FirstTimestamp => Int64
#         "q"  # MaxTimestamp => Int64
#         "q"  # ProducerId => Int64
#         "h"  # ProducerEpoch => Int16
#         "i"  # BaseSequence => Int32
#         "i"  # Records count => Int32
#     )
#     ATTRIBUTES_OFFSET = struct.calcsize(">qiibI")
#     CRC_OFFSET = struct.calcsize(">qiib")
#     AFTER_LEN_OFFSET = struct.calcsize(">qi")
#     CODEC_MASK = 0x07
#     CODEC_NONE = 0x00
#     CODEC_GZIP = 0x01
#     CODEC_SNAPPY = 0x02
#     CODEC_LZ4 = 0x03
#     CODEC_ZSTD = 0x04
#     TIMESTAMP_TYPE_MASK = 0x08
#     TRANSACTIONAL_MASK = 0x10
#     CONTROL_MASK = 0x20
#     LOG_APPEND_TIME = 1
#     CREATE_TIME = 0
#     NO_PARTITION_LEADER_EPOCH = -1
#     MAX_RECORD_OVERHEAD = 21
#     def _assert_has_codec(self, compression_type):
#     def __init__(self, buffer):
#     def base_offset(self):
#     def magic(self):
#     def crc(self):
#     def attributes(self):
#     def compression_type(self):
#     def timestamp_type(self):
#     def is_transactional(self):
#     def is_control_batch(self):
#     def last_offset_delta(self):
#     def first_timestamp(self):
#     def max_timestamp(self):
#     def producer_id(self):
#     def producer_epoch(self):
#     def base_sequence(self):
#     def next_offset(self):
#     def _maybe_uncompress(self):
#     def _read_msg(
#             self,
#             decode_varint=decode_varint):
#     def __iter__(self):
#     def __next__(self):
#     def validate_crc(self):
#     def __init__(self, offset, timestamp, timestamp_type, key, value, headers):
#     def offset(self):
#     def timestamp(self):
#     def timestamp_type(self):
#     def key(self):
#     def value(self):
#     def headers(self):
#     def checksum(self):
#     def __repr__(self):
#     def __init__(
#             self, magic, compression_type, is_transactional,
#             producer_id, producer_epoch, base_sequence, batch_size):
#     def _get_attributes(self, include_compression_type=True):
#     def append(self, offset, timestamp, key, value, headers,
#                # Cache for LOAD_FAST opcodes
#                encode_varint=encode_varint, size_of_varint=size_of_varint,
#                get_type=type, type_int=int, time_time=time.time,
#                byte_like=(bytes, bytearray, memoryview),
#                bytearray_type=bytearray, len_func=len, zero_len_varint=1
#                ):
#     def write_header(self, use_compression_type=True):
#     def _maybe_compress(self):
#     def build(self):
#     def size(self):
#     def size_in_bytes(self, offset, timestamp, key, value, headers):
#     def size_of(cls, key, value, headers):
#     def estimate_size_in_bytes(cls, key, value, headers):
#     def set_producer_state(self, producer_id, producer_epoch, base_sequence):
#     def producer_id(self):
#     def producer_epoch(self):
#     def base_sequence(self):
#     def __init__(self, offset, size, timestamp):
#     def offset(self):
#     def crc(self):
#     def size(self):
#     def timestamp(self):
#     def __repr__(self):


from unittest import mock
from kafka.errors import UnsupportedCodecError
from aiokafka.record.default_records import (
    DefaultRecordBatch, DefaultRecordBatchBuilder
)
import kafka.codec
import pytest
        producer_id=-1, producer_epoch=-1, base_sequence=-1,
        batch_size=1024)

    meta = builder.append(
        0, timestamp=None, key=None, value=b"M" * 2000, headers=[])
    assert meta.size > 0
    assert meta.crc is None
    assert meta.offset == 0
    assert meta.timestamp is not None
    assert len(builder.build()) > 2000

    builder = DefaultRecordBatchBuilder(
        magic=2, compression_type=0, is_transactional=0,
        producer_id=-1, producer_epoch=-1, base_sequence=-1,
        batch_size=1024)
    meta = builder.append(
        0, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is not None
    meta = builder.append(
        1, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is None
    meta = builder.append(
        2, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is None
    assert len(builder.build()) < 1000


@pytest.mark.parametrize("compression_type,name,checker_name", [
    (DefaultRecordBatch.CODEC_GZIP, "gzip", "has_gzip"),
    (DefaultRecordBatch.CODEC_SNAPPY, "snappy", "has_snappy"),

# Path: aiokafka/record/default_records.py
# class DefaultRecordBase:
# class _DefaultRecordBatchPy(DefaultRecordBase):
# class _DefaultRecordPy:
# class _DefaultRecordBatchBuilderPy(DefaultRecordBase):
# class _DefaultRecordMetadataPy:
#     HEADER_STRUCT = struct.Struct(
#         ">q"  # BaseOffset => Int64
#         "i"  # Length => Int32
#         "i"  # PartitionLeaderEpoch => Int32
#         "b"  # Magic => Int8
#         "I"  # CRC => Uint32
#         "h"  # Attributes => Int16
#         "i"  # LastOffsetDelta => Int32 // also serves as LastSequenceDelta
#         "q"  # FirstTimestamp => Int64
#         "q"  # MaxTimestamp => Int64
#         "q"  # ProducerId => Int64
#         "h"  # ProducerEpoch => Int16
#         "i"  # BaseSequence => Int32
#         "i"  # Records count => Int32
#     )
#     ATTRIBUTES_OFFSET = struct.calcsize(">qiibI")
#     CRC_OFFSET = struct.calcsize(">qiib")
#     AFTER_LEN_OFFSET = struct.calcsize(">qi")
#     CODEC_MASK = 0x07
#     CODEC_NONE = 0x00
#     CODEC_GZIP = 0x01
#     CODEC_SNAPPY = 0x02
#     CODEC_LZ4 = 0x03
#     CODEC_ZSTD = 0x04
#     TIMESTAMP_TYPE_MASK = 0x08
#     TRANSACTIONAL_MASK = 0x10
#     CONTROL_MASK = 0x20
#     LOG_APPEND_TIME = 1
#     CREATE_TIME = 0
#     NO_PARTITION_LEADER_EPOCH = -1
#     MAX_RECORD_OVERHEAD = 21
#     def _assert_has_codec(self, compression_type):
#     def __init__(self, buffer):
#     def base_offset(self):
#     def magic(self):
#     def crc(self):
#     def attributes(self):
#     def compression_type(self):
#     def timestamp_type(self):
#     def is_transactional(self):
#     def is_control_batch(self):
#     def last_offset_delta(self):
#     def first_timestamp(self):
#     def max_timestamp(self):
#     def producer_id(self):
#     def producer_epoch(self):
#     def base_sequence(self):
#     def next_offset(self):
#     def _maybe_uncompress(self):
#     def _read_msg(
#             self,
#             decode_varint=decode_varint):
#     def __iter__(self):
#     def __next__(self):
#     def validate_crc(self):
#     def __init__(self, offset, timestamp, timestamp_type, key, value, headers):
#     def offset(self):
#     def timestamp(self):
#     def timestamp_type(self):
#     def key(self):
#     def value(self):
#     def headers(self):
#     def checksum(self):
#     def __repr__(self):
#     def __init__(
#             self, magic, compression_type, is_transactional,
#             producer_id, producer_epoch, base_sequence, batch_size):
#     def _get_attributes(self, include_compression_type=True):
#     def append(self, offset, timestamp, key, value, headers,
#                # Cache for LOAD_FAST opcodes
#                encode_varint=encode_varint, size_of_varint=size_of_varint,
#                get_type=type, type_int=int, time_time=time.time,
#                byte_like=(bytes, bytearray, memoryview),
#                bytearray_type=bytearray, len_func=len, zero_len_varint=1
#                ):
#     def write_header(self, use_compression_type=True):
#     def _maybe_compress(self):
#     def build(self):
#     def size(self):
#     def size_in_bytes(self, offset, timestamp, key, value, headers):
#     def size_of(cls, key, value, headers):
#     def estimate_size_in_bytes(cls, key, value, headers):
#     def set_producer_state(self, producer_id, producer_epoch, base_sequence):
#     def producer_id(self):
#     def producer_epoch(self):
#     def base_sequence(self):
#     def __init__(self, offset, size, timestamp):
#     def offset(self):
#     def crc(self):
#     def size(self):
#     def timestamp(self):
#     def __repr__(self):


# Path: tests/record/test_default_records.py
from unittest import mock
from kafka.errors import UnsupportedCodecError
from aiokafka.record.default_records import (
    DefaultRecordBatch, DefaultRecordBatchBuilder
)
import kafka.codec
import pytest

        producer_id=-1, producer_epoch=-1, base_sequence=-1,
        batch_size=1024)

    meta = builder.append(
        0, timestamp=None, key=None, value=b"M" * 2000, headers=[])
    assert meta.size > 0
    assert meta.crc is None
    assert meta.offset == 0
    assert meta.timestamp is not None
    assert len(builder.build()) > 2000

    builder = DefaultRecordBatchBuilder(
        magic=2, compression_type=0, is_transactional=0,
        producer_id=-1, producer_epoch=-1, base_sequence=-1,
        batch_size=1024)
    meta = builder.append(
        0, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is not None
    meta = builder.append(
        1, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is None
    meta = builder.append(
        2, timestamp=None, key=None, value=b"M" * 700, headers=[])
    assert meta is None
    assert len(builder.build()) < 1000


@pytest.mark.parametrize("compression_type,name,checker_name", [
    (DefaultRecordBatch.CODEC_GZIP, "gzip", "has_gzip"),
    (DefaultRecordBatch.CODEC_SNAPPY, "snappy", "has_snappy"),

    (DefaultRecordBatch.CODEC_LZ4, "lz4", "has_lz4"),