typed-encoding-0.3.0.0: Type safe string transformations

Safe HaskellSafe
LanguageHaskell2010

Data.TypedEncoding.Common.Types.Exceptions

Contents

Description

Internal definition of types

Synopsis

Documentation

>>> :set -XOverloadedStrings -XMultiParamTypeClasses -XDataKinds -XAllowAmbiguousTypes
>>> import qualified Data.Text as T

data RecreateEx where Source #

Represents errors in recovery (recreation of encoded types).

Constructors

RecreateEx :: (Show e, KnownSymbol x) => Proxy x -> e -> RecreateEx 
RecreateExUnkStep :: Show e => e -> RecreateEx 
Instances
Show RecreateEx Source # 
Instance details

Defined in Data.TypedEncoding.Common.Types.Exceptions

IsStringR str => Validate (Either RecreateEx) "r-Int-decimal" "r-Int-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

validation :: Validation (Either RecreateEx) "r-Int-decimal" "r-Int-decimal" c str Source #

IsStringR str => Validate (Either RecreateEx) "r-Word8-decimal" "r-Word8-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

validation :: Validation (Either RecreateEx) "r-Word8-decimal" "r-Word8-decimal" c str Source #

RecreateErr (Either RecreateEx) Source # 
Instance details

Defined in Data.TypedEncoding.Common.Class.Validate

data EncodeEx where Source #

Represents errors in encoding

Constructors

EncodeEx :: (Show a, KnownSymbol x) => Proxy x -> a -> EncodeEx 
Instances
Show EncodeEx Source # 
Instance details

Defined in Data.TypedEncoding.Common.Types.Exceptions

(Ban s, Algorithm s "r-ban", IsStringR str) => Encode (Either EncodeEx) s "r-ban" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.BoundedAlphaNums

Methods

encoding :: Encoding (Either EncodeEx) s "r-ban" c str Source #

Char8Find str => Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ASCII

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c str Source #

Encode (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.ASCII

Methods

encoding :: Encoding (Either EncodeEx) "r-ASCII" "r-ASCII" c Char Source #

IsStringR str => Encode (Either EncodeEx) "r-Int-decimal" "r-Int-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

encoding :: Encoding (Either EncodeEx) "r-Int-decimal" "r-Int-decimal" c str Source #

Encode (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.UTF8

Methods

encoding :: Encoding (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

Encode (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

UTF8 encodings are defined for ByteString only as that would not make much sense for Text

>>> encodeFAll . toEncoding () $ "\xc3\xb1" :: Either EncodeEx (Enc '["r-UTF8"] () B.ByteString)
Right (UnsafeMkEnc Proxy () "\195\177")
>>> encodeFAll . toEncoding () $ "\xc3\x28" :: Either EncodeEx (Enc '["r-UTF8"] () B.ByteString)
Left (EncodeEx "r-UTF8" (Cannot decode byte '\xc3': Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream))

Following test uses verEncoding helper that checks that bytes are encoded as Right iff they are valid UTF8 bytes

\(b :: B.ByteString) -> verEncoding b (fmap (fromEncoding . decodeAll . proxiedId (Proxy :: Proxy (Enc '["r-UTF8"] _ _))) . (encodeFAll :: _ -> Either EncodeEx _). toEncoding () $ b)
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.UTF8

Methods

encoding :: Encoding (Either EncodeEx) "r-UTF8" "r-UTF8" c ByteString Source #

IsStringR str => Encode (Either EncodeEx) "r-Word8-decimal" "r-Word8-decimal" c str Source # 
Instance details

Defined in Data.TypedEncoding.Instances.Restriction.Misc

Methods

encoding :: Encoding (Either EncodeEx) "r-Word8-decimal" "r-Word8-decimal" c str Source #

encToRecrEx :: EncodeEx -> RecreateEx Source #

Useful when manually recreating using recovery

data UnexpectedDecodeEx where Source #

Type safety over encodings makes decoding process safe. However failures are still possible due to bugs or unsafe payload modifications. UnexpectedDecodeEx represents such errors.

Constructors

UnexpectedDecodeEx :: (Show a, KnownSymbol x) => Proxy x -> a -> UnexpectedDecodeEx 

Base combinators that rely on types defined here

mergeErrs :: err -> (err -> Maybe err -> err) -> Either err a -> Either err b -> Either err c Source #