Unpack a MongoDB Wire Protocol header.
(self)
| 633 | self._response_to = None |
| 634 | |
| 635 | def process_header(self) -> tuple[int, int, int, bool]: |
| 636 | """Unpack a MongoDB Wire Protocol header.""" |
| 637 | length, _, response_to, op_code = _UNPACK_HEADER(self._header) |
| 638 | expecting_compression = False |
| 639 | if op_code == 2012: # OP_COMPRESSED |
| 640 | if length <= 25: |
| 641 | raise ProtocolError( |
| 642 | f"Message length ({length!r}) not longer than standard OP_COMPRESSED message header size (25)" |
| 643 | ) |
| 644 | expecting_compression = True |
| 645 | length -= 9 |
| 646 | if length <= 16: |
| 647 | raise ProtocolError( |
| 648 | f"Message length ({length!r}) not longer than standard message header size (16)" |
| 649 | ) |
| 650 | if length > self._max_message_size: |
| 651 | raise ProtocolError( |
| 652 | f"Message length ({length!r}) is larger than server max " |
| 653 | f"message size ({self._max_message_size!r})" |
| 654 | ) |
| 655 | |
| 656 | return length - 16, op_code, response_to, expecting_compression |
| 657 | |
| 658 | def process_compression_header(self) -> tuple[int, int]: |
| 659 | """Unpack a MongoDB Wire Protocol compression header.""" |
no test coverage detected