Skip to content

Commit

Permalink
define and export a safe version of 'runGet'
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Dec 24, 2019
1 parent ca2675b commit 8e87584
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/jormungandr/src/Cardano/Wallet/Jormungandr/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ module Cardano.Wallet.Jormungandr.Binary
-- * Re-export
, Get
, runGet
, eitherRunGet
, runGetOrFail
, Put
, runPut
Expand Down Expand Up @@ -971,6 +972,15 @@ withRaw get = do
raw <- getByteString (end - start)
pure (raw, a)

-- | 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

{-------------------------------------------------------------------------------
Conversions
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 8e87584

Please sign in to comment.