{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Cardano.Ledger.Binary.Decoding.Decoder (
Decoder,
toPlainDecoder,
fromPlainDecoder,
withPlainDecoder,
enforceDecoderVersion,
getOriginalBytes,
originalBytesExpectedFailureMessage,
DecoderError (..),
C.ByteOffset,
ByteArray (..),
C.DecodeAction (..),
C.TokenType (..),
getDecoderVersion,
ifDecoderVersionAtLeast,
whenDecoderVersionAtLeast,
unlessDecoderVersionAtLeast,
cborError,
toCborError,
showDecoderError,
invalidKey,
assertTag,
enforceSize,
matchSize,
binaryGetDecoder,
allowTag,
decodeVersion,
decodeRational,
decodeRationalWithTag,
decodeRecordNamed,
decodeRecordNamedT,
decodeRecordSum,
decodeListLike,
decodeListLikeT,
decodeEnumBounded,
decodeWithOrigin,
decodeMaybe,
decodeNullMaybe,
decodeStrictMaybe,
decodeNullStrictMaybe,
decodeEither,
decodeList,
decodeNonEmptyList,
decodeVector,
decodeSet,
setTag,
decodeIntMap,
decodeMap,
decodeMapByKey,
decodeMapLikeEnforceNoDuplicates,
decodeVMap,
decodeSeq,
decodeStrictSeq,
decodeSetTag,
decodeListLikeWithCount,
decodeListLikeWithCountT,
decodeSetLikeEnforceNoDuplicates,
decodeListLikeEnforceNoDuplicates,
decodeMapContents,
decodeMapTraverse,
decodeMapContentsTraverse,
decodeUTCTime,
decodeIPv4,
decodeIPv6,
decodeBool,
decodeBreakOr,
decodeByteArray,
decodeByteArrayCanonical,
decodeBytes,
decodeBytesCanonical,
decodeBytesIndef,
decodeDouble,
decodeDoubleCanonical,
decodeFloat,
decodeFloat16Canonical,
decodeFloatCanonical,
decodeInt,
decodeInt16,
decodeInt16Canonical,
decodeInt32,
decodeInt32Canonical,
decodeInt64,
decodeInt64Canonical,
decodeInt8,
decodeInt8Canonical,
decodeIntCanonical,
decodeInteger,
decodeIntegerCanonical,
decodeNatural,
decodeListLen,
decodeListLenCanonical,
decodeListLenCanonicalOf,
decodeListLenIndef,
decodeListLenOf,
decodeListLenOrIndef,
decodeMapLen,
decodeMapLenCanonical,
decodeMapLenIndef,
decodeMapLenOrIndef,
decodeNegWord,
decodeNegWord64,
decodeNegWord64Canonical,
decodeNegWordCanonical,
decodeNull,
decodeSequenceLenIndef,
decodeSequenceLenN,
decodeSimple,
decodeSimpleCanonical,
decodeString,
decodeStringCanonical,
decodeStringIndef,
decodeTag,
decodeTag64,
decodeTag64Canonical,
decodeTagCanonical,
decodeUtf8ByteArray,
decodeUtf8ByteArrayCanonical,
decodeWithByteSpan,
decodeWord,
decodeWord16,
decodeWord16Canonical,
decodeWord32,
decodeWord32Canonical,
decodeWord64,
decodeWord64Canonical,
decodeWord8,
decodeWord8Canonical,
decodeWordCanonical,
decodeWordCanonicalOf,
decodeWordOf,
decodeTerm,
peekAvailable,
peekByteOffset,
peekTokenType,
) where
import Cardano.Ledger.Binary.Plain (
DecoderError (..),
cborError,
invalidKey,
showDecoderError,
toCborError,
)
import qualified Cardano.Ledger.Binary.Plain as Plain (assertTag, decodeTagMaybe)
import Cardano.Ledger.Binary.Version (Version, mkVersion64, natVersion)
import Cardano.Slotting.Slot (WithOrigin, withOriginFromMaybe)
import Codec.CBOR.ByteArray (ByteArray (..))
import qualified Codec.CBOR.Decoding as C (
ByteOffset,
DecodeAction (..),
Decoder,
TokenType (..),
decodeBool,
decodeBreakOr,
decodeByteArray,
decodeByteArrayCanonical,
decodeBytes,
decodeBytesCanonical,
decodeBytesIndef,
decodeDouble,
decodeDoubleCanonical,
decodeFloat,
decodeFloat16Canonical,
decodeFloatCanonical,
decodeInt,
decodeInt16,
decodeInt16Canonical,
decodeInt32,
decodeInt32Canonical,
decodeInt64,
decodeInt64Canonical,
decodeInt8,
decodeInt8Canonical,
decodeIntCanonical,
decodeInteger,
decodeIntegerCanonical,
decodeListLen,
decodeListLenCanonical,
decodeListLenCanonicalOf,
decodeListLenIndef,
decodeListLenOf,
decodeListLenOrIndef,
decodeMapLen,
decodeMapLenCanonical,
decodeMapLenIndef,
decodeMapLenOrIndef,
decodeNegWord,
decodeNegWord64,
decodeNegWord64Canonical,
decodeNegWordCanonical,
decodeNull,
decodeSequenceLenIndef,
decodeSequenceLenN,
decodeSimple,
decodeSimpleCanonical,
decodeString,
decodeStringCanonical,
decodeStringIndef,
decodeTag,
decodeTag64,
decodeTag64Canonical,
decodeTagCanonical,
decodeUtf8ByteArray,
decodeUtf8ByteArrayCanonical,
decodeWithByteSpan,
decodeWord,
decodeWord16,
decodeWord16Canonical,
decodeWord32,
decodeWord32Canonical,
decodeWord64,
decodeWord64Canonical,
decodeWord8,
decodeWord8Canonical,
decodeWordCanonical,
decodeWordCanonicalOf,
decodeWordOf,
peekAvailable,
peekByteOffset,
peekTokenType,
)
import qualified Codec.CBOR.Term as C (Term (..), decodeTerm)
import Control.Monad
import Control.Monad.Trans (MonadTrans (..))
import Control.Monad.Trans.Identity (IdentityT (runIdentityT))
import Data.Binary.Get (Get, getWord32le, runGetOrFail)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
import Data.Functor.Compose (Compose (..))
import Data.IP (IPv4, IPv6, fromHostAddress, fromHostAddress6)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.IntMap as IntMap
import qualified Data.List.NonEmpty as NE (NonEmpty, nonEmpty)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..), maybeToStrictMaybe)
import Data.Ratio ((%))
import qualified Data.Sequence as Seq
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import qualified Data.Text as Text
import Data.Time.Calendar.OrdinalDate (fromOrdinalDate)
import Data.Time.Clock (UTCTime (..), picosecondsToDiffTime)
import Data.Typeable (Proxy (Proxy), Typeable, typeRep)
import qualified Data.VMap as VMap
import qualified Data.Vector.Generic as VG
import Data.Word (Word16, Word32, Word64, Word8)
import Network.Socket (HostAddress6)
import Numeric.Natural (Natural)
import Prelude hiding (decodeFloat)
newtype Decoder s a = Decoder
{ forall s a.
Decoder s a -> Maybe ByteString -> Version -> Decoder s a
runDecoder :: Maybe BSL.ByteString -> Version -> C.Decoder s a
}
instance Functor (Decoder s) where
fmap :: forall a b. (a -> b) -> Decoder s a -> Decoder s b
fmap a -> b
f Decoder s a
d = (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder (\Maybe ByteString
bsl Version
v -> a -> b
f (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a -> Maybe ByteString -> Version -> Decoder s a
forall s a.
Decoder s a -> Maybe ByteString -> Version -> Decoder s a
runDecoder Decoder s a
d Maybe ByteString
bsl Version
v)
{-# INLINE fmap #-}
instance Applicative (Decoder s) where
pure :: forall a. a -> Decoder s a
pure a
x = (Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder (\Maybe ByteString
_ Version
_ -> a -> Decoder s a
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
x)
{-# INLINE pure #-}
Decoder Maybe ByteString -> Version -> Decoder s (a -> b)
f <*> :: forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
<*> Decoder Maybe ByteString -> Version -> Decoder s a
g = (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s b) -> Decoder s b)
-> (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
bsl Version
v -> Maybe ByteString -> Version -> Decoder s (a -> b)
f Maybe ByteString
bsl Version
v Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe ByteString -> Version -> Decoder s a
g Maybe ByteString
bsl Version
v
{-# INLINE (<*>) #-}
Decoder Maybe ByteString -> Version -> Decoder s a
f *> :: forall a b. Decoder s a -> Decoder s b -> Decoder s b
*> Decoder Maybe ByteString -> Version -> Decoder s b
g = (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s b) -> Decoder s b)
-> (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
bsl Version
v -> Maybe ByteString -> Version -> Decoder s a
f Maybe ByteString
bsl Version
v Decoder s a -> Decoder s b -> Decoder s b
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Maybe ByteString -> Version -> Decoder s b
g Maybe ByteString
bsl Version
v
{-# INLINE (*>) #-}
instance Monad (Decoder s) where
Decoder Maybe ByteString -> Version -> Decoder s a
f >>= :: forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
>>= a -> Decoder s b
g = (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s b) -> Decoder s b)
-> (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
bsl Version
v -> do
a
x <- Maybe ByteString -> Version -> Decoder s a
f Maybe ByteString
bsl Version
v
Decoder s b -> Maybe ByteString -> Version -> Decoder s b
forall s a.
Decoder s a -> Maybe ByteString -> Version -> Decoder s a
runDecoder (a -> Decoder s b
g a
x) Maybe ByteString
bsl Version
v
{-# INLINE (>>=) #-}
instance MonadFail (Decoder s) where
fail :: forall a. String -> Decoder s a
fail String
msg = Decoder s a -> Decoder s a
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s a -> Decoder s a) -> Decoder s a -> Decoder s a
forall a b. (a -> b) -> a -> b
$ String -> Decoder s a
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
msg
{-# INLINE fail #-}
fromPlainDecoder :: C.Decoder s a -> Decoder s a
fromPlainDecoder :: forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s a
d = (Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder (\Maybe ByteString
_ Version
_ -> Decoder s a
d)
{-# INLINE fromPlainDecoder #-}
toPlainDecoder ::
Maybe BSL.ByteString ->
Version ->
Decoder s a ->
C.Decoder s a
toPlainDecoder :: forall s a.
Maybe ByteString -> Version -> Decoder s a -> Decoder s a
toPlainDecoder Maybe ByteString
bsl Version
v (Decoder Maybe ByteString -> Version -> Decoder s a
d) = Maybe ByteString -> Version -> Decoder s a
d Maybe ByteString
bsl Version
v
{-# INLINE toPlainDecoder #-}
withPlainDecoder :: Decoder s a -> (C.Decoder s a -> C.Decoder s b) -> Decoder s b
withPlainDecoder :: forall s a b.
Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
withPlainDecoder Decoder s a
vd Decoder s a -> Decoder s b
f = (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s b) -> Decoder s b)
-> (Maybe ByteString -> Version -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
bsl -> Decoder s a -> Decoder s b
f (Decoder s a -> Decoder s b)
-> (Version -> Decoder s a) -> Version -> Decoder s b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Decoder s a -> Maybe ByteString -> Version -> Decoder s a
forall s a.
Decoder s a -> Maybe ByteString -> Version -> Decoder s a
runDecoder Decoder s a
vd Maybe ByteString
bsl
{-# INLINE withPlainDecoder #-}
enforceDecoderVersion :: Version -> Decoder s a -> Decoder s a
enforceDecoderVersion :: forall s a. Version -> Decoder s a -> Decoder s a
enforceDecoderVersion Version
version Decoder s a
d = (Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s a) -> Decoder s a)
-> (Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
bsl Version
_ -> Decoder s a -> Maybe ByteString -> Version -> Decoder s a
forall s a.
Decoder s a -> Maybe ByteString -> Version -> Decoder s a
runDecoder Decoder s a
d Maybe ByteString
bsl Version
version
{-# INLINE enforceDecoderVersion #-}
getOriginalBytes :: Decoder s BSL.ByteString
getOriginalBytes :: forall s. Decoder s ByteString
getOriginalBytes =
(Maybe ByteString -> Version -> Decoder s ByteString)
-> Decoder s ByteString
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s ByteString)
-> Decoder s ByteString)
-> (Maybe ByteString -> Version -> Decoder s ByteString)
-> Decoder s ByteString
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
maybeBytes Version
_ ->
case Maybe ByteString
maybeBytes of
Maybe ByteString
Nothing -> String -> Decoder s ByteString
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
originalBytesExpectedFailureMessage
Just ByteString
bsl -> ByteString -> Decoder s ByteString
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
bsl
originalBytesExpectedFailureMessage :: String
originalBytesExpectedFailureMessage :: String
originalBytesExpectedFailureMessage =
String
"Decoder was expected to provide the original ByteString"
getDecoderVersion :: Decoder s Version
getDecoderVersion :: forall s. Decoder s Version
getDecoderVersion = (Maybe ByteString -> Version -> Decoder s Version)
-> Decoder s Version
forall s a.
(Maybe ByteString -> Version -> Decoder s a) -> Decoder s a
Decoder ((Maybe ByteString -> Version -> Decoder s Version)
-> Decoder s Version)
-> (Maybe ByteString -> Version -> Decoder s Version)
-> Decoder s Version
forall a b. (a -> b) -> a -> b
$ \Maybe ByteString
_ -> Version -> Decoder s Version
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# INLINE getDecoderVersion #-}
ifDecoderVersionAtLeast ::
Version ->
Decoder s a ->
Decoder s a ->
Decoder s a
ifDecoderVersionAtLeast :: forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast Version
atLeast Decoder s a
newerDecoder Decoder s a
olderDecoder = do
Version
cur <- Decoder s Version
forall s. Decoder s Version
getDecoderVersion
if Version
cur Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= Version
atLeast
then Decoder s a
newerDecoder
else Decoder s a
olderDecoder
{-# INLINE ifDecoderVersionAtLeast #-}
whenDecoderVersionAtLeast ::
Version ->
Decoder s a ->
Decoder s ()
whenDecoderVersionAtLeast :: forall s a. Version -> Decoder s a -> Decoder s ()
whenDecoderVersionAtLeast Version
atLeast Decoder s a
decoder = do
Version
cur <- Decoder s Version
forall s. Decoder s Version
getDecoderVersion
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Version
cur Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= Version
atLeast) (Decoder s a -> Decoder s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Decoder s a
decoder)
{-# INLINE whenDecoderVersionAtLeast #-}
unlessDecoderVersionAtLeast ::
Version ->
Decoder s a ->
Decoder s ()
unlessDecoderVersionAtLeast :: forall s a. Version -> Decoder s a -> Decoder s ()
unlessDecoderVersionAtLeast Version
atLeast Decoder s a
decoder = do
Version
cur <- Decoder s Version
forall s. Decoder s Version
getDecoderVersion
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Version
cur Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
>= Version
atLeast) (Decoder s a -> Decoder s ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Decoder s a
decoder)
decodeVersion :: Decoder s Version
decodeVersion :: forall s. Decoder s Version
decodeVersion = Decoder s Word64
forall s. Decoder s Word64
decodeWord64 Decoder s Word64
-> (Word64 -> Decoder s Version) -> Decoder s Version
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word64 -> Decoder s Version
forall (m :: * -> *). MonadFail m => Word64 -> m Version
mkVersion64
{-# INLINE decodeVersion #-}
decodeRational :: Decoder s Rational
decodeRational :: forall s. Decoder s Rational
decodeRational =
Version
-> Decoder s Rational -> Decoder s Rational -> Decoder s Rational
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(Word -> Decoder s ()
forall s. Word -> Decoder s ()
allowTag Word
30 Decoder s () -> Decoder s Rational -> Decoder s Rational
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder s Rational
forall s. Decoder s Rational
decodeRationalWithoutTag)
( Version
-> Decoder s Rational -> Decoder s Rational -> Decoder s Rational
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
Decoder s Rational
forall s. Decoder s Rational
decodeRationalWithoutTag
Decoder s Rational
forall s. Decoder s Rational
decodeRationalFixedSizeTuple
)
where
decodeRationalFixedSizeTuple :: Decoder s Rational
decodeRationalFixedSizeTuple = do
Text -> Int -> Decoder s ()
forall s. Text -> Int -> Decoder s ()
enforceSize Text
"Rational" Int
2
Integer
n <- Decoder s Integer
forall s. Decoder s Integer
decodeInteger
Integer
d <- Decoder s Integer
forall s. Decoder s Integer
decodeInteger
if Integer
d Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
0
then DecoderError -> Decoder s Rational
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s Rational)
-> DecoderError -> Decoder s Rational
forall a b. (a -> b) -> a -> b
$ Text -> Text -> DecoderError
DecoderErrorCustom Text
"Rational" Text
"invalid denominator"
else Rational -> Decoder s Rational
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> Decoder s Rational) -> Rational -> Decoder s Rational
forall a b. (a -> b) -> a -> b
$! Integer
n Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
d
{-# INLINE decodeRationalFixedSizeTuple #-}
{-# INLINE decodeRational #-}
_decodeRationalFuture :: Decoder s Rational
_decodeRationalFuture :: forall s. Decoder s Rational
_decodeRationalFuture = do
Version
v9 <- Word64 -> Decoder s Version
forall (m :: * -> *). MonadFail m => Word64 -> m Version
mkVersion64 Word64
9
Version
v10 <- Word64 -> Decoder s Version
forall (m :: * -> *). MonadFail m => Word64 -> m Version
mkVersion64 Word64
10
Version
-> Decoder s Rational -> Decoder s Rational -> Decoder s Rational
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
Version
v10
Decoder s Rational
forall s. Decoder s Rational
decodeRationalWithTag
( Version
-> Decoder s Rational -> Decoder s Rational -> Decoder s Rational
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
Version
v9
(Word -> Decoder s ()
forall s. Word -> Decoder s ()
allowTag Word
30 Decoder s () -> Decoder s Rational -> Decoder s Rational
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder s Rational
forall s. Decoder s Rational
decodeRational)
Decoder s Rational
forall s. Decoder s Rational
decodeRational
)
decodeRationalWithTag :: Decoder s Rational
decodeRationalWithTag :: forall s. Decoder s Rational
decodeRationalWithTag = Word -> Decoder s ()
forall s. Word -> Decoder s ()
assertTag Word
30 Decoder s () -> Decoder s Rational -> Decoder s Rational
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder s Rational
forall s. Decoder s Rational
decodeRationalWithoutTag
{-# INLINE decodeRationalWithTag #-}
decodeRationalWithoutTag :: Decoder s Rational
decodeRationalWithoutTag :: forall s. Decoder s Rational
decodeRationalWithoutTag = do
(Int
numValues, [Integer]
values) <- Decoder s (Maybe Int)
-> Decoder s Integer -> Decoder s (Int, [Integer])
forall s v.
Decoder s (Maybe Int) -> Decoder s v -> Decoder s (Int, [v])
decodeCollectionWithLen Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef Decoder s Integer
forall s. Decoder s Integer
decodeInteger
case [Integer]
values of
[Integer
n, Integer
d] -> do
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Integer
d Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
0) (String -> Decoder s ()
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Denominator cannot be zero")
Rational -> Decoder s Rational
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Rational -> Decoder s Rational) -> Rational -> Decoder s Rational
forall a b. (a -> b) -> a -> b
$! Integer
n Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
d
[Integer]
_ -> DecoderError -> Decoder s Rational
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s Rational)
-> DecoderError -> Decoder s Rational
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> DecoderError
DecoderErrorSizeMismatch Text
"Rational" Int
2 Int
numValues
{-# INLINE decodeRationalWithoutTag #-}
decodeList :: Decoder s a -> Decoder s [a]
decodeList :: forall s a. Decoder s a -> Decoder s [a]
decodeList Decoder s a
decodeValue =
Version -> Decoder s [a] -> Decoder s [a] -> Decoder s [a]
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
(Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef Decoder s a
decodeValue)
(Decoder s a -> Decoder s [a]
forall s a. Decoder s a -> Decoder s [a]
decodeListWith Decoder s a
decodeValue)
{-# INLINE decodeList #-}
decodeNonEmptyList :: Decoder s a -> Decoder s (NE.NonEmpty a)
decodeNonEmptyList :: forall s a. Decoder s a -> Decoder s (NonEmpty a)
decodeNonEmptyList Decoder s a
decodeValue = do
[a]
xs <- Decoder s a -> Decoder s [a]
forall s a. Decoder s a -> Decoder s [a]
decodeList Decoder s a
decodeValue
case [a] -> Maybe (NonEmpty a)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [a]
xs of
Maybe (NonEmpty a)
Nothing -> String -> Decoder s (NonEmpty a)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Empty list found, expected non-empty"
Just NonEmpty a
ne -> NonEmpty a -> Decoder s (NonEmpty a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NonEmpty a
ne
{-# INLINE decodeNonEmptyList #-}
decodeListWith :: Decoder s a -> Decoder s [a]
decodeListWith :: forall s a. Decoder s a -> Decoder s [a]
decodeListWith Decoder s a
decodeValue = do
Decoder s ()
forall s. Decoder s ()
decodeListLenIndef
([a] -> a -> [a])
-> [a] -> ([a] -> [a]) -> Decoder s a -> Decoder s [a]
forall r a b s.
(r -> a -> r) -> r -> (r -> b) -> Decoder s a -> Decoder s b
decodeSequenceLenIndef ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (:)) [] [a] -> [a]
forall a. [a] -> [a]
reverse Decoder s a
decodeValue
{-# INLINE decodeListWith #-}
decodeMaybe :: Decoder s a -> Decoder s (Maybe a)
decodeMaybe :: forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybe Decoder s a
decodeValue = do
Version
-> Decoder s (Maybe a)
-> Decoder s (Maybe a)
-> Decoder s (Maybe a)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
(Decoder s a -> Decoder s (Maybe a)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybeVarLen Decoder s a
decodeValue)
(Decoder s a -> Decoder s (Maybe a)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybeExactLen Decoder s a
decodeValue)
{-# INLINE decodeMaybe #-}
decodeMaybeExactLen :: Decoder s a -> Decoder s (Maybe a)
decodeMaybeExactLen :: forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybeExactLen Decoder s a
decodeValue = do
Int
n <- Decoder s Int
forall s. Decoder s Int
decodeListLen
case Int
n of
Int
0 -> Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
Int
1 -> do
!a
x <- Decoder s a
decodeValue
Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
Int
_ -> String -> Decoder s (Maybe a)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"too many elements while decoding Maybe."
{-# INLINE decodeMaybeExactLen #-}
decodeMaybeVarLen :: Decoder s a -> Decoder s (Maybe a)
decodeMaybeVarLen :: forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybeVarLen Decoder s a
decodeValue = do
Maybe Int
maybeLength <- Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef
case Maybe Int
maybeLength of
Just Int
0 -> Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
Just Int
1 -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Decoder s a -> Decoder s (Maybe a)
forall (m :: * -> *) a b. Monad m => (a -> b) -> m a -> m b
<$!> Decoder s a
decodeValue
Just Int
_ -> String -> Decoder s (Maybe a)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"too many elements in length-style decoding of Maybe."
Maybe Int
Nothing -> do
Bool
isBreak <- Decoder s Bool
forall s. Decoder s Bool
decodeBreakOr
if Bool
isBreak
then Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
else do
!a
x <- Decoder s a
decodeValue
Bool
isBreak2 <- Decoder s Bool
forall s. Decoder s Bool
decodeBreakOr
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
isBreak2 (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
String -> Decoder s ()
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"too many elements in break-style decoding of Maybe."
Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just a
x)
{-# INLINE decodeMaybeVarLen #-}
decodeNullMaybe :: Decoder s a -> Decoder s (Maybe a)
decodeNullMaybe :: forall s a. Decoder s a -> Decoder s (Maybe a)
decodeNullMaybe Decoder s a
decoder = do
Decoder s TokenType
forall s. Decoder s TokenType
peekTokenType Decoder s TokenType
-> (TokenType -> Decoder s (Maybe a)) -> Decoder s (Maybe a)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
TokenType
C.TypeNull -> do
Decoder s ()
forall s. Decoder s ()
decodeNull
Maybe a -> Decoder s (Maybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
TokenType
_ -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Decoder s a -> Decoder s (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a
decoder
{-# INLINE decodeNullMaybe #-}
decodeStrictMaybe :: Decoder s a -> Decoder s (StrictMaybe a)
decodeStrictMaybe :: forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeStrictMaybe = (Maybe a -> StrictMaybe a)
-> Decoder s (Maybe a) -> Decoder s (StrictMaybe a)
forall a b. (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> StrictMaybe a
forall a. Maybe a -> StrictMaybe a
maybeToStrictMaybe (Decoder s (Maybe a) -> Decoder s (StrictMaybe a))
-> (Decoder s a -> Decoder s (Maybe a))
-> Decoder s a
-> Decoder s (StrictMaybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Decoder s a -> Decoder s (Maybe a)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybeVarLen
{-# INLINE decodeStrictMaybe #-}
decodeNullStrictMaybe :: Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe :: forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeNullStrictMaybe Decoder s a
decoder = do
Decoder s TokenType
forall s. Decoder s TokenType
peekTokenType Decoder s TokenType
-> (TokenType -> Decoder s (StrictMaybe a))
-> Decoder s (StrictMaybe a)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
TokenType
C.TypeNull -> do
Decoder s ()
forall s. Decoder s ()
decodeNull
StrictMaybe a -> Decoder s (StrictMaybe a)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure StrictMaybe a
forall a. StrictMaybe a
SNothing
TokenType
_ -> a -> StrictMaybe a
forall a. a -> StrictMaybe a
SJust (a -> StrictMaybe a) -> Decoder s a -> Decoder s (StrictMaybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a
decoder
{-# INLINE decodeNullStrictMaybe #-}
decodeEither :: Decoder s a -> Decoder s b -> Decoder s (Either a b)
decodeEither :: forall s a b. Decoder s a -> Decoder s b -> Decoder s (Either a b)
decodeEither Decoder s a
decodeLeft Decoder s b
decodeRight = do
Int -> Decoder s ()
forall s. Int -> Decoder s ()
decodeListLenOf Int
2
Word
t <- Decoder s Word
forall s. Decoder s Word
decodeWord
case Word
t of
Word
0 -> a -> Either a b
forall a b. a -> Either a b
Left (a -> Either a b) -> Decoder s a -> Decoder s (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a
decodeLeft
Word
1 -> b -> Either a b
forall a b. b -> Either a b
Right (b -> Either a b) -> Decoder s b -> Decoder s (Either a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s b
decodeRight
Word
_ -> DecoderError -> Decoder s (Either a b)
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s (Either a b))
-> DecoderError -> Decoder s (Either a b)
forall a b. (a -> b) -> a -> b
$ Text -> Word8 -> DecoderError
DecoderErrorUnknownTag Text
"Either" (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
t)
{-# INLINE decodeEither #-}
decodeRecordNamed :: Text.Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed :: forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
name a -> Int
getRecordSize Decoder s a
decoder = do
IdentityT (Decoder s) a -> Decoder s a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT (IdentityT (Decoder s) a -> Decoder s a)
-> IdentityT (Decoder s) a -> Decoder s a
forall a b. (a -> b) -> a -> b
$ Text
-> (a -> Int) -> IdentityT (Decoder s) a -> IdentityT (Decoder s) a
forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text -> (a -> Int) -> m (Decoder s) a -> m (Decoder s) a
decodeRecordNamedT Text
name a -> Int
getRecordSize (Decoder s a -> IdentityT (Decoder s) a
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s a
decoder)
{-# INLINE decodeRecordNamed #-}
decodeRecordNamedT ::
(MonadTrans m, Monad (m (Decoder s))) =>
Text.Text ->
(a -> Int) ->
m (Decoder s) a ->
m (Decoder s) a
decodeRecordNamedT :: forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text -> (a -> Int) -> m (Decoder s) a -> m (Decoder s) a
decodeRecordNamedT Text
name a -> Int
getRecordSize m (Decoder s) a
decoder =
Text
-> m (Decoder s) a
-> (a -> Int -> m (Decoder s) ())
-> m (Decoder s) a
forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text
-> m (Decoder s) a
-> (a -> Int -> m (Decoder s) ())
-> m (Decoder s) a
decodeListLikeT Text
name m (Decoder s) a
decoder ((a -> Int -> m (Decoder s) ()) -> m (Decoder s) a)
-> (a -> Int -> m (Decoder s) ()) -> m (Decoder s) a
forall a b. (a -> b) -> a -> b
$ \a
result Int
n ->
Decoder s () -> m (Decoder s) ()
forall (m :: * -> *) a. Monad m => m a -> m m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Decoder s () -> m (Decoder s) ())
-> Decoder s () -> m (Decoder s) ()
forall a b. (a -> b) -> a -> b
$ Text -> Int -> Int -> Decoder s ()
forall s. Text -> Int -> Int -> Decoder s ()
matchSize (Text
"Record " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name) Int
n (a -> Int
getRecordSize a
result)
{-# INLINE decodeRecordNamedT #-}
decodeRecordSum :: Text.Text -> (Word -> Decoder s (Int, a)) -> Decoder s a
decodeRecordSum :: forall s a. Text -> (Word -> Decoder s (Int, a)) -> Decoder s a
decodeRecordSum Text
name Word -> Decoder s (Int, a)
decoder =
(Int, a) -> a
forall a b. (a, b) -> b
snd ((Int, a) -> a) -> Decoder s (Int, a) -> Decoder s a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
Text
-> Decoder s (Int, a)
-> ((Int, a) -> Int -> Decoder s ())
-> Decoder s (Int, a)
forall s a.
Text -> Decoder s a -> (a -> Int -> Decoder s ()) -> Decoder s a
decodeListLike Text
name (Decoder s Word
forall s. Decoder s Word
decodeWord Decoder s Word
-> (Word -> Decoder s (Int, a)) -> Decoder s (Int, a)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Word -> Decoder s (Int, a)
decoder) (((Int, a) -> Int -> Decoder s ()) -> Decoder s (Int, a))
-> ((Int, a) -> Int -> Decoder s ()) -> Decoder s (Int, a)
forall a b. (a -> b) -> a -> b
$ \(Int
size, a
_) Int
n ->
Text -> Int -> Int -> Decoder s ()
forall s. Text -> Int -> Int -> Decoder s ()
matchSize (String -> Text
Text.pack String
"Sum " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name) Int
size Int
n
{-# INLINE decodeRecordSum #-}
decodeListLike ::
Text.Text ->
Decoder s a ->
(a -> Int -> Decoder s ()) ->
Decoder s a
decodeListLike :: forall s a.
Text -> Decoder s a -> (a -> Int -> Decoder s ()) -> Decoder s a
decodeListLike Text
name Decoder s a
decoder a -> Int -> Decoder s ()
actOnLength =
IdentityT (Decoder s) a -> Decoder s a
forall {k} (f :: k -> *) (a :: k). IdentityT f a -> f a
runIdentityT (IdentityT (Decoder s) a -> Decoder s a)
-> IdentityT (Decoder s) a -> Decoder s a
forall a b. (a -> b) -> a -> b
$ Text
-> IdentityT (Decoder s) a
-> (a -> Int -> IdentityT (Decoder s) ())
-> IdentityT (Decoder s) a
forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text
-> m (Decoder s) a
-> (a -> Int -> m (Decoder s) ())
-> m (Decoder s) a
decodeListLikeT Text
name (Decoder s a -> IdentityT (Decoder s) a
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s a
decoder) (\a
r Int
i -> Decoder s () -> IdentityT (Decoder s) ()
forall (m :: * -> *) a. Monad m => m a -> IdentityT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> Int -> Decoder s ()
actOnLength a
r Int
i))
{-# INLINE decodeListLike #-}
decodeListLikeT ::
(MonadTrans m, Monad (m (Decoder s))) =>
Text.Text ->
m (Decoder s) a ->
(a -> Int -> m (Decoder s) ()) ->
m (Decoder s) a
decodeListLikeT :: forall (m :: (* -> *) -> * -> *) s a.
(MonadTrans m, Monad (m (Decoder s))) =>
Text
-> m (Decoder s) a
-> (a -> Int -> m (Decoder s) ())
-> m (Decoder s) a
decodeListLikeT Text
name m (Decoder s) a
decoder a -> Int -> m (Decoder s) ()
actOnLength = do
Maybe Int
lenOrIndef <- Decoder s (Maybe Int) -> m (Decoder s) (Maybe Int)
forall (m :: * -> *) a. Monad m => m a -> m m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef
a
result <- m (Decoder s) a
decoder
case Maybe Int
lenOrIndef of
Just Int
n -> a -> Int -> m (Decoder s) ()
actOnLength a
result Int
n
Maybe Int
Nothing -> Decoder s () -> m (Decoder s) ()
forall (m :: * -> *) a. Monad m => m a -> m m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Decoder s () -> m (Decoder s) ())
-> Decoder s () -> m (Decoder s) ()
forall a b. (a -> b) -> a -> b
$ do
Bool
isBreak <- Decoder s Bool
forall s. Decoder s Bool
decodeBreakOr
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
isBreak (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ DecoderError -> Decoder s ()
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s ()) -> DecoderError -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ Text -> Text -> DecoderError
DecoderErrorCustom Text
name Text
"Excess terms in array"
a -> m (Decoder s) a
forall a. a -> m (Decoder s) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
result
{-# INLINE decodeListLikeT #-}
decodeEnumBounded :: forall a s. (Enum a, Bounded a, Typeable a) => Decoder s a
decodeEnumBounded :: forall a s. (Enum a, Bounded a, Typeable a) => Decoder s a
decodeEnumBounded = do
Int
n <- Decoder s Int
forall s. Decoder s Int
decodeInt
if a -> Int
forall a. Enum a => a -> Int
fromEnum (a
forall a. Bounded a => a
minBound :: a) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
n Bool -> Bool -> Bool
&& Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= a -> Int
forall a. Enum a => a -> Int
fromEnum (a
forall a. Bounded a => a
maxBound :: a)
then a -> Decoder s a
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Decoder s a) -> a -> Decoder s a
forall a b. (a -> b) -> a -> b
$ Int -> a
forall a. Enum a => Int -> a
toEnum Int
n
else
String -> Decoder s a
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s a) -> String -> Decoder s a
forall a b. (a -> b) -> a -> b
$
String
"Failed to decode an Enum: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
n String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" for TypeRep: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> TypeRep -> String
forall a. Show a => a -> String
show (Proxy a -> TypeRep
forall {k} (proxy :: k -> *) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @a))
{-# INLINE decodeEnumBounded #-}
decodeWithOrigin :: Decoder s a -> Decoder s (WithOrigin a)
decodeWithOrigin :: forall s a. Decoder s a -> Decoder s (WithOrigin a)
decodeWithOrigin Decoder s a
f = Maybe a -> WithOrigin a
forall t. Maybe t -> WithOrigin t
withOriginFromMaybe (Maybe a -> WithOrigin a)
-> Decoder s (Maybe a) -> Decoder s (WithOrigin a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s a -> Decoder s (Maybe a)
forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybe Decoder s a
f
{-# INLINE decodeWithOrigin #-}
decodeMapSkel ::
forall k m v s.
Ord k =>
([(k, v)] -> m) ->
Decoder s (k, v) ->
Decoder s m
decodeMapSkel :: forall k m v s.
Ord k =>
([(k, v)] -> m) -> Decoder s (k, v) -> Decoder s m
decodeMapSkel [(k, v)] -> m
fromDistinctDescList Decoder s (k, v)
decodeKeyValue = do
Int
n <- Decoder s Int
forall s. Decoder s Int
decodeMapLen
[(k, v)] -> m
fromDistinctDescList ([(k, v)] -> m) -> Decoder s [(k, v)] -> Decoder s m
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Int
n of
Int
0 -> [(k, v)] -> Decoder s [(k, v)]
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Int
_ -> do
(k
firstKey, v
firstValue) <- Decoder s (k, v)
decodeKeyValue
Int -> k -> [(k, v)] -> Decoder s [(k, v)]
decodeEntries (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) k
firstKey [(k
firstKey, v
firstValue)]
where
decodeEntries :: Int -> k -> [(k, v)] -> Decoder s [(k, v)]
decodeEntries :: Int -> k -> [(k, v)] -> Decoder s [(k, v)]
decodeEntries Int
0 k
_ [(k, v)]
acc = [(k, v)] -> Decoder s [(k, v)]
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [(k, v)]
acc
decodeEntries !Int
remainingPairs k
previousKey ![(k, v)]
acc = do
p :: (k, v)
p@(k
newKey, v
_) <- Decoder s (k, v)
decodeKeyValue
if k
newKey k -> k -> Bool
forall a. Ord a => a -> a -> Bool
> k
previousKey
then Int -> k -> [(k, v)] -> Decoder s [(k, v)]
decodeEntries (Int
remainingPairs Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) k
newKey ((k, v)
p (k, v) -> [(k, v)] -> [(k, v)]
forall a. a -> [a] -> [a]
: [(k, v)]
acc)
else DecoderError -> Decoder s [(k, v)]
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s [(k, v)])
-> DecoderError -> Decoder s [(k, v)]
forall a b. (a -> b) -> a -> b
$ Text -> DecoderError
DecoderErrorCanonicityViolation Text
"Map"
{-# INLINE decodeMapSkel #-}
decodeCollection :: Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection :: forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
lenOrIndef Decoder s a
el = (Int, [a]) -> [a]
forall a b. (a, b) -> b
snd ((Int, [a]) -> [a]) -> Decoder s (Int, [a]) -> Decoder s [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s a -> Decoder s (Int, [a])
forall s v.
Decoder s (Maybe Int) -> Decoder s v -> Decoder s (Int, [v])
decodeCollectionWithLen Decoder s (Maybe Int)
lenOrIndef Decoder s a
el
{-# INLINE decodeCollection #-}
decodeCollectionWithLen ::
Decoder s (Maybe Int) ->
Decoder s v ->
Decoder s (Int, [v])
decodeCollectionWithLen :: forall s v.
Decoder s (Maybe Int) -> Decoder s v -> Decoder s (Int, [v])
decodeCollectionWithLen Decoder s (Maybe Int)
lenOrIndef Decoder s v
decodeElement =
([v] -> [v]) -> (Int, [v]) -> (Int, [v])
forall a b. (a -> b) -> (Int, a) -> (Int, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [v] -> [v]
forall a. [a] -> [a]
reverse ((Int, [v]) -> (Int, [v]))
-> Decoder s (Int, [v]) -> Decoder s (Int, [v])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int)
-> (v -> [v] -> [v])
-> ([v] -> Decoder s v)
-> Decoder s (Int, [v])
forall s a b.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> Decoder s a) -> Decoder s (Int, b)
decodeListLikeWithCount Decoder s (Maybe Int)
lenOrIndef (:) (Decoder s v -> [v] -> Decoder s v
forall a b. a -> b -> a
const Decoder s v
decodeElement)
{-# INLINE decodeCollectionWithLen #-}
decodeMap ::
Ord k =>
Decoder s k ->
Decoder s v ->
Decoder s (Map.Map k v)
decodeMap :: forall k s v.
Ord k =>
Decoder s k -> Decoder s v -> Decoder s (Map k v)
decodeMap Decoder s k
decodeKey Decoder s v
decodeValue = Decoder s k -> (k -> Decoder s v) -> Decoder s (Map k v)
forall k s v.
Ord k =>
Decoder s k -> (k -> Decoder s v) -> Decoder s (Map k v)
decodeMapByKey Decoder s k
decodeKey (Decoder s v -> k -> Decoder s v
forall a b. a -> b -> a
const Decoder s v
decodeValue)
{-# INLINE decodeMap #-}
decodeMapByKey ::
Ord k =>
Decoder s k ->
(k -> Decoder s v) ->
Decoder s (Map.Map k v)
decodeMapByKey :: forall k s v.
Ord k =>
Decoder s k -> (k -> Decoder s v) -> Decoder s (Map k v)
decodeMapByKey Decoder s k
decodeKey k -> Decoder s v
decodeValue =
Version
-> Decoder s (Map k v)
-> Decoder s (Map k v)
-> Decoder s (Map k v)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
( Version
-> Decoder s (Map k v)
-> Decoder s (Map k v)
-> Decoder s (Map k v)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s (Map k v)
forall k s v.
Ord k =>
Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s (Map k v)
decodeMapLikeEnforceNoDuplicates Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef Decoder s (k, v)
decodeKeyValue)
([(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(k, v)] -> Map k v) -> Decoder s [(k, v)] -> Decoder s (Map k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s [(k, v)]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef Decoder s (k, v)
decodeKeyValue)
)
(([(k, v)] -> Map k v) -> Decoder s (k, v) -> Decoder s (Map k v)
forall k m v s.
Ord k =>
([(k, v)] -> m) -> Decoder s (k, v) -> Decoder s m
decodeMapSkel [(k, v)] -> Map k v
forall k a. [(k, a)] -> Map k a
Map.fromDistinctDescList Decoder s (k, v)
decodeKeyValue)
where
decodeKeyValue :: Decoder s (k, v)
decodeKeyValue = do
!k
key <- Decoder s k
decodeKey
!v
value <- k -> Decoder s v
decodeValue k
key
(k, v) -> Decoder s (k, v)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (k
key, v
value)
{-# INLINE decodeKeyValue #-}
{-# INLINE decodeMapByKey #-}
decodeMapLikeEnforceNoDuplicates ::
Ord k =>
Decoder s (Maybe Int) ->
Decoder s (k, v) ->
Decoder s (Map.Map k v)
decodeMapLikeEnforceNoDuplicates :: forall k s v.
Ord k =>
Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s (Map k v)
decodeMapLikeEnforceNoDuplicates =
([(k, v)] -> Map k v)
-> (Map k v -> Int)
-> Decoder s (Maybe Int)
-> Decoder s (k, v)
-> Decoder s (Map k v)
forall k v m s.
([(k, v)] -> m)
-> (m -> Int)
-> Decoder s (Maybe Int)
-> Decoder s (k, v)
-> Decoder s m
decodeMapLikeEnforceNoDuplicatesInternal [(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList Map k v -> Int
forall k a. Map k a -> Int
Map.size
{-# INLINE decodeMapLikeEnforceNoDuplicates #-}
decodeMapLikeEnforceNoDuplicatesInternal ::
([(k, v)] -> m) ->
(m -> Int) ->
Decoder s (Maybe Int) ->
Decoder s (k, v) ->
Decoder s m
decodeMapLikeEnforceNoDuplicatesInternal :: forall k v m s.
([(k, v)] -> m)
-> (m -> Int)
-> Decoder s (Maybe Int)
-> Decoder s (k, v)
-> Decoder s m
decodeMapLikeEnforceNoDuplicatesInternal [(k, v)] -> m
fromPairs m -> Int
size Decoder s (Maybe Int)
decodeLenOrIndef =
Decoder s (Maybe Int)
-> ((k, v) -> [(k, v)] -> [(k, v)])
-> ([(k, v)] -> (Int, m))
-> Decoder s (k, v)
-> Decoder s m
forall s a b c.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
decodeListLikeEnforceNoDuplicates Decoder s (Maybe Int)
decodeLenOrIndef (:) (([(k, v)] -> (Int, m)) -> Decoder s (k, v) -> Decoder s m)
-> ([(k, v)] -> (Int, m)) -> Decoder s (k, v) -> Decoder s m
forall a b. (a -> b) -> a -> b
$ \[(k, v)]
xs ->
let result :: m
result = [(k, v)] -> m
fromPairs ([(k, v)] -> [(k, v)]
forall a. [a] -> [a]
reverse [(k, v)]
xs)
in (m -> Int
size m
result, m
result)
decodeIntMap :: Decoder s v -> Decoder s (IntMap.IntMap v)
decodeIntMap :: forall s v. Decoder s v -> Decoder s (IntMap v)
decodeIntMap Decoder s v
decodeValue =
Version
-> Decoder s (IntMap v)
-> Decoder s (IntMap v)
-> Decoder s (IntMap v)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
( Version
-> Decoder s (IntMap v)
-> Decoder s (IntMap v)
-> Decoder s (IntMap v)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
( ([(Int, v)] -> IntMap v)
-> (IntMap v -> Int)
-> Decoder s (Maybe Int)
-> Decoder s (Int, v)
-> Decoder s (IntMap v)
forall k v m s.
([(k, v)] -> m)
-> (m -> Int)
-> Decoder s (Maybe Int)
-> Decoder s (k, v)
-> Decoder s m
decodeMapLikeEnforceNoDuplicatesInternal
[(Int, v)] -> IntMap v
forall a. [(Int, a)] -> IntMap a
IntMap.fromList
IntMap v -> Int
forall a. IntMap a -> Int
IntMap.size
Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef
Decoder s (Int, v)
decodeKeyValue
)
([(Int, v)] -> IntMap v
forall a. [(Int, a)] -> IntMap a
IntMap.fromList ([(Int, v)] -> IntMap v)
-> Decoder s [(Int, v)] -> Decoder s (IntMap v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s (Int, v) -> Decoder s [(Int, v)]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef Decoder s (Int, v)
decodeKeyValue)
)
( ([(Int, v)] -> IntMap v)
-> Decoder s (Int, v) -> Decoder s (IntMap v)
forall k m v s.
Ord k =>
([(k, v)] -> m) -> Decoder s (k, v) -> Decoder s m
decodeMapSkel
([(Int, v)] -> IntMap v
forall a. [(Int, a)] -> IntMap a
IntMap.fromDistinctAscList ([(Int, v)] -> IntMap v)
-> ([(Int, v)] -> [(Int, v)]) -> [(Int, v)] -> IntMap v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Int, v)] -> [(Int, v)]
forall a. [a] -> [a]
reverse)
Decoder s (Int, v)
decodeKeyValue
)
where
decodeKeyValue :: Decoder s (Int, v)
decodeKeyValue = (,) (Int -> v -> (Int, v))
-> Decoder s Int -> Decoder s (v -> (Int, v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Int
forall s. Decoder s Int
decodeInt Decoder s (v -> (Int, v)) -> Decoder s v -> Decoder s (Int, v)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s v
decodeValue
{-# INLINE decodeIntMap #-}
decodeVMap ::
(VMap.Vector kv k, VMap.Vector vv v, Ord k) =>
Decoder s k ->
Decoder s v ->
Decoder s (VMap.VMap kv vv k v)
decodeVMap :: forall (kv :: * -> *) k (vv :: * -> *) v s.
(Vector kv k, Vector vv v, Ord k) =>
Decoder s k -> Decoder s v -> Decoder s (VMap kv vv k v)
decodeVMap Decoder s k
decodeKey Decoder s v
decodeValue =
Map k v -> VMap kv vv k v
forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> VMap kv vv k v
VMap.fromMap
(Map k v -> VMap kv vv k v)
-> Decoder s (Map k v) -> Decoder s (VMap kv vv k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s (Map k v)
forall k s v.
Ord k =>
Decoder s (Maybe Int) -> Decoder s (k, v) -> Decoder s (Map k v)
decodeMapLikeEnforceNoDuplicates
Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef
((,) (k -> v -> (k, v)) -> Decoder s k -> Decoder s (v -> (k, v))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s k
decodeKey Decoder s (v -> (k, v)) -> Decoder s v -> Decoder s (k, v)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s v
decodeValue)
{-# INLINE decodeVMap #-}
setTag :: Word
setTag :: Word
setTag = Word
258
decodeSetTag :: Decoder s ()
decodeSetTag :: forall s. Decoder s ()
decodeSetTag = do
Word
t <- Decoder s Word
forall s. Decoder s Word
decodeTag
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Word
t Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
/= Word
setTag) (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ DecoderError -> Decoder s ()
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s ()) -> DecoderError -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ Text -> Word8 -> DecoderError
DecoderErrorUnknownTag Text
"Set" (Word -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
t)
{-# INLINE decodeSetTag #-}
decodeSetSkel ::
forall a s c.
Ord a =>
([a] -> c) ->
Decoder s a ->
Decoder s c
decodeSetSkel :: forall a s c. Ord a => ([a] -> c) -> Decoder s a -> Decoder s c
decodeSetSkel [a] -> c
fromDistinctDescList Decoder s a
decodeValue = do
Decoder s ()
forall s. Decoder s ()
decodeSetTag
Int
n <- Decoder s Int
forall s. Decoder s Int
decodeListLen
[a] -> c
fromDistinctDescList ([a] -> c) -> Decoder s [a] -> Decoder s c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Int
n of
Int
0 -> [a] -> Decoder s [a]
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return []
Int
_ -> do
a
firstValue <- Decoder s a
decodeValue
Int -> a -> [a] -> Decoder s [a]
decodeEntries (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
firstValue [a
firstValue]
where
decodeEntries :: Int -> a -> [a] -> Decoder s [a]
decodeEntries :: Int -> a -> [a] -> Decoder s [a]
decodeEntries Int
0 a
_ [a]
acc = [a] -> Decoder s [a]
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [a]
acc
decodeEntries !Int
remainingEntries a
previousValue ![a]
acc = do
a
newValue <- Decoder s a
decodeValue
if a
newValue a -> a -> Bool
forall a. Ord a => a -> a -> Bool
> a
previousValue
then Int -> a -> [a] -> Decoder s [a]
decodeEntries (Int
remainingEntries Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
newValue (a
newValue a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
acc)
else DecoderError -> Decoder s [a]
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s [a]) -> DecoderError -> Decoder s [a]
forall a b. (a -> b) -> a -> b
$ Text -> DecoderError
DecoderErrorCanonicityViolation Text
"Set"
{-# INLINE decodeSetSkel #-}
decodeSet :: Ord a => Decoder s a -> Decoder s (Set.Set a)
decodeSet :: forall a s. Ord a => Decoder s a -> Decoder s (Set a)
decodeSet Decoder s a
valueDecoder =
Version
-> Decoder s (Set a) -> Decoder s (Set a) -> Decoder s (Set a)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
( Version
-> Decoder s (Set a) -> Decoder s (Set a) -> Decoder s (Set a)
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(Decoder s a -> Decoder s (Set a)
forall s a. Ord a => Decoder s a -> Decoder s (Set a)
decodeSetEnforceNoDuplicates Decoder s a
valueDecoder)
([a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList ([a] -> Set a) -> Decoder s [a] -> Decoder s (Set a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef Decoder s a
valueDecoder)
)
(([a] -> Set a) -> Decoder s a -> Decoder s (Set a)
forall a s c. Ord a => ([a] -> c) -> Decoder s a -> Decoder s c
decodeSetSkel [a] -> Set a
forall a. [a] -> Set a
Set.fromDistinctDescList Decoder s a
valueDecoder)
{-# INLINE decodeSet #-}
decodeSetEnforceNoDuplicates ::
forall s a.
Ord a =>
Decoder s a ->
Decoder s (Set.Set a)
decodeSetEnforceNoDuplicates :: forall s a. Ord a => Decoder s a -> Decoder s (Set a)
decodeSetEnforceNoDuplicates = (a -> [a] -> [a])
-> ([a] -> (Int, Set a)) -> Decoder s a -> Decoder s (Set a)
forall s a b c.
Monoid b =>
(a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
decodeSetLikeEnforceNoDuplicates (:) (([a] -> (Int, Set a)) -> Decoder s a -> Decoder s (Set a))
-> ([a] -> (Int, Set a)) -> Decoder s a -> Decoder s (Set a)
forall a b. (a -> b) -> a -> b
$ \[a]
xs ->
let result :: Set a
result = [a] -> Set a
forall a. Ord a => [a] -> Set a
Set.fromList ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
xs)
in (Set a -> Int
forall a. Set a -> Int
Set.size Set a
result, Set a
result)
{-# INLINE decodeSetEnforceNoDuplicates #-}
decodeListLikeWithCount ::
forall s a b.
Monoid b =>
Decoder s (Maybe Int) ->
(a -> b -> b) ->
(b -> Decoder s a) ->
Decoder s (Int, b)
decodeListLikeWithCount :: forall s a b.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> Decoder s a) -> Decoder s (Int, b)
decodeListLikeWithCount Decoder s (Maybe Int)
decodeLenOrIndef a -> b -> b
insert b -> Decoder s a
decodeElement = do
Decoder s (Maybe Int)
decodeLenOrIndef Decoder s (Maybe Int)
-> (Maybe Int -> Decoder s (Int, b)) -> Decoder s (Int, b)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Int
len -> (Int -> Decoder s Bool) -> Int -> b -> Decoder s (Int, b)
loop (\Int
x -> Bool -> Decoder s Bool
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len)) Int
0 b
forall a. Monoid a => a
mempty
Maybe Int
Nothing -> (Int -> Decoder s Bool) -> Int -> b -> Decoder s (Int, b)
loop (\Int
_ -> Decoder s Bool
forall s. Decoder s Bool
decodeBreakOr) Int
0 b
forall a. Monoid a => a
mempty
where
loop :: (Int -> Decoder s Bool) -> Int -> b -> Decoder s (Int, b)
loop :: (Int -> Decoder s Bool) -> Int -> b -> Decoder s (Int, b)
loop Int -> Decoder s Bool
condition = Int -> b -> Decoder s (Int, b)
go
where
go :: Int -> b -> Decoder s (Int, b)
go !Int
count !b
acc = do
Bool
shouldStop <- Int -> Decoder s Bool
condition Int
count
if Bool
shouldStop
then (Int, b) -> Decoder s (Int, b)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
count, b
acc)
else do
a
element <- b -> Decoder s a
decodeElement b
acc
Int -> b -> Decoder s (Int, b)
go (Int
count Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (a -> b -> b
insert a
element b
acc)
{-# INLINE loop #-}
{-# INLINE decodeListLikeWithCount #-}
decodeListLikeWithCountT ::
forall t s a b.
(MonadTrans t, Monad (t (Decoder s)), Monoid b) =>
t (Decoder s) (Maybe Int) ->
(a -> b -> b) ->
(b -> t (Decoder s) a) ->
t (Decoder s) (Int, b)
decodeListLikeWithCountT :: forall (t :: (* -> *) -> * -> *) s a b.
(MonadTrans t, Monad (t (Decoder s)), Monoid b) =>
t (Decoder s) (Maybe Int)
-> (a -> b -> b)
-> (b -> t (Decoder s) a)
-> t (Decoder s) (Int, b)
decodeListLikeWithCountT t (Decoder s) (Maybe Int)
decodeLenOrIndef a -> b -> b
insert b -> t (Decoder s) a
decodeElement = do
t (Decoder s) (Maybe Int)
decodeLenOrIndef t (Decoder s) (Maybe Int)
-> (Maybe Int -> t (Decoder s) (Int, b)) -> t (Decoder s) (Int, b)
forall a b.
t (Decoder s) a -> (a -> t (Decoder s) b) -> t (Decoder s) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just Int
len -> (Int -> t (Decoder s) Bool) -> Int -> b -> t (Decoder s) (Int, b)
loop (\Int
x -> Bool -> t (Decoder s) Bool
forall a. a -> t (Decoder s) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len)) Int
0 b
forall a. Monoid a => a
mempty
Maybe Int
Nothing -> (Int -> t (Decoder s) Bool) -> Int -> b -> t (Decoder s) (Int, b)
loop (\Int
_ -> Decoder s Bool -> t (Decoder s) Bool
forall (m :: * -> *) a. Monad m => m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift Decoder s Bool
forall s. Decoder s Bool
decodeBreakOr) Int
0 b
forall a. Monoid a => a
mempty
where
loop :: (Int -> t (Decoder s) Bool) -> Int -> b -> t (Decoder s) (Int, b)
loop Int -> t (Decoder s) Bool
condition = Int -> b -> t (Decoder s) (Int, b)
go
where
go :: Int -> b -> t (Decoder s) (Int, b)
go !Int
count !b
acc = do
Bool
shouldStop <- Int -> t (Decoder s) Bool
condition Int
count
if Bool
shouldStop
then (Int, b) -> t (Decoder s) (Int, b)
forall a. a -> t (Decoder s) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
count, b
acc)
else do
a
element <- b -> t (Decoder s) a
decodeElement b
acc
Int -> b -> t (Decoder s) (Int, b)
go (Int
count Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (a -> b -> b
insert a
element b
acc)
{-# INLINE loop #-}
{-# INLINE decodeListLikeWithCountT #-}
decodeListLikeEnforceNoDuplicates ::
forall s a b c.
Monoid b =>
Decoder s (Maybe Int) ->
(a -> b -> b) ->
(b -> (Int, c)) ->
Decoder s a ->
Decoder s c
decodeListLikeEnforceNoDuplicates :: forall s a b c.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
decodeListLikeEnforceNoDuplicates Decoder s (Maybe Int)
decodeLenOrIndef a -> b -> b
insert b -> (Int, c)
getFinalWithCount Decoder s a
decodeElement = do
(Int
count, b
result) <- Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> Decoder s a) -> Decoder s (Int, b)
forall s a b.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> Decoder s a) -> Decoder s (Int, b)
decodeListLikeWithCount Decoder s (Maybe Int)
decodeLenOrIndef a -> b -> b
insert (Decoder s a -> b -> Decoder s a
forall a b. a -> b -> a
const Decoder s a
decodeElement)
let (Int
len, c
finalResult) = b -> (Int, c)
getFinalWithCount b
result
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
len Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
count) (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
String -> Decoder s ()
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s ()) -> String -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
String
"Final number of elements: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
len
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" does not match the total count that was decoded: "
String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
count
c -> Decoder s c
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure c
finalResult
{-# INLINE decodeListLikeEnforceNoDuplicates #-}
decodeSetLikeEnforceNoDuplicates ::
forall s a b c.
Monoid b =>
(a -> b -> b) ->
(b -> (Int, c)) ->
Decoder s a ->
Decoder s c
decodeSetLikeEnforceNoDuplicates :: forall s a b c.
Monoid b =>
(a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
decodeSetLikeEnforceNoDuplicates a -> b -> b
insert b -> (Int, c)
getFinalWithLen Decoder s a
decodeElement = do
Word -> Decoder s ()
forall s. Word -> Decoder s ()
allowTag Word
setTag
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
forall s a b c.
Monoid b =>
Decoder s (Maybe Int)
-> (a -> b -> b) -> (b -> (Int, c)) -> Decoder s a -> Decoder s c
decodeListLikeEnforceNoDuplicates Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef a -> b -> b
insert b -> (Int, c)
getFinalWithLen Decoder s a
decodeElement
{-# INLINE decodeSetLikeEnforceNoDuplicates #-}
decodeContainerSkelWithReplicate ::
Decoder s Int ->
(Int -> Decoder s c) ->
([c] -> c) ->
Decoder s c
decodeContainerSkelWithReplicate :: forall s c.
Decoder s Int -> (Int -> Decoder s c) -> ([c] -> c) -> Decoder s c
decodeContainerSkelWithReplicate Decoder s Int
decodeLen Int -> Decoder s c
replicateFun [c] -> c
concatList = do
Int
sz <- Decoder s Int
decodeLen
Int
limit <- Decoder s Int
forall s. Decoder s Int
peekAvailable
if Int
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
limit
then Int -> Decoder s c
replicateFun Int
sz
else do
let chunkSize :: Int
chunkSize = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
limit Int
128
(Int
d, Int
m) = Int
sz Int -> Int -> (Int, Int)
forall a. Integral a => a -> a -> (a, a)
`divMod` Int
chunkSize
[c]
containers <- [Decoder s c] -> Decoder s [c]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
forall (m :: * -> *) a. Monad m => [m a] -> m [a]
sequence ([Decoder s c] -> Decoder s [c]) -> [Decoder s c] -> Decoder s [c]
forall a b. (a -> b) -> a -> b
$ Int -> Decoder s c
replicateFun Int
m Decoder s c -> [Decoder s c] -> [Decoder s c]
forall a. a -> [a] -> [a]
: Int -> Decoder s c -> [Decoder s c]
forall a. Int -> a -> [a]
replicate Int
d (Int -> Decoder s c
replicateFun Int
chunkSize)
c -> Decoder s c
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (c -> Decoder s c) -> c -> Decoder s c
forall a b. (a -> b) -> a -> b
$! [c] -> c
concatList [c]
containers
{-# INLINE decodeContainerSkelWithReplicate #-}
decodeVector :: VG.Vector vec a => Decoder s a -> Decoder s (vec a)
decodeVector :: forall (vec :: * -> *) a s.
Vector vec a =>
Decoder s a -> Decoder s (vec a)
decodeVector Decoder s a
decodeValue =
Decoder s Int
-> (Int -> Decoder s (vec a))
-> ([vec a] -> vec a)
-> Decoder s (vec a)
forall s c.
Decoder s Int -> (Int -> Decoder s c) -> ([c] -> c) -> Decoder s c
decodeContainerSkelWithReplicate
Decoder s Int
forall s. Decoder s Int
decodeListLen
(Int -> Decoder s a -> Decoder s (vec a)
forall (m :: * -> *) (v :: * -> *) a.
(Monad m, Vector v a) =>
Int -> m a -> m (v a)
`VG.replicateM` Decoder s a
decodeValue)
[vec a] -> vec a
forall (v :: * -> *) a. Vector v a => [v a] -> v a
VG.concat
{-# INLINE decodeVector #-}
decodeSeq :: Decoder s a -> Decoder s (Seq.Seq a)
decodeSeq :: forall s a. Decoder s a -> Decoder s (Seq a)
decodeSeq Decoder s a
decoder = [a] -> Seq a
forall a. [a] -> Seq a
Seq.fromList ([a] -> Seq a) -> Decoder s [a] -> Decoder s (Seq a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef Decoder s a
decoder
{-# INLINE decodeSeq #-}
decodeStrictSeq :: Decoder s a -> Decoder s (SSeq.StrictSeq a)
decodeStrictSeq :: forall s a. Decoder s a -> Decoder s (StrictSeq a)
decodeStrictSeq Decoder s a
decoder = [a] -> StrictSeq a
forall a. [a] -> StrictSeq a
SSeq.fromList ([a] -> StrictSeq a) -> Decoder s [a] -> Decoder s (StrictSeq a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeListLenOrIndef Decoder s a
decoder
{-# INLINE decodeStrictSeq #-}
decodeMapContents :: Decoder s a -> Decoder s [a]
decodeMapContents :: forall s a. Decoder s a -> Decoder s [a]
decodeMapContents = Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
forall s a. Decoder s (Maybe Int) -> Decoder s a -> Decoder s [a]
decodeCollection Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef
{-# INLINE decodeMapContents #-}
decodeMapTraverse ::
(Ord a, Applicative t) =>
Decoder s (t a) ->
Decoder s (t b) ->
Decoder s (t (Map.Map a b))
decodeMapTraverse :: forall a (t :: * -> *) s b.
(Ord a, Applicative t) =>
Decoder s (t a) -> Decoder s (t b) -> Decoder s (t (Map a b))
decodeMapTraverse Decoder s (t a)
decodeKey Decoder s (t b)
decodeValue =
([(a, b)] -> Map a b) -> t [(a, b)] -> t (Map a b)
forall a b. (a -> b) -> t a -> t b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(a, b)] -> Map a b
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList (t [(a, b)] -> t (Map a b))
-> Decoder s (t [(a, b)]) -> Decoder s (t (Map a b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (t a) -> Decoder s (t b) -> Decoder s (t [(a, b)])
forall (t :: * -> *) s a b.
Applicative t =>
Decoder s (t a) -> Decoder s (t b) -> Decoder s (t [(a, b)])
decodeMapContentsTraverse Decoder s (t a)
decodeKey Decoder s (t b)
decodeValue
{-# INLINE decodeMapTraverse #-}
decodeMapContentsTraverse ::
Applicative t =>
Decoder s (t a) ->
Decoder s (t b) ->
Decoder s (t [(a, b)])
decodeMapContentsTraverse :: forall (t :: * -> *) s a b.
Applicative t =>
Decoder s (t a) -> Decoder s (t b) -> Decoder s (t [(a, b)])
decodeMapContentsTraverse Decoder s (t a)
decodeKey Decoder s (t b)
decodeValue =
[t (a, b)] -> t [(a, b)]
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => [f a] -> f [a]
sequenceA ([t (a, b)] -> t [(a, b)])
-> Decoder s [t (a, b)] -> Decoder s (t [(a, b)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (t (a, b)) -> Decoder s [t (a, b)]
forall s a. Decoder s a -> Decoder s [a]
decodeMapContents Decoder s (t (a, b))
decodeInlinedPair
where
decodeInlinedPair :: Decoder s (t (a, b))
decodeInlinedPair = Compose (Decoder s) t (a, b) -> Decoder s (t (a, b))
forall {k1} {k2} (f :: k1 -> *) (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose (Decoder s) t (a, b) -> Decoder s (t (a, b)))
-> Compose (Decoder s) t (a, b) -> Decoder s (t (a, b))
forall a b. (a -> b) -> a -> b
$ (,) (a -> b -> (a, b))
-> Compose (Decoder s) t a -> Compose (Decoder s) t (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (t a) -> Compose (Decoder s) t a
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose Decoder s (t a)
decodeKey Compose (Decoder s) t (b -> (a, b))
-> Compose (Decoder s) t b -> Compose (Decoder s) t (a, b)
forall a b.
Compose (Decoder s) t (a -> b)
-> Compose (Decoder s) t a -> Compose (Decoder s) t b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s (t b) -> Compose (Decoder s) t b
forall {k} {k1} (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose Decoder s (t b)
decodeValue
{-# INLINE decodeInlinedPair #-}
{-# INLINE decodeMapContentsTraverse #-}
decodeUTCTime :: Decoder s UTCTime
decodeUTCTime :: forall s. Decoder s UTCTime
decodeUTCTime =
Version
-> Decoder s UTCTime -> Decoder s UTCTime -> Decoder s UTCTime
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @2)
(Text -> Int -> Decoder s ()
forall s. Text -> Int -> Decoder s ()
enforceSize Text
"UTCTime" Int
3 Decoder s () -> Decoder s UTCTime -> Decoder s UTCTime
forall a b. Decoder s a -> Decoder s b -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Decoder s UTCTime
forall s. Decoder s UTCTime
timeDecoder)
(Text -> (UTCTime -> Int) -> Decoder s UTCTime -> Decoder s UTCTime
forall a s. Text -> (a -> Int) -> Decoder s a -> Decoder s a
decodeRecordNamed Text
"UTCTime" (Int -> UTCTime -> Int
forall a b. a -> b -> a
const Int
3) Decoder s UTCTime
forall s. Decoder s UTCTime
timeDecoder)
where
timeDecoder :: Decoder s UTCTime
timeDecoder = do
!Integer
year <- Decoder s Integer
forall s. Decoder s Integer
decodeInteger
!Int
dayOfYear <- Decoder s Int
forall s. Decoder s Int
decodeInt
!Integer
timeOfDayPico <- Decoder s Integer
forall s. Decoder s Integer
decodeInteger
UTCTime -> Decoder s UTCTime
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> Decoder s UTCTime) -> UTCTime -> Decoder s UTCTime
forall a b. (a -> b) -> a -> b
$!
Day -> DiffTime -> UTCTime
UTCTime
(Integer -> Int -> Day
fromOrdinalDate Integer
year Int
dayOfYear)
(Integer -> DiffTime
picosecondsToDiffTime Integer
timeOfDayPico)
{-# INLINE timeDecoder #-}
{-# INLINE decodeUTCTime #-}
binaryGetDecoder ::
Bool ->
Text.Text ->
Get a ->
Decoder s a
binaryGetDecoder :: forall a s. Bool -> Text -> Get a -> Decoder s a
binaryGetDecoder Bool
allowLeftOver Text
name Get a
getter = do
ByteString
bs <- Decoder s ByteString
forall s. Decoder s ByteString
decodeBytes
case Get a
-> ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
forall a.
Get a
-> ByteString
-> Either
(ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
runGetOrFail Get a
getter (ByteString -> ByteString
BSL.fromStrict ByteString
bs) of
Left (ByteString
_, ByteOffset
_, String
err) -> DecoderError -> Decoder s a
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s a) -> DecoderError -> Decoder s a
forall a b. (a -> b) -> a -> b
$ Text -> Text -> DecoderError
DecoderErrorCustom Text
name (String -> Text
Text.pack String
err)
Right (ByteString
leftOver, ByteOffset
_, a
ha)
| Bool
allowLeftOver Bool -> Bool -> Bool
|| ByteString -> Bool
BSL.null ByteString
leftOver -> a -> Decoder s a
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
ha
| Bool
otherwise ->
DecoderError -> Decoder s a
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s a) -> DecoderError -> Decoder s a
forall a b. (a -> b) -> a -> b
$ Text -> ByteString -> DecoderError
DecoderErrorLeftover Text
name (ByteString -> ByteString
BSL.toStrict ByteString
leftOver)
{-# INLINE binaryGetDecoder #-}
decodeIPv4 :: Decoder s IPv4
decodeIPv4 :: forall s. Decoder s IPv4
decodeIPv4 =
HostAddress -> IPv4
fromHostAddress
(HostAddress -> IPv4) -> Decoder s HostAddress -> Decoder s IPv4
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version
-> Decoder s HostAddress
-> Decoder s HostAddress
-> Decoder s HostAddress
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(Bool -> Text -> Get HostAddress -> Decoder s HostAddress
forall a s. Bool -> Text -> Get a -> Decoder s a
binaryGetDecoder Bool
False Text
"decodeIPv4" Get HostAddress
getWord32le)
(Bool -> Text -> Get HostAddress -> Decoder s HostAddress
forall a s. Bool -> Text -> Get a -> Decoder s a
binaryGetDecoder Bool
True Text
"decodeIPv4" Get HostAddress
getWord32le)
{-# INLINE decodeIPv4 #-}
getHostAddress6 :: Get HostAddress6
getHostAddress6 :: Get HostAddress6
getHostAddress6 = do
!HostAddress
w1 <- Get HostAddress
getWord32le
!HostAddress
w2 <- Get HostAddress
getWord32le
!HostAddress
w3 <- Get HostAddress
getWord32le
!HostAddress
w4 <- Get HostAddress
getWord32le
HostAddress6 -> Get HostAddress6
forall a. a -> Get a
forall (m :: * -> *) a. Monad m => a -> m a
return (HostAddress
w1, HostAddress
w2, HostAddress
w3, HostAddress
w4)
{-# INLINE getHostAddress6 #-}
decodeIPv6 :: Decoder s IPv6
decodeIPv6 :: forall s. Decoder s IPv6
decodeIPv6 =
HostAddress6 -> IPv6
fromHostAddress6
(HostAddress6 -> IPv6) -> Decoder s HostAddress6 -> Decoder s IPv6
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Version
-> Decoder s HostAddress6
-> Decoder s HostAddress6
-> Decoder s HostAddress6
forall s a. Version -> Decoder s a -> Decoder s a -> Decoder s a
ifDecoderVersionAtLeast
(forall (v :: Natural).
(KnownNat v, MinVersion <= v, v <= MaxVersion) =>
Version
natVersion @9)
(Bool -> Text -> Get HostAddress6 -> Decoder s HostAddress6
forall a s. Bool -> Text -> Get a -> Decoder s a
binaryGetDecoder Bool
False Text
"decodeIPv6" Get HostAddress6
getHostAddress6)
(Bool -> Text -> Get HostAddress6 -> Decoder s HostAddress6
forall a s. Bool -> Text -> Get a -> Decoder s a
binaryGetDecoder Bool
True Text
"decodeIPv6" Get HostAddress6
getHostAddress6)
{-# INLINE decodeIPv6 #-}
decodeTagMaybe :: Decoder s (Maybe Word64)
decodeTagMaybe :: forall s. Decoder s (Maybe Word64)
decodeTagMaybe = Decoder s (Maybe Word64) -> Decoder s (Maybe Word64)
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s (Maybe Word64)
forall s. Decoder s (Maybe Word64)
Plain.decodeTagMaybe
{-# INLINE decodeTagMaybe #-}
allowTag :: Word -> Decoder s ()
allowTag :: forall s. Word -> Decoder s ()
allowTag Word
tagExpected = do
Maybe Word64
mTagReceived <- Decoder s (Maybe Word64)
forall s. Decoder s (Maybe Word64)
decodeTagMaybe
Maybe Word64 -> (Word64 -> Decoder s ()) -> Decoder s ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe Word64
mTagReceived ((Word64 -> Decoder s ()) -> Decoder s ())
-> (Word64 -> Decoder s ()) -> Decoder s ()
forall a b. (a -> b) -> a -> b
$ \Word64
tagReceived ->
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Word64
tagReceived Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== (Word -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word
tagExpected :: Word64)) (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
String -> Decoder s ()
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s ()) -> String -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
String
"Expecteg tag " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Word -> String
forall a. Show a => a -> String
show Word
tagExpected String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" but got tag " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Word64 -> String
forall a. Show a => a -> String
show Word64
tagReceived
{-# INLINE allowTag #-}
assertTag :: Word -> Decoder s ()
assertTag :: forall s. Word -> Decoder s ()
assertTag = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s () -> Decoder s ())
-> (Word -> Decoder s ()) -> Word -> Decoder s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Decoder s ()
forall s. Word -> Decoder s ()
Plain.assertTag
{-# INLINE assertTag #-}
enforceSize :: Text.Text -> Int -> Decoder s ()
enforceSize :: forall s. Text -> Int -> Decoder s ()
enforceSize Text
lbl Int
requestedSize = Decoder s Int
forall s. Decoder s Int
decodeListLen Decoder s Int -> (Int -> Decoder s ()) -> Decoder s ()
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> Int -> Int -> Decoder s ()
forall s. Text -> Int -> Int -> Decoder s ()
matchSize Text
lbl Int
requestedSize
{-# INLINE enforceSize #-}
matchSize :: Text.Text -> Int -> Int -> Decoder s ()
matchSize :: forall s. Text -> Int -> Int -> Decoder s ()
matchSize Text
lbl Int
requestedSize Int
actualSize =
Bool -> Decoder s () -> Decoder s ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
actualSize Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
requestedSize) (Decoder s () -> Decoder s ()) -> Decoder s () -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
DecoderError -> Decoder s ()
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s ()) -> DecoderError -> Decoder s ()
forall a b. (a -> b) -> a -> b
$
Text -> Int -> Int -> DecoderError
DecoderErrorSizeMismatch
Text
lbl
Int
requestedSize
Int
actualSize
{-# INLINE matchSize #-}
decodeBool :: Decoder s Bool
decodeBool :: forall s. Decoder s Bool
decodeBool = Decoder s Bool -> Decoder s Bool
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Bool
forall s. Decoder s Bool
C.decodeBool
{-# INLINE decodeBool #-}
decodeBreakOr :: Decoder s Bool
decodeBreakOr :: forall s. Decoder s Bool
decodeBreakOr = Decoder s Bool -> Decoder s Bool
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Bool
forall s. Decoder s Bool
C.decodeBreakOr
{-# INLINE decodeBreakOr #-}
decodeByteArray :: Decoder s ByteArray
decodeByteArray :: forall s. Decoder s ByteArray
decodeByteArray = Decoder s ByteArray -> Decoder s ByteArray
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteArray
forall s. Decoder s ByteArray
C.decodeByteArray
{-# INLINE decodeByteArray #-}
decodeByteArrayCanonical :: Decoder s ByteArray
decodeByteArrayCanonical :: forall s. Decoder s ByteArray
decodeByteArrayCanonical = Decoder s ByteArray -> Decoder s ByteArray
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteArray
forall s. Decoder s ByteArray
C.decodeByteArrayCanonical
{-# INLINE decodeByteArrayCanonical #-}
decodeBytes :: Decoder s BS.ByteString
decodeBytes :: forall s. Decoder s ByteString
decodeBytes = Decoder s ByteString -> Decoder s ByteString
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteString
forall s. Decoder s ByteString
C.decodeBytes
{-# INLINE decodeBytes #-}
decodeBytesCanonical :: Decoder s BS.ByteString
decodeBytesCanonical :: forall s. Decoder s ByteString
decodeBytesCanonical = Decoder s ByteString -> Decoder s ByteString
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteString
forall s. Decoder s ByteString
C.decodeBytesCanonical
{-# INLINE decodeBytesCanonical #-}
decodeBytesIndef :: Decoder s ()
decodeBytesIndef :: forall s. Decoder s ()
decodeBytesIndef = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ()
forall s. Decoder s ()
C.decodeBytesIndef
{-# INLINE decodeBytesIndef #-}
decodeDouble :: Decoder s Double
decodeDouble :: forall s. Decoder s Double
decodeDouble = Decoder s Double -> Decoder s Double
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Double
forall s. Decoder s Double
C.decodeDouble
{-# INLINE decodeDouble #-}
decodeDoubleCanonical :: Decoder s Double
decodeDoubleCanonical :: forall s. Decoder s Double
decodeDoubleCanonical = Decoder s Double -> Decoder s Double
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Double
forall s. Decoder s Double
C.decodeDoubleCanonical
{-# INLINE decodeDoubleCanonical #-}
decodeFloat :: Decoder s Float
decodeFloat :: forall s. Decoder s Float
decodeFloat = Decoder s Float -> Decoder s Float
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Float
forall s. Decoder s Float
C.decodeFloat
{-# INLINE decodeFloat #-}
decodeFloat16Canonical :: Decoder s Float
decodeFloat16Canonical :: forall s. Decoder s Float
decodeFloat16Canonical = Decoder s Float -> Decoder s Float
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Float
forall s. Decoder s Float
C.decodeFloat16Canonical
{-# INLINE decodeFloat16Canonical #-}
decodeFloatCanonical :: Decoder s Float
decodeFloatCanonical :: forall s. Decoder s Float
decodeFloatCanonical = Decoder s Float -> Decoder s Float
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Float
forall s. Decoder s Float
C.decodeFloatCanonical
{-# INLINE decodeFloatCanonical #-}
decodeInt :: Decoder s Int
decodeInt :: forall s. Decoder s Int
decodeInt = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeInt
{-# INLINE decodeInt #-}
decodeInt16 :: Decoder s Int16
decodeInt16 :: forall s. Decoder s Int16
decodeInt16 = Decoder s Int16 -> Decoder s Int16
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int16
forall s. Decoder s Int16
C.decodeInt16
{-# INLINE decodeInt16 #-}
decodeInt16Canonical :: Decoder s Int16
decodeInt16Canonical :: forall s. Decoder s Int16
decodeInt16Canonical = Decoder s Int16 -> Decoder s Int16
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int16
forall s. Decoder s Int16
C.decodeInt16Canonical
{-# INLINE decodeInt16Canonical #-}
decodeInt32 :: Decoder s Int32
decodeInt32 :: forall s. Decoder s Int32
decodeInt32 = Decoder s Int32 -> Decoder s Int32
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int32
forall s. Decoder s Int32
C.decodeInt32
{-# INLINE decodeInt32 #-}
decodeInt32Canonical :: Decoder s Int32
decodeInt32Canonical :: forall s. Decoder s Int32
decodeInt32Canonical = Decoder s Int32 -> Decoder s Int32
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int32
forall s. Decoder s Int32
C.decodeInt32Canonical
{-# INLINE decodeInt32Canonical #-}
decodeInt64 :: Decoder s Int64
decodeInt64 :: forall s. Decoder s ByteOffset
decodeInt64 = Decoder s ByteOffset -> Decoder s ByteOffset
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteOffset
forall s. Decoder s ByteOffset
C.decodeInt64
{-# INLINE decodeInt64 #-}
decodeInt64Canonical :: Decoder s Int64
decodeInt64Canonical :: forall s. Decoder s ByteOffset
decodeInt64Canonical = Decoder s ByteOffset -> Decoder s ByteOffset
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteOffset
forall s. Decoder s ByteOffset
C.decodeInt64Canonical
{-# INLINE decodeInt64Canonical #-}
decodeInt8 :: Decoder s Int8
decodeInt8 :: forall s. Decoder s Int8
decodeInt8 = Decoder s Int8 -> Decoder s Int8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int8
forall s. Decoder s Int8
C.decodeInt8
{-# INLINE decodeInt8 #-}
decodeInt8Canonical :: Decoder s Int8
decodeInt8Canonical :: forall s. Decoder s Int8
decodeInt8Canonical = Decoder s Int8 -> Decoder s Int8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int8
forall s. Decoder s Int8
C.decodeInt8Canonical
{-# INLINE decodeInt8Canonical #-}
decodeIntCanonical :: Decoder s Int
decodeIntCanonical :: forall s. Decoder s Int
decodeIntCanonical = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeIntCanonical
{-# INLINE decodeIntCanonical #-}
decodeInteger :: Decoder s Integer
decodeInteger :: forall s. Decoder s Integer
decodeInteger = Decoder s Integer -> Decoder s Integer
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Integer
forall s. Decoder s Integer
C.decodeInteger
{-# INLINE decodeInteger #-}
decodeNatural :: Decoder s Natural
decodeNatural :: forall s. Decoder s Natural
decodeNatural = do
!Integer
n <- Decoder s Integer
forall s. Decoder s Integer
decodeInteger
if Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
0
then Natural -> Decoder s Natural
forall a. a -> Decoder s a
forall (m :: * -> *) a. Monad m => a -> m a
return (Natural -> Decoder s Natural) -> Natural -> Decoder s Natural
forall a b. (a -> b) -> a -> b
$! Integer -> Natural
forall a. Num a => Integer -> a
fromInteger Integer
n
else DecoderError -> Decoder s Natural
forall (m :: * -> *) e a. (MonadFail m, Buildable e) => e -> m a
cborError (DecoderError -> Decoder s Natural)
-> DecoderError -> Decoder s Natural
forall a b. (a -> b) -> a -> b
$ Text -> Text -> DecoderError
DecoderErrorCustom Text
"Natural" Text
"got a negative number"
{-# INLINE decodeNatural #-}
decodeIntegerCanonical :: Decoder s Integer
decodeIntegerCanonical :: forall s. Decoder s Integer
decodeIntegerCanonical = Decoder s Integer -> Decoder s Integer
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Integer
forall s. Decoder s Integer
C.decodeIntegerCanonical
{-# INLINE decodeIntegerCanonical #-}
decodeListLen :: Decoder s Int
decodeListLen :: forall s. Decoder s Int
decodeListLen = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeListLen
{-# INLINE decodeListLen #-}
decodeListLenCanonical :: Decoder s Int
decodeListLenCanonical :: forall s. Decoder s Int
decodeListLenCanonical = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeListLenCanonical
{-# INLINE decodeListLenCanonical #-}
decodeListLenCanonicalOf :: Int -> Decoder s ()
decodeListLenCanonicalOf :: forall s. Int -> Decoder s ()
decodeListLenCanonicalOf = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s () -> Decoder s ())
-> (Int -> Decoder s ()) -> Int -> Decoder s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Decoder s ()
forall s. Int -> Decoder s ()
C.decodeListLenCanonicalOf
{-# INLINE decodeListLenCanonicalOf #-}
decodeListLenIndef :: Decoder s ()
decodeListLenIndef :: forall s. Decoder s ()
decodeListLenIndef = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ()
forall s. Decoder s ()
C.decodeListLenIndef
{-# INLINE decodeListLenIndef #-}
decodeListLenOf :: Int -> Decoder s ()
decodeListLenOf :: forall s. Int -> Decoder s ()
decodeListLenOf = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s () -> Decoder s ())
-> (Int -> Decoder s ()) -> Int -> Decoder s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Decoder s ()
forall s. Int -> Decoder s ()
C.decodeListLenOf
{-# INLINE decodeListLenOf #-}
decodeListLenOrIndef :: Decoder s (Maybe Int)
decodeListLenOrIndef :: forall s. Decoder s (Maybe Int)
decodeListLenOrIndef = Decoder s (Maybe Int) -> Decoder s (Maybe Int)
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
C.decodeListLenOrIndef
{-# INLINE decodeListLenOrIndef #-}
decodeMapLen :: Decoder s Int
decodeMapLen :: forall s. Decoder s Int
decodeMapLen = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeMapLen
{-# INLINE decodeMapLen #-}
decodeMapLenCanonical :: Decoder s Int
decodeMapLenCanonical :: forall s. Decoder s Int
decodeMapLenCanonical = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.decodeMapLenCanonical
{-# INLINE decodeMapLenCanonical #-}
decodeMapLenIndef :: Decoder s ()
decodeMapLenIndef :: forall s. Decoder s ()
decodeMapLenIndef = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ()
forall s. Decoder s ()
C.decodeMapLenIndef
{-# INLINE decodeMapLenIndef #-}
decodeMapLenOrIndef :: Decoder s (Maybe Int)
decodeMapLenOrIndef :: forall s. Decoder s (Maybe Int)
decodeMapLenOrIndef = Decoder s (Maybe Int) -> Decoder s (Maybe Int)
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s (Maybe Int)
forall s. Decoder s (Maybe Int)
C.decodeMapLenOrIndef
{-# INLINE decodeMapLenOrIndef #-}
decodeNegWord :: Decoder s Word
decodeNegWord :: forall s. Decoder s Word
decodeNegWord = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeNegWord
{-# INLINE decodeNegWord #-}
decodeNegWord64 :: Decoder s Word64
decodeNegWord64 :: forall s. Decoder s Word64
decodeNegWord64 = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeNegWord64
{-# INLINE decodeNegWord64 #-}
decodeNegWord64Canonical :: Decoder s Word64
decodeNegWord64Canonical :: forall s. Decoder s Word64
decodeNegWord64Canonical = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeNegWord64Canonical
{-# INLINE decodeNegWord64Canonical #-}
decodeNegWordCanonical :: Decoder s Word
decodeNegWordCanonical :: forall s. Decoder s Word
decodeNegWordCanonical = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeNegWordCanonical
{-# INLINE decodeNegWordCanonical #-}
decodeNull :: Decoder s ()
decodeNull :: forall s. Decoder s ()
decodeNull = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ()
forall s. Decoder s ()
C.decodeNull
{-# INLINE decodeNull #-}
decodeSequenceLenIndef :: (r -> a -> r) -> r -> (r -> b) -> Decoder s a -> Decoder s b
decodeSequenceLenIndef :: forall r a b s.
(r -> a -> r) -> r -> (r -> b) -> Decoder s a -> Decoder s b
decodeSequenceLenIndef r -> a -> r
a r
b r -> b
c Decoder s a
dec = Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
forall s a b.
Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
withPlainDecoder Decoder s a
dec ((Decoder s a -> Decoder s b) -> Decoder s b)
-> (Decoder s a -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ (r -> a -> r) -> r -> (r -> b) -> Decoder s a -> Decoder s b
forall r a r' s.
(r -> a -> r) -> r -> (r -> r') -> Decoder s a -> Decoder s r'
C.decodeSequenceLenIndef r -> a -> r
a r
b r -> b
c
{-# INLINE decodeSequenceLenIndef #-}
decodeSequenceLenN :: (r -> a -> r) -> r -> (r -> b) -> Int -> Decoder s a -> Decoder s b
decodeSequenceLenN :: forall r a b s.
(r -> a -> r) -> r -> (r -> b) -> Int -> Decoder s a -> Decoder s b
decodeSequenceLenN r -> a -> r
a r
b r -> b
c Int
n Decoder s a
dec = Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
forall s a b.
Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
withPlainDecoder Decoder s a
dec ((Decoder s a -> Decoder s b) -> Decoder s b)
-> (Decoder s a -> Decoder s b) -> Decoder s b
forall a b. (a -> b) -> a -> b
$ (r -> a -> r) -> r -> (r -> b) -> Int -> Decoder s a -> Decoder s b
forall r a r' s.
(r -> a -> r)
-> r -> (r -> r') -> Int -> Decoder s a -> Decoder s r'
C.decodeSequenceLenN r -> a -> r
a r
b r -> b
c Int
n
{-# INLINE decodeSequenceLenN #-}
decodeSimple :: Decoder s Word8
decodeSimple :: forall s. Decoder s Word8
decodeSimple = Decoder s Word8 -> Decoder s Word8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word8
forall s. Decoder s Word8
C.decodeSimple
{-# INLINE decodeSimple #-}
decodeSimpleCanonical :: Decoder s Word8
decodeSimpleCanonical :: forall s. Decoder s Word8
decodeSimpleCanonical = Decoder s Word8 -> Decoder s Word8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word8
forall s. Decoder s Word8
C.decodeSimpleCanonical
{-# INLINE decodeSimpleCanonical #-}
decodeString :: Decoder s Text.Text
decodeString :: forall s. Decoder s Text
decodeString = Decoder s Text -> Decoder s Text
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Text
forall s. Decoder s Text
C.decodeString
{-# INLINE decodeString #-}
decodeStringCanonical :: Decoder s Text.Text
decodeStringCanonical :: forall s. Decoder s Text
decodeStringCanonical = Decoder s Text -> Decoder s Text
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Text
forall s. Decoder s Text
C.decodeStringCanonical
{-# INLINE decodeStringCanonical #-}
decodeStringIndef :: Decoder s ()
decodeStringIndef :: forall s. Decoder s ()
decodeStringIndef = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ()
forall s. Decoder s ()
C.decodeStringIndef
{-# INLINE decodeStringIndef #-}
decodeTag :: Decoder s Word
decodeTag :: forall s. Decoder s Word
decodeTag = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeTag
{-# INLINE decodeTag #-}
decodeTag64 :: Decoder s Word64
decodeTag64 :: forall s. Decoder s Word64
decodeTag64 = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeTag64
{-# INLINE decodeTag64 #-}
decodeTag64Canonical :: Decoder s Word64
decodeTag64Canonical :: forall s. Decoder s Word64
decodeTag64Canonical = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeTag64Canonical
{-# INLINE decodeTag64Canonical #-}
decodeTagCanonical :: Decoder s Word
decodeTagCanonical :: forall s. Decoder s Word
decodeTagCanonical = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeTagCanonical
{-# INLINE decodeTagCanonical #-}
decodeUtf8ByteArray :: Decoder s ByteArray
decodeUtf8ByteArray :: forall s. Decoder s ByteArray
decodeUtf8ByteArray = Decoder s ByteArray -> Decoder s ByteArray
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteArray
forall s. Decoder s ByteArray
C.decodeUtf8ByteArray
{-# INLINE decodeUtf8ByteArray #-}
decodeUtf8ByteArrayCanonical :: Decoder s ByteArray
decodeUtf8ByteArrayCanonical :: forall s. Decoder s ByteArray
decodeUtf8ByteArrayCanonical = Decoder s ByteArray -> Decoder s ByteArray
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteArray
forall s. Decoder s ByteArray
C.decodeUtf8ByteArrayCanonical
{-# INLINE decodeUtf8ByteArrayCanonical #-}
decodeWithByteSpan :: Decoder s a -> Decoder s (a, C.ByteOffset, C.ByteOffset)
decodeWithByteSpan :: forall s a. Decoder s a -> Decoder s (a, ByteOffset, ByteOffset)
decodeWithByteSpan Decoder s a
d = Decoder s a
-> (Decoder s a -> Decoder s (a, ByteOffset, ByteOffset))
-> Decoder s (a, ByteOffset, ByteOffset)
forall s a b.
Decoder s a -> (Decoder s a -> Decoder s b) -> Decoder s b
withPlainDecoder Decoder s a
d Decoder s a -> Decoder s (a, ByteOffset, ByteOffset)
forall s a. Decoder s a -> Decoder s (a, ByteOffset, ByteOffset)
C.decodeWithByteSpan
{-# INLINE decodeWithByteSpan #-}
decodeWord :: Decoder s Word
decodeWord :: forall s. Decoder s Word
decodeWord = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeWord
{-# INLINE decodeWord #-}
decodeWord16 :: Decoder s Word16
decodeWord16 :: forall s. Decoder s Word16
decodeWord16 = Decoder s Word16 -> Decoder s Word16
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word16
forall s. Decoder s Word16
C.decodeWord16
{-# INLINE decodeWord16 #-}
decodeWord16Canonical :: Decoder s Word16
decodeWord16Canonical :: forall s. Decoder s Word16
decodeWord16Canonical = Decoder s Word16 -> Decoder s Word16
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word16
forall s. Decoder s Word16
C.decodeWord16Canonical
{-# INLINE decodeWord16Canonical #-}
decodeWord32 :: Decoder s Word32
decodeWord32 :: forall s. Decoder s HostAddress
decodeWord32 = Decoder s HostAddress -> Decoder s HostAddress
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s HostAddress
forall s. Decoder s HostAddress
C.decodeWord32
{-# INLINE decodeWord32 #-}
decodeWord32Canonical :: Decoder s Word32
decodeWord32Canonical :: forall s. Decoder s HostAddress
decodeWord32Canonical = Decoder s HostAddress -> Decoder s HostAddress
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s HostAddress
forall s. Decoder s HostAddress
C.decodeWord32Canonical
{-# INLINE decodeWord32Canonical #-}
decodeWord64 :: Decoder s Word64
decodeWord64 :: forall s. Decoder s Word64
decodeWord64 = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeWord64
{-# INLINE decodeWord64 #-}
decodeWord64Canonical :: Decoder s Word64
decodeWord64Canonical :: forall s. Decoder s Word64
decodeWord64Canonical = Decoder s Word64 -> Decoder s Word64
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word64
forall s. Decoder s Word64
C.decodeWord64Canonical
{-# INLINE decodeWord64Canonical #-}
decodeWord8 :: Decoder s Word8
decodeWord8 :: forall s. Decoder s Word8
decodeWord8 = Decoder s Word8 -> Decoder s Word8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word8
forall s. Decoder s Word8
C.decodeWord8
{-# INLINE decodeWord8 #-}
decodeWord8Canonical :: Decoder s Word8
decodeWord8Canonical :: forall s. Decoder s Word8
decodeWord8Canonical = Decoder s Word8 -> Decoder s Word8
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word8
forall s. Decoder s Word8
C.decodeWord8Canonical
{-# INLINE decodeWord8Canonical #-}
decodeWordCanonical :: Decoder s Word
decodeWordCanonical :: forall s. Decoder s Word
decodeWordCanonical = Decoder s Word -> Decoder s Word
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Word
forall s. Decoder s Word
C.decodeWordCanonical
{-# INLINE decodeWordCanonical #-}
decodeWordCanonicalOf :: Word -> Decoder s ()
decodeWordCanonicalOf :: forall s. Word -> Decoder s ()
decodeWordCanonicalOf = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s () -> Decoder s ())
-> (Word -> Decoder s ()) -> Word -> Decoder s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Decoder s ()
forall s. Word -> Decoder s ()
C.decodeWordCanonicalOf
{-# INLINE decodeWordCanonicalOf #-}
decodeWordOf :: Word -> Decoder s ()
decodeWordOf :: forall s. Word -> Decoder s ()
decodeWordOf = Decoder s () -> Decoder s ()
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder (Decoder s () -> Decoder s ())
-> (Word -> Decoder s ()) -> Word -> Decoder s ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Decoder s ()
forall s. Word -> Decoder s ()
C.decodeWordOf
{-# INLINE decodeWordOf #-}
decodeTerm :: Decoder s C.Term
decodeTerm :: forall s. Decoder s Term
decodeTerm = Decoder s Term -> Decoder s Term
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Term
forall s. Decoder s Term
C.decodeTerm
{-# INLINE decodeTerm #-}
peekAvailable :: Decoder s Int
peekAvailable :: forall s. Decoder s Int
peekAvailable = Decoder s Int -> Decoder s Int
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s Int
forall s. Decoder s Int
C.peekAvailable
{-# INLINE peekAvailable #-}
peekByteOffset :: Decoder s C.ByteOffset
peekByteOffset :: forall s. Decoder s ByteOffset
peekByteOffset = Decoder s ByteOffset -> Decoder s ByteOffset
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s ByteOffset
forall s. Decoder s ByteOffset
C.peekByteOffset
{-# INLINE peekByteOffset #-}
peekTokenType :: Decoder s C.TokenType
peekTokenType :: forall s. Decoder s TokenType
peekTokenType = Decoder s TokenType -> Decoder s TokenType
forall s a. Decoder s a -> Decoder s a
fromPlainDecoder Decoder s TokenType
forall s. Decoder s TokenType
C.peekTokenType
{-# INLINE peekTokenType #-}