MCPcopy Create free account
hub / github.com/dpkp/kafka-python / snappy_decode

Function snappy_decode

kafka/codec.py:200–222  ·  view source on GitHub ↗
(payload)

Source from the content-addressed store, hash-verified

198
199
200def snappy_decode(payload):
201 if not has_snappy():
202 raise NotImplementedError("Snappy codec is not available")
203
204 if _detect_xerial_stream(payload):
205 # TODO ? Should become a fileobj ?
206 out = io.BytesIO()
207 byt = payload[16:]
208 length = len(byt)
209 cursor = 0
210
211 while cursor < length:
212 block_size = struct.unpack_from('!i', byt[cursor:])[0]
213 # Skip the block size
214 cursor += 4
215 end = cursor + block_size
216 out.write(snappy.decompress(byt[cursor:end]))
217 cursor = end
218
219 out.seek(0)
220 return out.read()
221 else:
222 return snappy.decompress(payload)
223
224
225if lz4:

Callers 4

test_snappyFunction · 0.90
_decompressMethod · 0.90
_maybe_uncompressMethod · 0.90

Calls 5

has_snappyFunction · 0.85
_detect_xerial_streamFunction · 0.85
readMethod · 0.80
writeMethod · 0.45
seekMethod · 0.45

Tested by 2

test_snappyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…