Skip to content

Commit 37e2fff

Browse files
committed
Restore Annotator-decoding functions
1 parent 450708b commit 37e2fff

File tree

7 files changed

+45
-48
lines changed

7 files changed

+45
-48
lines changed

libs/cardano-ledger-api/testlib/Test/Cardano/Ledger/Api/DebugTools.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Cardano.Ledger.Binary (
1414
Version,
1515
decNoShareCBOR,
1616
decodeFull',
17+
decodeFullAnnotator,
1718
decodeFullDecoder',
1819
)
1920
import Cardano.Ledger.Binary.Encoding (serialize')
@@ -22,7 +23,6 @@ import Control.Exception (Exception, throwIO)
2223
import Control.Monad.IO.Class (MonadIO (..))
2324
import qualified Data.ByteString as BS
2425
import qualified Data.ByteString.Lazy as LBS
25-
import Test.Cardano.Ledger.Binary.Annotator (decodeFullAnnotator)
2626

2727
readCBORWith ::
2828
(MonadIO m, Exception e) => (Version -> BS.ByteString -> Either e a) -> Version -> FilePath -> m a

libs/cardano-ledger-binary/bench/Bench.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import qualified Data.Map.Strict as Map
1818
import Data.Set (Set)
1919
import qualified Data.Set as Set
2020
import System.Random.Stateful
21-
import Test.Cardano.Ledger.Binary.Annotator (decodeFullAnnotator)
2221

2322
data Serialized a = Serialized !Version !BS.ByteString
2423

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding.hs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module Cardano.Ledger.Binary.Decoding (
1111
decodeFullDecoder,
1212
decodeFullDecoder',
1313
decodeFullFromHexText,
14+
decodeFullAnnotator,
15+
decodeFullAnnotatedBytes,
16+
decodeFullAnnotatorFromHexText,
1417
module Cardano.Ledger.Binary.Version,
1518
module Cardano.Ledger.Binary.Decoding.DecCBOR,
1619
module Cardano.Ledger.Binary.Decoding.Sharing,
@@ -159,6 +162,47 @@ supplyAllInput bs (Read.Partial k) = case bs of
159162
supplyAllInput _ (Read.Fail bs _ exn) = return (Left (exn, bs))
160163
{-# INLINE supplyAllInput #-}
161164

165+
--------------------------------------------------------------------------------
166+
-- Annotator
167+
--------------------------------------------------------------------------------
168+
169+
-- | Same as `decodeFullDecoder`, except it provdes the means of passing portion or all
170+
-- of the `BSL.ByteString` input argument to the decoding `Annotator`.
171+
decodeFullAnnotator ::
172+
Version ->
173+
Text ->
174+
(forall s. Decoder s (Annotator a)) ->
175+
BSL.ByteString ->
176+
Either DecoderError a
177+
decodeFullAnnotator v lbl decoder bytes =
178+
(\x -> runAnnotator x (Full bytes)) <$> decodeFullDecoder v lbl decoder bytes
179+
{-# INLINE decodeFullAnnotator #-}
180+
181+
-- | Same as `decodeFullDecoder`, decodes a Haskell value from a lazy
182+
-- `BSL.ByteString`, requiring that the full ByteString is consumed, and
183+
-- replaces `ByteSpan` annotations with the corresponding slice of the input as
184+
-- a strict `BS.ByteString`.
185+
decodeFullAnnotatedBytes ::
186+
Functor f =>
187+
Version ->
188+
Text ->
189+
(forall s. Decoder s (f ByteSpan)) ->
190+
BSL.ByteString ->
191+
Either DecoderError (f BS.ByteString)
192+
decodeFullAnnotatedBytes v lbl decoder bytes =
193+
annotationBytes bytes <$> decodeFullDecoder v lbl decoder bytes
194+
{-# INLINE decodeFullAnnotatedBytes #-}
195+
196+
decodeFullAnnotatorFromHexText ::
197+
Version ->
198+
Text ->
199+
(forall s. Decoder s (Annotator a)) ->
200+
Text ->
201+
Either DecoderError a
202+
decodeFullAnnotatorFromHexText v desc dec =
203+
Plain.withHexText $ decodeFullAnnotator v desc dec . BSL.fromStrict
204+
{-# INLINE decodeFullAnnotatorFromHexText #-}
205+
162206
--------------------------------------------------------------------------------
163207
-- Nested CBOR-in-CBOR
164208
-- https://tools.ietf.org/html/rfc7049#section-2.4.4.1

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import qualified Data.ByteString.Lazy as BSL
1717
import Data.Proxy
1818
import qualified Data.Text as T
1919
import Data.Typeable
20-
import Test.Cardano.Ledger.Binary.Annotator (decodeFullAnnotator)
2120
import Test.Cardano.Ledger.Binary.RoundTrip (embedTripAnnExpectation)
2221
import Test.Hspec
2322
import Test.Hspec.QuickCheck (prop)

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Annotator.hs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,8 @@ module Test.Cardano.Ledger.Binary.Annotator (
3030
import Cardano.Ledger.Binary
3131
import qualified Cardano.Ledger.Binary.Plain as Plain
3232
import Control.Monad.Except (Except, MonadError (throwError))
33-
import qualified Data.ByteString as BS
34-
import qualified Data.ByteString.Lazy as BSL
3533
import Data.Text (Text)
3634

37-
--------------------------------------------------------------------------------
38-
-- Annotator
39-
--------------------------------------------------------------------------------
40-
41-
-- | Same as `decodeFullDecoder`, except it provdes the means of passing portion or all
42-
-- of the `BSL.ByteString` input argument to the decoding `Annotator`.
43-
decodeFullAnnotator ::
44-
Version ->
45-
Text ->
46-
(forall s. Decoder s (Annotator a)) ->
47-
BSL.ByteString ->
48-
Either DecoderError a
49-
decodeFullAnnotator v lbl decoder bytes =
50-
(\x -> runAnnotator x (Full bytes)) <$> decodeFullDecoder v lbl decoder bytes
51-
{-# INLINE decodeFullAnnotator #-}
52-
53-
-- | Same as `decodeFullDecoder`, decodes a Haskell value from a lazy
54-
-- `BSL.ByteString`, requiring that the full ByteString is consumed, and
55-
-- replaces `ByteSpan` annotations with the corresponding slice of the input as
56-
-- a strict `BS.ByteString`.
57-
decodeFullAnnotatedBytes ::
58-
Functor f =>
59-
Version ->
60-
Text ->
61-
(forall s. Decoder s (f ByteSpan)) ->
62-
BSL.ByteString ->
63-
Either DecoderError (f BS.ByteString)
64-
decodeFullAnnotatedBytes v lbl decoder bytes =
65-
annotationBytes bytes <$> decodeFullDecoder v lbl decoder bytes
66-
{-# INLINE decodeFullAnnotatedBytes #-}
67-
68-
decodeFullAnnotatorFromHexText ::
69-
Version ->
70-
Text ->
71-
(forall s. Decoder s (Annotator a)) ->
72-
Text ->
73-
Either DecoderError a
74-
decodeFullAnnotatorFromHexText v desc dec =
75-
Plain.withHexText $ decodeFullAnnotator v desc dec . BSL.fromStrict
76-
{-# INLINE decodeFullAnnotatorFromHexText #-}
77-
7835
-- | Translation function between values through a related binary representation. This
7936
-- function allows you to translate one type into another (or the same one) through their
8037
-- common binary format. It is possible for the source type to be encoded with a different

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Cddl.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import System.Process.Typed (
4646
setStdin,
4747
)
4848
import Test.Cardano.Ledger.Binary (decoderEquivalenceExpectation)
49-
import Test.Cardano.Ledger.Binary.Annotator (decodeFullAnnotator)
5049
import Test.Cardano.Ledger.Binary.RoundTrip
5150
import Test.Hspec
5251
import UnliftIO.Temporary (withTempFile)

libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/RoundTrip.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import Data.Functor
7474
import Data.Proxy
7575
import qualified Data.Text as T
7676
import Data.Typeable
77-
import Test.Cardano.Ledger.Binary.Annotator (decodeFullAnnotator)
7877
import Test.Cardano.Ledger.Binary.Plain.RoundTrip (
7978
showFailedTermsWithReSerialization,
8079
showMaybeDecoderError,

0 commit comments

Comments
 (0)