我正在尝试Store
为Streaming
. Store
已经decode
使用名为decodeMessageBS
.
我尝试如下进行store
反序列化的基本实现(暂时不保持简单)。但是,因为不断抛出的逻辑似乎有问题:Streaming
bracket
popper
decodeMessageBS
PeekException
{-# LANGUAGE RankNTypes #-}
import Streaming.Prelude as S hiding (print,show)
import Data.IORef
import Streaming as S
import qualified Data.ByteString as BS (ByteString,empty,length)
import System.IO.ByteBuffer
import Data.Store
import Data.Store.Streaming
streamDecode :: forall a. (Store a) => ByteBuffer -> Stream (Of BS.ByteString) IO () -> Stream (Of a) IO ()
streamDecode bb inp = do
ref <- lift $ newIORef inp
let popper = do
r <- S.uncons =<< readIORef ref
case r of
Nothing -> return Nothing
Just (a,rest) -> writeIORef ref rest >> return (Just a)
let go = do
r <- lift $ decodeMessageBS bb $ popper
lift $ print "Decoding"
case r of
Nothing -> return ()
Just msg -> (lift $ print "Message found") >> (S.yield . fromMessage $ msg) >> go
go
我可以很好地解码我的测试文件decodeIOPortionWith
- 所以,问题似乎出在 feed 所需的逻辑上decodeMessageBS
。popper
将欣赏有关此处逻辑有什么问题的指针。