| 207 | return SegmentHeader(payload_length, uncompressed_payload_length, is_self_contained) |
| 208 | |
| 209 | def decode(self, buffer, header): |
| 210 | encoded_payload = buffer.read(header.payload_length) |
| 211 | expected_payload_crc = read_uint_le(buffer) |
| 212 | |
| 213 | actual_payload_crc = compute_crc32(encoded_payload, CRC32_INITIAL) |
| 214 | if actual_payload_crc != expected_payload_crc: |
| 215 | raise CrcException('CRC mismatch on payload. Received {:x}", computed {:x}.'.format( |
| 216 | expected_payload_crc, actual_payload_crc)) |
| 217 | |
| 218 | payload = encoded_payload |
| 219 | if self.compression and header.uncompressed_payload_length > 0: |
| 220 | payload = self.decompress(encoded_payload, header.uncompressed_payload_length) |
| 221 | |
| 222 | return Segment(payload, header.is_self_contained) |