Move data to a C pointer.
(
ptr: "ctypes._PointerLike",
stream: bytes,
*,
unsafe: bool = False,
target: str = "memory allocation",
)
| 52 | |
| 53 | |
| 54 | def move_to_mem( |
| 55 | ptr: "ctypes._PointerLike", |
| 56 | stream: bytes, |
| 57 | *, |
| 58 | unsafe: bool = False, |
| 59 | target: str = "memory allocation", |
| 60 | ): |
| 61 | """Move data to a C pointer.""" |
| 62 | |
| 63 | slen = len(stream) |
| 64 | plen = len(ptr.contents) # type: ignore |
| 65 | |
| 66 | if (slen > plen) and (not unsafe): |
| 67 | raise InvalidSizeError( |
| 68 | f"object is of size {slen}, while {target} is {plen}", |
| 69 | ) |
| 70 | |
| 71 | ctypes.memmove(ptr, stream, slen) |
| 72 | |
| 73 | |
| 74 | def attempt_decode(data: bytes) -> Union[str, bytes]: |
no test coverage detected