def validate_crc(self):
        assert self._decompressed is False, "Validate should be called before iteration"

        crc = self.crc
        data_view = memoryview(self._buffer)[self.ATTRIBUTES_OFFSET:]
        verify_crc = calc_crc32c(data_view.tobytes())
        return crc == verify_crc
Beispiel #2
0
    def validate_crc(self):
        assert self._decompressed is False, \
            "Validate should be called before iteration"

        crc = self.crc
        data_view = memoryview(self._buffer)[self.ATTRIBUTES_OFFSET:]
        verify_crc = calc_crc32c(data_view.tobytes())
        return crc == verify_crc
Beispiel #3
0
 def write_header(self, use_compression_type=True):
     batch_len = len(self._buffer)
     self.HEADER_STRUCT.pack_into(
         self._buffer, 0,
         0,  # BaseOffset, set by broker
         batch_len - self.AFTER_LEN_OFFSET,  # Size from here to end
         0,  # PartitionLeaderEpoch, set by broker
         self._magic,
         0,  # CRC will be set below, as we need a filled buffer for it
         self._get_attributes(use_compression_type),
         self._last_offset,
         self._first_timestamp,
         self._max_timestamp,
         self._producer_id,
         self._producer_epoch,
         self._base_sequence,
         self._num_records
     )
     crc = calc_crc32c(self._buffer[self.ATTRIBUTES_OFFSET:])
     struct.pack_into(">I", self._buffer, self.CRC_OFFSET, crc)
Beispiel #4
0
 def write_header(self, use_compression_type=True):
     batch_len = len(self._buffer)
     self.HEADER_STRUCT.pack_into(
         self._buffer, 0,
         0,  # BaseOffset, set by broker
         batch_len - self.AFTER_LEN_OFFSET,  # Size from here to end
         0,  # PartitionLeaderEpoch, set by broker
         self._magic,
         0,  # CRC will be set below, as we need a filled buffer for it
         self._get_attributes(use_compression_type),
         self._last_offset,
         self._first_timestamp,
         self._max_timestamp,
         self._producer_id,
         self._producer_epoch,
         self._base_sequence,
         self._num_records
     )
     crc = calc_crc32c(self._buffer[self.ATTRIBUTES_OFFSET:])
     struct.pack_into(">I", self._buffer, self.CRC_OFFSET, crc)
Beispiel #5
0
 def make_crc(data):
     crc = util.calc_crc32c(data)
     return struct.pack(">I", crc)