@@ -76,6 +76,10 @@ module Codec.CBOR.Decoding
7676 , peekByteOffset -- :: Decoder s ByteOffset
7777 , decodeWithByteSpan
7878
79+ , markInput -- :: Decoder s ()
80+ , unmarkInput -- :: Decoder s ()
81+ , getInputSpan -- :: Decoder s LazyByteString
82+
7983 -- ** Canonical CBOR
8084 -- $canonical
8185 , decodeWordCanonical -- :: Decoder s Word
@@ -118,6 +122,7 @@ import GHC.Word
118122import GHC.Int
119123import Data.Text (Text )
120124import Data.ByteString (ByteString )
125+ import qualified Data.ByteString.Lazy as LBS
121126import Control.Applicative
122127import Control.Monad.ST
123128import qualified Control.Monad.Fail as Fail
@@ -193,6 +198,9 @@ data DecodeAction s a
193198#else
194199 | PeekByteOffset (Int # -> ST s (DecodeAction s a))
195200#endif
201+ | MarkInput (ST s (DecodeAction s a))
202+ | UnmarkInput (ST s (DecodeAction s a))
203+ | GetInputSpan (LBS. ByteString -> ST s (DecodeAction s a))
196204
197205 -- All the canonical variants
198206 | ConsumeWordCanonical (Word # -> ST s (DecodeAction s a))
@@ -990,6 +998,25 @@ peekByteOffset = Decoder (\k -> return (PeekByteOffset (\off# -> k (I64#
990998 ))))
991999{-# INLINE peekByteOffset #-}
9921000
1001+ -- |
1002+ --
1003+ -- @since 0.3.0.0
1004+ markInput :: Decoder s ()
1005+ markInput = Decoder (\ k -> return (MarkInput (k () )))
1006+
1007+ -- |
1008+ --
1009+ -- @since 0.3.0.0
1010+ unmarkInput :: Decoder s ()
1011+ unmarkInput = Decoder (\ k -> return (UnmarkInput (k () )))
1012+
1013+ -- |
1014+ --
1015+ -- @since 0.3.0.0
1016+ getInputSpan :: Decoder s LBS. ByteString
1017+ getInputSpan = Decoder (\ k -> return (GetInputSpan k))
1018+
1019+
9931020-- | This captures the pattern of getting the byte offsets before and after
9941021-- decoding a subterm.
9951022--
0 commit comments