我正在解析一个长度编码的二进制流,并且正在尝试编译此代码。combinatorrent 代码(https://github.com/jlouis/combinatorrent/blob/master/src/Protocol/Wire.hs)对让我继续前进非常有帮助,但现在我被卡住了。如何在 return 语句中使用 frame_length?
data FrameCont = FINAL | MORE | BADCONT
deriving (Show, Eq)
frame_cont 0x00 = FINAL
frame_cont 0x01 = MORE
frame_cont otherwise = BADCONT
data FrameSize = Small Word8 | Jumbo B.ByteString
deriving (Show)
get_fc = do
raw_cont <- AP.anyWord8
guard((frame_cont raw_cont) /= BADCONT) AP.<?> "State must be either MORE or FINAL"
return raw_cont
parser = do
frame_length <- AP.anyWord8
case frame_length of
0x255 -> return (Jumbo <$> AP.take 8, get_fc, AP.take (fromIntegral frame_length))
otherwise -> return (Small otherwise, get_fc, AP.take (fromIntegral frame_length))
另外:我如何使用 pass (AP.take 8) 进入 Word64?