def _serialize(self): return pack("<l", self._flags()) + \ cstrify(self._collection) + \ pack("<ll", self._docs_to_skip or 0, self._docs_to_return or -1) + \ serialize_to_bytes(self._query) + \ (serialize_to_bytes({ f: 1 for f in self._fields }) if self._fields is not None else b"")
pack("<lllllqll", 36, 7, 8, 1, 0b1011, 0x0123456789ABCDEF, 100, 0)) rs = MongoDB_Response.parse_stream(rs_s) assert isinstance(rs, OP_REPLY) assert rs.response_id == 8 assert rs.cursor_id == 0x0123456789ABCDEF assert rs.cursor_not_found is True assert rs.query_failure is True assert rs.await_capable is True assert rs.documents == [] assert f_s( rs ) == "OP_REPLY FAILURE CURSOR NOT FOUND USING CURSOR 0x0123456789abcdef AWAIT CAPABLE STARTING FROM 100" rs_d = serialize_to_bytes({"foo": "bar"}) rs_s = BytesIO( pack("<lllllqll", 36 + len(rs_d), 8, 7, 1, 0b0000, 0, 0, 1) + rs_d) rs = MongoDB_Response.parse_stream(rs_s) assert isinstance(rs, OP_REPLY) assert rs.response_id == 7 assert rs.cursor_id == 0 assert rs.cursor_not_found is False assert rs.query_failure is False assert rs.await_capable is False assert rs.documents == [{"foo": "bar"}] assert f_s(rs) == "OP_REPLY RETURNS 1" print("ok")
def _serialize(self): return pack("<l", 0) + \ cstrify(self._collection) + \ pack("<l", self._flags()) + \ serialize_to_bytes(self._selector) + \ serialize_to_bytes(self._update)
def _serialize(self): return pack("<l", 0) + \ cstrify(self._collection) + \ b"".join(serialize_to_bytes(document) for document in self._documents)