cardano-binary-1.5.0.0.0.0.0.2: Binary serialization for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Binary

Synopsis

Documentation

class Typeable a => ToCBOR a where Source #

Minimal complete definition

toCBOR

Methods

toCBOR :: a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy a -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size Source #

Instances

Instances details
ToCBOR Nano Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Nano -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Nano -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Nano] -> Size Source #

ToCBOR Pico Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Pico -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Pico -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Pico] -> Size Source #

ToCBOR Void Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Void -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Void -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Void] -> Size Source #

ToCBOR Int32 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Int32 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Int32 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Int32] -> Size Source #

ToCBOR Int64 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Int64 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Int64 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Int64] -> Size Source #

ToCBOR Word16 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Word16 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word16 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Word16] -> Size Source #

ToCBOR Word32 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Word32 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word32 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Word32] -> Size Source #

ToCBOR Word64 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Word64 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word64 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Word64] -> Size Source #

ToCBOR Word8 Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Word8 -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word8 -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Word8] -> Size Source #

ToCBOR ByteString Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

ToCBOR ByteString Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

ToCBOR ShortByteString Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

ToCBOR Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

Methods

toCBOR :: Raw -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Raw -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Raw] -> Size Source #

ToCBOR Text Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Text -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Text -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Text] -> Size Source #

ToCBOR NominalDiffTime Source #

For backwards compatibility we round pico precision to micro

Instance details

Defined in Cardano.Binary.ToCBOR

ToCBOR UTCTime Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: UTCTime -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy UTCTime -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [UTCTime] -> Size Source #

ToCBOR Integer Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Integer -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Integer -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Integer] -> Size Source #

ToCBOR Natural Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Natural -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Natural -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Natural] -> Size Source #

ToCBOR () Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: () -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy () -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [()] -> Size Source #

ToCBOR Bool Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Bool -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Bool -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Bool] -> Size Source #

ToCBOR Float Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Float -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Float -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Float] -> Size Source #

ToCBOR Int Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Int -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Int -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Int] -> Size Source #

ToCBOR Word Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Word -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Word -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Word] -> Size Source #

ToCBOR a => ToCBOR (Ratio a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Ratio a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Ratio a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Ratio a] -> Size Source #

Typeable xs => ToCBOR (LengthOf xs) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: LengthOf xs -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (LengthOf xs) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [LengthOf xs] -> Size Source #

(Ord a, ToCBOR a) => ToCBOR (Set a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Set a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Set a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Set a] -> Size Source #

ToCBOR a => ToCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Vector a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Vector a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Vector a] -> Size Source #

ToCBOR a => ToCBOR (NonEmpty a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: NonEmpty a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (NonEmpty a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [NonEmpty a] -> Size Source #

ToCBOR a => ToCBOR (Maybe a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Maybe a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Maybe a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Maybe a] -> Size Source #

ToCBOR a => ToCBOR [a] Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: [a] -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [a] -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [[a]] -> Size Source #

(ToCBOR a, ToCBOR b) => ToCBOR (Either a b) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Either a b -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Either a b) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Either a b] -> Size Source #

(Ord k, ToCBOR k, ToCBOR v) => ToCBOR (Map k v) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Map k v -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Map k v) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Map k v] -> Size Source #

(ToCBOR a, ToCBOR b) => ToCBOR (a, b) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: (a, b) -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (a, b) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [(a, b)] -> Size Source #

(Typeable s, ToCBOR a) => ToCBOR (Tagged s a) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: Tagged s a -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (Tagged s a) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Tagged s a] -> Size Source #

(ToCBOR a, ToCBOR b, ToCBOR c) => ToCBOR (a, b, c) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: (a, b, c) -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (a, b, c) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [(a, b, c)] -> Size Source #

(ToCBOR a, ToCBOR b, ToCBOR c, ToCBOR d) => ToCBOR (a, b, c, d) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: (a, b, c, d) -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (a, b, c, d) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [(a, b, c, d)] -> Size Source #

(ToCBOR a, ToCBOR b, ToCBOR c, ToCBOR d, ToCBOR e) => ToCBOR (a, b, c, d, e) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: (a, b, c, d, e) -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (a, b, c, d, e) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [(a, b, c, d, e)] -> Size Source #

(ToCBOR a, ToCBOR b, ToCBOR c, ToCBOR d, ToCBOR e, ToCBOR f, ToCBOR g) => ToCBOR (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: (a, b, c, d, e, f, g) -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (a, b, c, d, e, f, g) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [(a, b, c, d, e, f, g)] -> Size Source #

withWordSize :: (Integral s, Integral a) => s -> a Source #

Compute encoded size of an integer

Size of expressions

data Range b Source #

A range of values. Should satisfy the invariant forall x. lo x <= hi x.

Constructors

Range 

Fields

Instances

Instances details
(Ord b, Num b) => Num (Range b) Source #

The Num instance for Range uses interval arithmetic. Note that the signum method is not lawful: if the interval x includes 0 in its interior but is not symmetric about 0, then abs x * signum x /= x.

Instance details

Defined in Cardano.Binary.ToCBOR

Methods

(+) :: Range b -> Range b -> Range b Source #

(-) :: Range b -> Range b -> Range b Source #

(*) :: Range b -> Range b -> Range b Source #

negate :: Range b -> Range b Source #

abs :: Range b -> Range b Source #

signum :: Range b -> Range b Source #

fromInteger :: Integer -> Range b Source #

Buildable (Range Natural) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

szEval :: (forall t. ToCBOR t => (Proxy t -> Size) -> Proxy t -> Range Natural) -> Size -> Range Natural Source #

Fully evaluate a size expression by applying the given function to any suspended computations. szEval g effectively turns each "thunk" of the form TodoF f x into g x, then evaluates the result.

type Size = Fix SizeF Source #

Expressions describing the statically-computed size bounds on a type's possible values.

data Case t Source #

An individual labeled case.

Constructors

Case Text t 

Instances

Instances details
Functor Case Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

fmap :: (a -> b) -> Case a -> Case b Source #

(<$) :: a -> Case b -> Case a Source #

Buildable t => Buildable (Case t) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

build :: Case t -> Builder Source #

caseValue :: Case t -> t Source #

Discard the label on a case.

newtype LengthOf xs Source #

A type used to represent the length of a value in Size computations.

Constructors

LengthOf xs 

Instances

Instances details
Typeable xs => ToCBOR (LengthOf xs) Source # 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBOR :: LengthOf xs -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy (LengthOf xs) -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [LengthOf xs] -> Size Source #

data SizeOverride Source #

Override mechanisms to be used with szWithCtx.

Constructors

SizeConstant Size

Replace with a fixed Size.

SizeExpression ((forall a. ToCBOR a => Proxy a -> Size) -> Size)

Recursively compute the size.

SelectCases [Text]

Select only a specific case from a CasesF.

isTodo :: Size -> Bool Source #

Is this expression a thunk?

szCases :: [Case Size] -> Size Source #

Create a case expression from individual cases.

szLazy :: ToCBOR a => Proxy a -> Size Source #

Evaluate the expression lazily, by immediately creating a thunk that will evaluate its contents lazily.

ghci> putStrLn $ pretty $ szLazy (Proxy @TxAux)
(_ :: TxAux)

szGreedy :: ToCBOR a => Proxy a -> Size Source #

Evaluate an expression greedily. There may still be thunks in the result, for types that did not provide a custom encodedSizeExpr method in their ToCBOR instance.

ghci> putStrLn $ pretty $ szGreedy (Proxy @TxAux)
(0 + { TxAux=(2 + ((0 + (((1 + (2 + ((_ :: LengthOf [TxIn]) * (2 + { TxInUtxo=(2 + ((1 + 34) + { minBound=1 maxBound=5 })) })))) + (2 + ((_ :: LengthOf [TxOut]) * (0 + { TxOut=(2 + ((0 + ((2 + ((2 + withWordSize((((1 + 30) + (_ :: Attributes AddrAttributes)) + 1))) + (((1 + 30) + (_ :: Attributes AddrAttributes)) + 1))) + { minBound=1 maxBound=5 })) + { minBound=1 maxBound=9 })) })))) + (_ :: Attributes ()))) + (_ :: Vector TxInWitness))) })

szForce :: Size -> Size Source #

Force any thunks in the given Size expression.

ghci> putStrLn $ pretty $ szForce $ szLazy (Proxy @TxAux)
(0 + { TxAux=(2 + ((0 + (_ :: Tx)) + (_ :: Vector TxInWitness))) })

szWithCtx :: ToCBOR a => Map TypeRep SizeOverride -> Proxy a -> Size Source #

Greedily compute the size bounds for a type, using the given context to override sizes for specific types.

szSimplify :: Size -> Either Size (Range Natural) Source #

Simplify the given Size, resulting in either the simplified Size or, if it was fully simplified, an explicit upper and lower bound.

apMono :: Text -> (Natural -> Natural) -> Size -> Size Source #

Apply a monotonically increasing function to the expression. There are three cases when applying f to a Size expression: * When applied to a value x, compute f x. * When applied to cases, apply to each case individually. * In all other cases, create a deferred application of f.

serialize :: ToCBOR a => a -> ByteString Source #

Serialize a Haskell value with a ToCBOR instance to an external binary representation.

The output is represented as a lazy LByteString and is constructed incrementally.

serialize' :: ToCBOR a => a -> ByteString Source #

Serialize a Haskell value to an external binary representation.

The output is represented as a strict ByteString.

serializeBuilder :: ToCBOR a => a -> Builder Source #

Serialize into a Builder. Useful if you want to throw other ByteStrings around it.

serializeEncoding :: Encoding -> ByteString Source #

Serialize a Haskell value to an external binary representation using the provided CBOR Encoding

The output is represented as an LByteString and is constructed incrementally.

CBOR in CBOR

encodeNestedCbor :: ToCBOR a => a -> Encoding Source #

Encode and serialise the given a and sorround it with the semantic tag 24 In CBOR diagnostic notation: >>> 24(hDEADBEEF)

encodeNestedCborBytes :: ByteString -> Encoding Source #

Like encodeNestedCbor, but assumes nothing about the shape of input object, so that it must be passed as a binary ByteString blob. It's the caller responsibility to ensure the input ByteString correspond indeed to valid, previously-serialised CBOR data.

newtype Raw Source #

A wrapper over ByteString for signalling that a bytestring should be processed as a sequence of bytes, not as a separate entity. It's used in crypto and binary code.

Constructors

Raw ByteString 

Instances

Instances details
Show Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

FromCBOR Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

ToCBOR Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

Methods

toCBOR :: Raw -> Encoding Source #

encodedSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy Raw -> Size Source #

encodedListSizeExpr :: (forall t. ToCBOR t => Proxy t -> Size) -> Proxy [Raw] -> Size Source #

NFData Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

Methods

rnf :: Raw -> () Source #

Eq Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

Methods

(==) :: Raw -> Raw -> Bool Source #

(/=) :: Raw -> Raw -> Bool Source #

Ord Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

Methods

compare :: Raw -> Raw -> Ordering Source #

(<) :: Raw -> Raw -> Bool Source #

(<=) :: Raw -> Raw -> Bool Source #

(>) :: Raw -> Raw -> Bool Source #

(>=) :: Raw -> Raw -> Bool Source #

max :: Raw -> Raw -> Raw Source #

min :: Raw -> Raw -> Raw Source #

class Typeable a => FromCBOR a where Source #

Minimal complete definition

fromCBOR

Methods

fromCBOR :: Decoder s a Source #

label :: Proxy a -> Text Source #

Instances

Instances details
FromCBOR Nano Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Pico Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Void Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Int32 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Int64 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Word16 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Word32 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Word64 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Word8 Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR ByteString Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR ByteString Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR ShortByteString Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Raw Source # 
Instance details

Defined in Cardano.Binary.Raw

FromCBOR Text Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR NominalDiffTime Source #

For backwards compatibility we round pico precision to micro

Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR UTCTime Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Integer Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Natural Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR () Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s () Source #

label :: Proxy () -> Text Source #

FromCBOR Bool Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Float Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Int Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR Word Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

(Integral a, FromCBOR a) => FromCBOR (Ratio a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

(Ord a, FromCBOR a) => FromCBOR (Set a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (Set a) Source #

label :: Proxy (Set a) -> Text Source #

FromCBOR a => FromCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR a => FromCBOR (NonEmpty a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR a => FromCBOR (Maybe a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

FromCBOR a => FromCBOR [a] Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s [a] Source #

label :: Proxy [a] -> Text Source #

(FromCBOR a, FromCBOR b) => FromCBOR (Either a b) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (Either a b) Source #

label :: Proxy (Either a b) -> Text Source #

(Ord k, FromCBOR k, FromCBOR v) => FromCBOR (Map k v) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (Map k v) Source #

label :: Proxy (Map k v) -> Text Source #

(FromCBOR a, FromCBOR b) => FromCBOR (a, b) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (a, b) Source #

label :: Proxy (a, b) -> Text Source #

(Typeable s, FromCBOR a) => FromCBOR (Tagged s a) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s0 (Tagged s a) Source #

label :: Proxy (Tagged s a) -> Text Source #

(FromCBOR a, FromCBOR b, FromCBOR c) => FromCBOR (a, b, c) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (a, b, c) Source #

label :: Proxy (a, b, c) -> Text Source #

(FromCBOR a, FromCBOR b, FromCBOR c, FromCBOR d) => FromCBOR (a, b, c, d) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (a, b, c, d) Source #

label :: Proxy (a, b, c, d) -> Text Source #

(FromCBOR a, FromCBOR b, FromCBOR c, FromCBOR d, FromCBOR e) => FromCBOR (a, b, c, d, e) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (a, b, c, d, e) Source #

label :: Proxy (a, b, c, d, e) -> Text Source #

(FromCBOR a, FromCBOR b, FromCBOR c, FromCBOR d, FromCBOR e, FromCBOR f, FromCBOR g) => FromCBOR (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBOR :: Decoder s (a, b, c, d, e, f, g) Source #

label :: Proxy (a, b, c, d, e, f, g) -> Text Source #

enforceSize :: Text -> Int -> Decoder s () Source #

Enforces that the input size is the same as the decoded one, failing in case it's not

matchSize :: Text -> Int -> Int -> Decoder s () Source #

Compare two sizes, failing if they are not equal

decodeListWith :: Decoder s a -> Decoder s [a] Source #

Decoder for list.

Helper tools to build instances

decodeMapSkel :: (Ord k, FromCBOR k, FromCBOR v) => ([(k, v)] -> m) -> Decoder s m Source #

Checks canonicity by comparing the new key being decoded with the previous one, to enfore these are sorted the correct way. See: https://tools.ietf.org/html/rfc7049#section-3.9 "[..]The keys in every map must be sorted lowest value to highest.[...]"

cborError :: Buildable e => e -> Decoder s a Source #

Convert a Buildable error into a cborg decoder error

toCborError :: Buildable e => Either e a -> Decoder s a Source #

Convert an Either-encoded failure to a cborg decoder failure

type Dropper s = Decoder s () Source #

dropList :: Dropper s -> Dropper s Source #

Drop a list of values using the supplied Dropper for each element

Unsafe deserialization

unsafeDeserialize :: FromCBOR a => ByteString -> a Source #

Deserialize a Haskell value from the external binary representation (which must have been made using serialize or related function).

Throws: DeserialiseFailure if the given external representation is invalid or does not correspond to a value of the expected type.

unsafeDeserialize' :: FromCBOR a => ByteString -> a Source #

Strict variant of deserialize.

toStrictByteString Source #

Arguments

:: Encoding

The Encoding of a CBOR value.

-> ByteString

The encoded value.

Turn an Encoding into a strict ByteString in CBOR binary format.

Since: cborg-0.2.0.0

Backward-compatible functions

decodeFull :: forall a. FromCBOR a => ByteString -> Either DecoderError a Source #

Deserialize a Haskell value from the external binary representation, failing if there are leftovers. In a nutshell, the full here implies the contract of this function is that what you feed as input needs to be consumed entirely.

decodeFullDecoder Source #

Arguments

:: Text

Label for error reporting

-> (forall s. Decoder s a)

The parser for the ByteString to decode. It should decode the given ByteString into a value of type a

-> ByteString

The ByteString to decode

-> Either DecoderError a 

CBOR in CBOR

decodeNestedCbor :: FromCBOR a => Decoder s a Source #

Remove the the semantic tag 24 from the enclosed CBOR data item, decoding back the inner ByteString as a proper Haskell type. Consume its input in full.

decodeNestedCborBytes :: Decoder s ByteString Source #

Like decodeKnownCborDataItem, but assumes nothing about the Haskell type we want to deserialise back, therefore it yields the ByteString Tag 24 surrounded (stripping such tag away).

In CBOR notation, if the data was serialised as:

>>> 24(h'DEADBEEF')

then decodeNestedCborBytes yields the inner DEADBEEF, unchanged.

data Annotated b a Source #

Constructors

Annotated 

Fields

Instances

Instances details
Bifunctor Annotated Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

bimap :: (a -> b) -> (c -> d) -> Annotated a c -> Annotated b d Source #

first :: (a -> b) -> Annotated a c -> Annotated b c Source #

second :: (b -> c) -> Annotated a b -> Annotated a c Source #

Functor (Annotated b) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

fmap :: (a -> b0) -> Annotated b a -> Annotated b b0 Source #

(<$) :: a -> Annotated b b0 -> Annotated b a Source #

FromJSON b => FromJSON (Annotated b ()) Source # 
Instance details

Defined in Cardano.Binary.Annotated

ToJSON b => ToJSON (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Generic (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Associated Types

type Rep (Annotated b a) :: Type -> Type Source #

Methods

from :: Annotated b a -> Rep (Annotated b a) x Source #

to :: Rep (Annotated b a) x -> Annotated b a Source #

(Show b, Show a) => Show (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Decoded (Annotated b ByteString) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Associated Types

type BaseType (Annotated b ByteString) Source #

(NFData b, NFData a) => NFData (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

rnf :: Annotated b a -> () Source #

(Eq b, Eq a) => Eq (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

(==) :: Annotated b a -> Annotated b a -> Bool Source #

(/=) :: Annotated b a -> Annotated b a -> Bool Source #

(Eq a, Ord b) => Ord (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

compare :: Annotated b a -> Annotated b a -> Ordering Source #

(<) :: Annotated b a -> Annotated b a -> Bool Source #

(<=) :: Annotated b a -> Annotated b a -> Bool Source #

(>) :: Annotated b a -> Annotated b a -> Bool Source #

(>=) :: Annotated b a -> Annotated b a -> Bool Source #

max :: Annotated b a -> Annotated b a -> Annotated b a Source #

min :: Annotated b a -> Annotated b a -> Annotated b a Source #

(NoThunks b, NoThunks a) => NoThunks (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

type Rep (Annotated b a) Source # 
Instance details

Defined in Cardano.Binary.Annotated

type Rep (Annotated b a) = D1 ('MetaData "Annotated" "Cardano.Binary.Annotated" "cardano-binary-1.5.0.0.0.0.0.2-8iTQWWAwtXhCoH4lsrSYWM" 'False) (C1 ('MetaCons "Annotated" 'PrefixI 'True) (S1 ('MetaSel ('Just "unAnnotated") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 b) :*: S1 ('MetaSel ('Just "annotation") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)))
type BaseType (Annotated b ByteString) Source # 
Instance details

Defined in Cardano.Binary.Annotated

data ByteSpan Source #

A pair of offsets delimiting the beginning and end of a substring of a ByteString

Instances

Instances details
ToJSON ByteSpan Source # 
Instance details

Defined in Cardano.Binary.Annotated

Generic ByteSpan Source # 
Instance details

Defined in Cardano.Binary.Annotated

Associated Types

type Rep ByteSpan :: Type -> Type Source #

Show ByteSpan Source # 
Instance details

Defined in Cardano.Binary.Annotated

type Rep ByteSpan Source # 
Instance details

Defined in Cardano.Binary.Annotated

type Rep ByteSpan = D1 ('MetaData "ByteSpan" "Cardano.Binary.Annotated" "cardano-binary-1.5.0.0.0.0.0.2-8iTQWWAwtXhCoH4lsrSYWM" 'False) (C1 ('MetaCons "ByteSpan" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteOffset) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteOffset)))

class Decoded t where Source #

Associated Types

type BaseType t :: Type Source #

Instances

Instances details
Decoded (Annotated b ByteString) Source # 
Instance details

Defined in Cardano.Binary.Annotated

Associated Types

type BaseType (Annotated b ByteString) Source #

annotatedDecoder :: Decoder s a -> Decoder s (Annotated a ByteSpan) Source #

A decoder for a value paired with an annotation specifying the start and end of the consumed bytes.

slice :: ByteString -> ByteSpan -> ByteString Source #

Extract a substring of a given ByteString corresponding to the offsets.

fromCBORAnnotated :: FromCBOR a => Decoder s (Annotated a ByteSpan) Source #

A decoder for a value paired with an annotation specifying the start and end of the consumed bytes.

decodeFullAnnotatedBytes :: Functor f => Text -> (forall s. Decoder s (f ByteSpan)) -> ByteString -> Either DecoderError (f ByteString) Source #

Decodes a value from a ByteString, requiring that the full ByteString is consumed, and replaces ByteSpan annotations with the corresponding substrings of the input string.

reAnnotate :: ToCBOR a => Annotated a b -> Annotated a ByteString Source #

Reconstruct an annotation by re-serialising the payload to a ByteString.

newtype Annotator a Source #

A value of type (Annotator a) is one that needs access to the entire bytestring used during decoding to finish construction of a vaue of type a. A typical use is some type that stores the bytes that were used to deserialize it. For example the type Inner below is constructed using the helper function makeInner which serializes and stores its bytes (using serializeEncoding). Note how we build the Annotator by abstracting over the full bytes, and using those original bytes to fill the bytes field of the constructor Inner. The ToCBOR instance just reuses the stored bytes to produce an encoding (using encodePreEncoded).

data Inner = Inner Int Bool LByteString

makeInner :: Int -> Bool -> Inner
makeInner i b = Inner i b (serializeEncoding (toCBOR i <> toCBOR b))

instance ToCBOR Inner where
  toCBOR (Inner _ _ bytes) = encodePreEncoded bytes

instance FromCBOR (Annotator Inner) where
  fromCBOR = do
     int <- fromCBOR
     trueOrFalse <- fromCBOR
     pure (Annotator ((Full bytes) -> Inner int trueOrFalse bytes))

if an Outer type has a field of type Inner, with a (ToCBOR (Annotator Inner)) instance, the Outer type must also have a (ToCBOR (Annotator Outer)) instance. The key to writing that instance is to use the operation withSlice which returns a pair. The first component is an Annotator that can build Inner, the second is an Annotator that given the full bytes, extracts just the bytes needed to decode Inner.

data Outer = Outer Text Inner

instance ToCBOR Outer where
  toCBOR (Outer t i) = toCBOR t <> toCBOR i

instance FromCBOR (Annotator Outer) where
  fromCBOR = do
    t <- fromCBOR
    (Annotator mkInner, Annotator extractInnerBytes) <- withSlice fromCBOR
    pure (Annotator ( full -> Outer t (mkInner (Full (extractInnerBytes full)))))

Constructors

Annotator 

Instances

Instances details
Applicative Annotator Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

pure :: a -> Annotator a Source #

(<*>) :: Annotator (a -> b) -> Annotator a -> Annotator b Source #

liftA2 :: (a -> b -> c) -> Annotator a -> Annotator b -> Annotator c Source #

(*>) :: Annotator a -> Annotator b -> Annotator b Source #

(<*) :: Annotator a -> Annotator b -> Annotator a Source #

Functor Annotator Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

fmap :: (a -> b) -> Annotator a -> Annotator b Source #

(<$) :: a -> Annotator b -> Annotator a Source #

Monad Annotator Source # 
Instance details

Defined in Cardano.Binary.Annotated

Methods

(>>=) :: Annotator a -> (a -> Annotator b) -> Annotator b Source #

(>>) :: Annotator a -> Annotator b -> Annotator b Source #

return :: a -> Annotator a Source #

annotatorSlice :: Decoder s (Annotator (ByteString -> a)) -> Decoder s (Annotator a) Source #

The argument is a decoder for a annotator that needs access to the bytes that | were decoded. This function constructs and supplies the relevant piece.

decodeAnnotator :: Text -> (forall s. Decoder s (Annotator a)) -> ByteString -> Either DecoderError a Source #

Supplies the bytestring argument to both the decoder and the produced annotator.

withSlice :: Decoder s a -> Decoder s (a, Annotator ByteString) Source #

Pairs the decoder result with an annotator that can be used to construct the exact bytes used to decode the result.

newtype FullByteString Source #

This marks the entire bytestring used during decoding, rather than the piece we need to finish constructing our value.

Constructors

Full ByteString 

serializeEncoding :: Encoding -> ByteString Source #

Serialize a Haskell value to an external binary representation using the provided CBOR Encoding

The output is represented as an LByteString and is constructed incrementally.

encodePreEncoded :: ByteString -> Encoding Source #

Include pre-encoded valid CBOR data into the Encoding.

The data is included into the output as-is without any additional wrapper.

This should be used with care. The data must be a valid CBOR encoding, but this is not checked.

This is useful when you have CBOR data that you know is already valid, e.g. previously validated and stored on disk, and you wish to include it without having to decode and re-encode it.

Since: cborg-0.2.2.0