Decode a BSON binary to bson.binary.Binary or python UUID.
(
data: Any, _view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy1: Any
)
| 374 | |
| 375 | |
| 376 | def _get_binary( |
| 377 | data: Any, _view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy1: Any |
| 378 | ) -> Tuple[Union[Binary, uuid.UUID], int]: |
| 379 | """Decode a BSON binary to bson.binary.Binary or python UUID.""" |
| 380 | length, subtype = _UNPACK_LENGTH_SUBTYPE_FROM(data, position) |
| 381 | position += 5 |
| 382 | if subtype == 2: |
| 383 | length2 = _UNPACK_INT_FROM(data, position)[0] |
| 384 | position += 4 |
| 385 | if length2 != length - 4: |
| 386 | raise InvalidBSON("invalid binary (st 2) - lengths don't match!") |
| 387 | length = length2 |
| 388 | end = position + length |
| 389 | if length < 0 or end > obj_end: |
| 390 | raise InvalidBSON("bad binary object length") |
| 391 | |
| 392 | # Convert UUID subtypes to native UUIDs. |
| 393 | if subtype in ALL_UUID_SUBTYPES: |
| 394 | uuid_rep = opts.uuid_representation |
| 395 | binary_value = Binary(data[position:end], subtype) |
| 396 | if ( |
| 397 | (uuid_rep == UuidRepresentation.UNSPECIFIED) |
| 398 | or (subtype == UUID_SUBTYPE and uuid_rep != STANDARD) |
| 399 | or (subtype == OLD_UUID_SUBTYPE and uuid_rep == STANDARD) |
| 400 | ): |
| 401 | return binary_value, end |
| 402 | return binary_value.as_uuid(uuid_rep), end |
| 403 | |
| 404 | # Decode subtype 0 to 'bytes'. |
| 405 | if subtype == 0: |
| 406 | value = data[position:end] |
| 407 | else: |
| 408 | value = Binary(data[position:end], subtype) |
| 409 | |
| 410 | return value, end |
| 411 | |
| 412 | |
| 413 | def _get_oid( |
nothing calls this directly
no test coverage detected