Created
September 16, 2013 14:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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