"Peeking", to read a pointer ptr
to a new ByteString
, is straightforward:
BS.packCStringLen (ptr, size)
But the poke
operation (writing a ByteString
into a given memory location) isn't that obvious. We have
useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a
so we could do (with the help of copyBytes
.
BS.useAsCStringLen bs $ \(src, len) -> copyBytes ptr src len
or for better performance unsafeUseAsCStringLen
.
Is there perhaps a ready-made function that does the above?