I posted this to stack overflow 
<https://stackoverflow.com/questions/49246763/adapting-store-decoding-for-streaming-library>
 
in case anyone might be able to help answer it there. The problem that I am 
trying to solve is how to adapt the following decoding API from Store 
<https://www.stackage.org/haddock/lts-10.9/store-0.4.3.2/Data-Store-Streaming.html>
 
to `Streaming` library:
decodeMessageBS :: (MonadIO 
<https://www.stackage.org/haddock/lts-10.9/foundation-0.0.17/Foundation-Monad.html#t:MonadIO>
 
m, Store 
<https://www.stackage.org/haddock/lts-10.9/store-0.4.3.2/Data-Store-Internal.html#t:Store>
 
a) => ByteBuffer 
<https://www.stackage.org/haddock/lts-10.9/store-0.4.3.2/System-IO-ByteBuffer.html#t:ByteBuffer>
 
-> m (Maybe 
<https://www.stackage.org/haddock/lts-10.9/basement-0.0.4/Basement-Compat-Base.html#t:Maybe>
 
ByteString 
<https://www.stackage.org/haddock/lts-10.9/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString>
) -> m (Maybe 
<https://www.stackage.org/haddock/lts-10.9/basement-0.0.4/Basement-Compat-Base.html#t:Maybe>
 
(Message 
<https://www.stackage.org/haddock/lts-10.9/store-0.4.3.2/Data-Store-Streaming.html#t:Message>
 
a))

I took a shot at it with the code below but am not able to figure it out 
yet - there are some undefined statements in the code below btw as 
placeholders - perhaps, there also exists a simpler and efficient way to 
adapt `decodeMessageBS` to `Streaming`:

{-# LANGUAGE OverloadedStrings,ScopedTypeVariables #-}import           
Data.ByteString (ByteString)import           System.IO.ByteBuffer 
(ByteBuffer)import qualified System.IO.ByteBuffer as BBimport 
Data.Store.Streamingimport Data.Store (Store)import Streaming.Prelude as 
Simport Data.IORef

streamDecodeH :: forall a r. (Store a) => ByteBuffer -> Stream (Of ByteString) 
IO r -> Stream (Of (Message a)) IO r
streamDecodeH bb inp = do
    ref <- newIORef inp 
    go (popper ref)
    undefined
  where
    go src = do
      r <- (decodeMessageBS :: ByteBuffer -> IO (Maybe ByteString) -> IO (Maybe 
(Message a))) bb src
      case r of 
        Nothing -> undefined
        Just msg -> (S.yield :: Message a -> Stream (Of (Message a)) IO ()) msg 
>> go src

    popper :: IORef (Stream (Of ByteString) IO r) -> IO (Maybe ByteString)
    popper ref = do
      chunks <- readIORef ref
      r <- S.uncons chunks
      case r of
        Nothing -> return Nothing
        Just (a,rest) -> writeIORef ref rest >> return (Just a)


Will appreciate help with it, either here or at StackOverflow.

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to