[commit: packages/binary] master: Update the example that uses 'runGetState' to new API. (fc61b89)
git at git.haskell.org
git at git.haskell.org
Sun Dec 14 17:54:08 UTC 2014
Repository : ssh://git@git.haskell.org/binary
On branch : master
Link : http://git.haskell.org/packages/binary.git/commitdiff/fc61b8913a73fa66491a486755778a1de006594d
>---------------------------------------------------------------
commit fc61b8913a73fa66491a486755778a1de006594d
Author: Mikhail Glushenkov <mikhail.glushenkov at gmail.com>
Date: Tue Nov 12 02:51:13 2013 +0100
Update the example that uses 'runGetState' to new API.
Fixes #30.
>---------------------------------------------------------------
fc61b8913a73fa66491a486755778a1de006594d
src/Data/Binary/Get.hs | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/src/Data/Binary/Get.hs b/src/Data/Binary/Get.hs
index 028d07a..bef3b28 100644
--- a/src/Data/Binary/Get.hs
+++ b/src/Data/Binary/Get.hs
@@ -103,11 +103,29 @@
--
-- @
-- example2 :: BL.ByteString -> [Trade]
--- example2 input
--- | BL.null input = []
--- | otherwise =
--- let (trade, rest, _) = 'runGetState' getTrade input 0
--- in trade : example2 rest
+-- example2 input = go (runGetIncremental getTrade) input
+-- where
+-- decoder = runGetIncremental getTrade
+--
+-- go :: Decoder Trade -> BL.ByteString -> [Trade]
+-- go (Done leftover _consumed trade) input' =
+-- trade : go decoder (BL.chunk leftover input')
+-- go (Partial k) input' =
+-- go (k . takeHeadChunk $ input') (dropHeadChunk input')
+-- go (Fail _leftover _consumed msg) _input' =
+-- error msg
+--
+-- takeHeadChunk :: BL.ByteString -> Maybe BS.ByteString
+-- takeHeadChunk lbs =
+-- case lbs of
+-- (BL.Chunk bs _) -> Just bs
+-- _ -> Nothing
+--
+-- dropHeadChunk :: BL.ByteString -> BL.ByteString
+-- dropHeadChunk lbs =
+-- case lbs of
+-- (BL.Chunk _ lbs') -> lbs'
+-- _ -> BL.Empty
-- @
--
-- Both these examples use lazy I/O to read the file from the disk, which is
More information about the ghc-commits
mailing list