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

Function _decode_all

bson/__init__.py:1100–1129  ·  view source on GitHub ↗

Decode a BSON data to multiple documents.

(data: _ReadableBuffer, opts: CodecOptions[_DocumentType])

Source from the content-addressed store, hash-verified

1098
1099
1100def _decode_all(data: _ReadableBuffer, opts: CodecOptions[_DocumentType]) -> list[_DocumentType]:
1101 """Decode a BSON data to multiple documents."""
1102 data, view = get_data_and_view(data)
1103 data_len = len(data)
1104 docs: list[_DocumentType] = []
1105 position = 0
1106 end = data_len - 1
1107 use_raw = _raw_document_class(opts.document_class)
1108 try:
1109 while position < end:
1110 obj_size = _UNPACK_INT_FROM(data, position)[0]
1111 if data_len - position < obj_size:
1112 raise InvalidBSON(
1113 f"invalid object size: expected {obj_size}, got {data_len - position}"
1114 )
1115 obj_end = position + obj_size - 1
1116 if data[obj_end] != 0:
1117 raise InvalidBSON("bad eoo")
1118 if use_raw:
1119 docs.append(opts.document_class(data[position : obj_end + 1], opts)) # type: ignore
1120 else:
1121 docs.append(_elements_to_dict(data, view, position + 4, obj_end, opts))
1122 position += obj_size
1123 return docs
1124 except InvalidBSON:
1125 raise
1126 except Exception:
1127 # Change exception type to InvalidBSON but preserve traceback.
1128 _, exc_value, exc_tb = sys.exc_info()
1129 raise InvalidBSON(str(exc_value)).with_traceback(exc_tb) from None
1130
1131
1132if _USE_C:

Callers 1

decode_allFunction · 0.85

Calls 4

_raw_document_classFunction · 0.90
InvalidBSONClass · 0.90
get_data_and_viewFunction · 0.85
_elements_to_dictFunction · 0.85

Tested by

no test coverage detected