[英]Ptr Word8 to [Word8]
I'm using the library Network.Pcap
, and it has the function toBS
我正在使用库
Network.Pcap
,它具有toBS
的功能
toBS :: (PktHdr, Ptr Word8) -> IO (PktHdr, B.ByteString)
toBS (hdr, ptr) = do
let len = hdrCaptureLength hdr
s <- B.create (fromIntegral len) $ \p -> B.memcpy p ptr (fromIntegral len)
return (hdr, s)
Right now I am unpacking the ByteString which gives me the [Word8]
I want. 现在,我正在打开ByteString的包装,这给了我所需的
[Word8]
。 I' m looking for a way to avoid having to unpack the ByteString
, and get the [Word8]
directly. 我正在寻找避免解压
ByteString
并直接获取[Word8]
。
(1) Does this function exist? (1)这个功能存在吗? (2) If not, could I get some advice on how to proceed?
(2)如果没有,请问我如何进行操作?
I'm not familiar with those libraries, but can't you just do this? 我对那些库不熟悉,但是您不能这样做吗?
import Foreign.Marshal.Array
toByteList :: PktHdr -> Ptr Word8 -> IO [Word8]
toByteList hdr ptr = peekArray (fromIntegral (hdrCaptureLength hdr)) ptr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.