2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Data.Binary.Get with Data.Conduit

Posted at

引き続き簡単だった、ほぼ頭使わないで使える。

conduit_binary.hs
{-# 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
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?