Decode a BSON string to python str.
(
data: Any, view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy: Any
)
| 280 | |
| 281 | |
| 282 | def _get_string( |
| 283 | data: Any, view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy: Any |
| 284 | ) -> Tuple[str, int]: |
| 285 | """Decode a BSON string to python str.""" |
| 286 | length = _UNPACK_INT_FROM(data, position)[0] |
| 287 | position += 4 |
| 288 | if length < 1 or obj_end - position < length: |
| 289 | raise InvalidBSON("invalid string length") |
| 290 | end = position + length - 1 |
| 291 | if data[end] != 0: |
| 292 | raise InvalidBSON("invalid end of string") |
| 293 | return _utf_8_decode(view[position:end], opts.unicode_decode_error_handler, True)[0], end + 1 |
| 294 | |
| 295 | |
| 296 | def _get_object_size(data: Any, position: int, obj_end: int) -> Tuple[int, int]: |
no test coverage detected