-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1229 from input-output-hk/KtorZ/1228/safe-eitherR…
…unGet Define and use safe 'eitherRunGet' to avoid throwing on binary decoding
- Loading branch information
Showing
8 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- | | ||
-- Copyright: © 2018-2019 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
-- Extra helpers for safe decoding of binary data. | ||
|
||
module Data.Binary.Get.Safe | ||
( eitherRunGet | ||
) where | ||
|
||
import Prelude | ||
|
||
import Data.Binary.Get | ||
( Get, runGetOrFail ) | ||
|
||
import qualified Data.ByteString.Lazy as BL | ||
|
||
|
||
-- | A safe version of 'runGet' which doesn't throw on error. | ||
eitherRunGet | ||
:: Get a | ||
-> BL.ByteString | ||
-> Either String a | ||
eitherRunGet decoder bytes = case runGetOrFail decoder bytes of | ||
Right (_, _, a) -> Right a | ||
Left (_, _, e) -> Left e |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ test-suite unit | |
, monad-loops | ||
, QuickCheck | ||
, safe | ||
, servant | ||
, text | ||
, text-class | ||
, time | ||
|
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.