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

Function _encode_dbref

bson/__init__.py:721–735  ·  view source on GitHub ↗

Encode bson.dbref.DBRef.

(name: bytes, value: DBRef, check_keys: bool, opts: CodecOptions[Any])

Source from the content-addressed store, hash-verified

719
720
721def _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
738def _encode_list(

Callers

nothing calls this directly

Calls 3

_name_value_to_bsonFunction · 0.85
_element_to_bsonFunction · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected