async def write(self, dest: Pointer, data: bytes) -> None: if dest.size() != len(data): raise Exception("mismatched pointer size", dest.size(), "and data size", len(data)) src = await self.local.ram.ptr(data) dest_span = to_span(dest) await self.do_write(dest_span, src)
async def do_write(self, dest: Pointer, src: Pointer[bytes], i=0) -> None: if dest.size() == 0: return written, rest = await self.local.write(src) dest, dest_rest = dest.split(written.size()) if dest_rest.size() != 0: raise NotImplementedError("partial write, oops, not supported yet") await self.remote.recv(dest, MSG.WAITALL)
async def read(self, src: Pointer) -> bytes: dest = await self.local.ram.malloc(bytes, src.size()) src_span = to_span(src) return await self.do_read(dest, src_span)
def to_span(ptr: Pointer) -> Pointer: "Wraps the pointer's allocation in SpanAllocation so it can be split freely" return Pointer(ptr.mapping, ptr.transport, ptr.serializer, SpanAllocation(ptr.allocation, 0, ptr.allocation.size()), ptr.typ)