Skip to content

Instantly share code, notes, and snippets.

@xkikeg
Created September 16, 2013 14:49
Show Gist options
  • Save xkikeg/6581677 to your computer and use it in GitHub Desktop.
Save xkikeg/6581677 to your computer and use it in GitHub Desktop.
Data.Binary.Get with Data.Conduit ref: http://qiita.com/liquidamber/items/7c69271ae5c19beee383
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Data.Binary.Get
import qualified Data.ByteString as BS
import Data.Conduit
import Data.Conduit.Serialization.Binary
import Data.Word
query :: BS.ByteString
query = "\64\64\0ABC"
qSource :: Monad m => Source m BS.ByteString
qSource = yield query
getter :: Get (Word8, Word16, BS.ByteString)
getter = (,,) <$> getWord8 <*> getWord16be <*> getByteString 3
main = do
result <- qSource $$ sinkGet getter
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment