MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _compress

Function _compress

pymongo/message.py:294–310  ·  view source on GitHub ↗

Takes message data, compresses it, and adds an OP_COMPRESSED header.

(
    operation: int, data: bytes, ctx: Union[SnappyContext, ZlibContext, ZstdContext]
)

Source from the content-addressed store, hash-verified

292
293
294def _compress(
295 operation: int, data: bytes, ctx: Union[SnappyContext, ZlibContext, ZstdContext]
296) -> tuple[int, bytes]:
297 """Takes message data, compresses it, and adds an OP_COMPRESSED header."""
298 compressed = ctx.compress(data)
299 request_id = _randint()
300
301 header = _pack_compression_header(
302 _COMPRESSION_HEADER_SIZE + len(compressed), # Total message length
303 request_id, # Request id
304 0, # responseTo
305 2012, # operation id
306 operation, # original operation id
307 len(data), # uncompressed message length
308 ctx.compressor_id,
309 ) # compressor id
310 return request_id, header + compressed
311
312
313_pack_header = struct.Struct("<iiii").pack

Callers 5

_op_msg_compressedFunction · 0.85
_query_compressedFunction · 0.85
_get_more_compressedFunction · 0.85

Calls 2

_randintFunction · 0.85
compressMethod · 0.45

Tested by

no test coverage detected