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

Method unpack

pymongo/message.py:1525–1541  ·  view source on GitHub ↗

Construct an _OpMsg from raw bytes.

(cls, msg: bytes | memoryview)

Source from the content-addressed store, hash-verified

1523
1524 @classmethod
1525 def unpack(cls, msg: bytes | memoryview) -> _OpMsg:
1526 """Construct an _OpMsg from raw bytes."""
1527 flags, first_payload_type, first_payload_size = cls.UNPACK_FROM(msg)
1528 if flags != 0:
1529 if flags & cls.CHECKSUM_PRESENT:
1530 raise ProtocolError(f"Unsupported OP_MSG flag checksumPresent: 0x{flags:x}")
1531
1532 if flags ^ cls.MORE_TO_COME:
1533 raise ProtocolError(f"Unsupported OP_MSG flags: 0x{flags:x}")
1534 if first_payload_type != 0:
1535 raise ProtocolError(f"Unsupported OP_MSG payload type: 0x{first_payload_type:x}")
1536
1537 if len(msg) != first_payload_size + 5:
1538 raise ProtocolError("Unsupported OP_MSG reply: >1 section")
1539
1540 payload_document = msg[5:]
1541 return cls(flags, payload_document)
1542
1543
1544_UNPACK_REPLY: dict[int, Callable[[bytes | memoryview], Union[_OpReply, _OpMsg]]] = {

Callers 3

receive_messageMethod · 0.45
receive_messageMethod · 0.45

Calls 1

ProtocolErrorClass · 0.90

Tested by 3

receive_messageMethod · 0.36
receive_messageMethod · 0.36