Encode payload for 0.8/0.9 brokers -- requires an incorrect header checksum.
(payload)
| 257 | |
| 258 | |
| 259 | def lz4_encode_old_kafka(payload): |
| 260 | """Encode payload for 0.8/0.9 brokers -- requires an incorrect header checksum.""" |
| 261 | if xxhash is None: |
| 262 | raise RuntimeError('pip install xxhash for lz4 encoding with 0.8/0.9 brokers') |
| 263 | data = lz4_encode(payload) |
| 264 | header_size = 7 |
| 265 | flg = data[4] |
| 266 | if not isinstance(flg, int): |
| 267 | flg = ord(flg) |
| 268 | |
| 269 | content_size_bit = ((flg >> 3) & 1) |
| 270 | if content_size_bit: |
| 271 | # Old kafka does not accept the content-size field |
| 272 | # so we need to discard it and reset the header flag |
| 273 | flg -= 8 |
| 274 | data = bytearray(data) |
| 275 | data[4] = flg |
| 276 | data = bytes(data) |
| 277 | payload = data[header_size+8:] |
| 278 | else: |
| 279 | payload = data[header_size:] |
| 280 | |
| 281 | # This is the incorrect hc |
| 282 | hc = xxhash.xxh32(data[0:header_size-1]).digest()[-2:-1] # pylint: disable-msg=no-member |
| 283 | |
| 284 | return b''.join([ |
| 285 | data[0:header_size-1], |
| 286 | hc, |
| 287 | payload |
| 288 | ]) |
| 289 | |
| 290 | |
| 291 | def lz4_decode_old_kafka(payload): |
no outgoing calls
searching dependent graphs…