Encode bson.dbref.DBRef.
(name: bytes, value: DBRef, check_keys: bool, opts: CodecOptions[Any])
| 719 | |
| 720 | |
| 721 | def _encode_dbref(name: bytes, value: DBRef, check_keys: bool, opts: CodecOptions[Any]) -> bytes: |
| 722 | """Encode bson.dbref.DBRef.""" |
| 723 | buf = bytearray(b"\x03" + name + b"\x00\x00\x00\x00") |
| 724 | begin = len(buf) - 4 |
| 725 | |
| 726 | buf += _name_value_to_bson(b"$ref\x00", value.collection, check_keys, opts) |
| 727 | buf += _name_value_to_bson(b"$id\x00", value.id, check_keys, opts) |
| 728 | if value.database is not None: |
| 729 | buf += _name_value_to_bson(b"$db\x00", value.database, check_keys, opts) |
| 730 | for key, val in value._DBRef__kwargs.items(): |
| 731 | buf += _element_to_bson(key, val, check_keys, opts) |
| 732 | |
| 733 | buf += b"\x00" |
| 734 | buf[begin : begin + 4] = _PACK_INT(len(buf) - begin) |
| 735 | return bytes(buf) |
| 736 | |
| 737 | |
| 738 | def _encode_list( |
nothing calls this directly
no test coverage detected