MCPcopy Create free account
hub / github.com/ZeroIntensity/pointers.py / move_to_mem

Function move_to_mem

src/pointers/_utils.py:54–71  ·  view source on GitHub ↗

Move data to a C pointer.

(
    ptr: "ctypes._PointerLike",
    stream: bytes,
    *,
    unsafe: bool = False,
    target: str = "memory allocation",
)

Source from the content-addressed store, hash-verified

52
53
54def 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
74def attempt_decode(data: bytes) -> Union[str, bytes]:

Callers 2

moveMethod · 0.85
moveMethod · 0.85

Calls 1

InvalidSizeErrorClass · 0.85

Tested by

no test coverage detected