簡體   English   中英

調整商店解碼以用於流媒體庫

[英]Adapting Store decoding for streaming library

我正在嘗試將Store編碼和解碼用於Streaming Store已經使用稱為decodeMessageBS的功能實現了流式decode

我嘗試按照以下方式對流進行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很好地解碼我的測試文件,因此,問題似乎出在提供decodeMessageBS所需的邏輯中。 在這里,將感謝您指出popper邏輯到底出了什么問題。

PeekException會發生PeekException ,是因為在以流模式保存消息時, Store使用不同的格式,這與Binary不同。 當使用decodeMessageBS函數時,它期望在Store數據周圍使用Message類型的包裝器。 decodeIOPortionWith不需要Message包裝器,因此可以與保存的向下Store數據一起正常工作。 在修復序列化以將數據保存為Message編碼后, decodeMessageBS在該數據上工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM