cardano-ledger-binary-1.6.0.0: Binary serialization library used throughout ledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Ledger.Binary.Decoding

Synopsis

Running decoders

decodeFull ∷ ∀ a. DecCBOR a ⇒ VersionByteStringEither DecoderError a Source #

Deserialize a Haskell value from a binary CBOR representation, failing if there are leftovers. In other words, the Full here implies the contract on this function that the input must be consumed in its entirety by the decoder specified in DecCBOR.

decodeFull' ∷ ∀ a. DecCBOR a ⇒ VersionByteStringEither DecoderError a Source #

Same as decodeFull, except accepts a strict ByteString as input instead of the lazy one.

decodeFullDecoder Source #

Arguments

Version

Protocol version to be used during decoding.

Text

Label for error reporting

→ (∀ 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 

Same as decodeFull, except instead of relying on the DecCBOR instance the Decoder must be suplied manually.

decodeFullDecoder'VersionText → (∀ s. Decoder s a) → ByteStringEither DecoderError a Source #

Same as decodeFullDecoder, except works on strict ByteString

decodeFullAnnotatorVersionText → (∀ s. Decoder s (Annotator a)) → ByteStringEither DecoderError a Source #

Same as decodeFullDecoder, except it provdes the means of passing portion or all of the ByteString input argument to the decoding Annotator.

decodeFullAnnotatedBytesFunctor f ⇒ VersionText → (∀ s. Decoder s (f ByteSpan)) → ByteStringEither DecoderError (f ByteString) Source #

Same as decodeFullDecoder, decodes a Haskell value from a lazy ByteString, requiring that the full ByteString is consumed, and replaces ByteSpan annotations with the corresponding slice of the input as a strict ByteString.

class Typeable a ⇒ DecCBOR a where Source #

Minimal complete definition

Nothing

Methods

decCBORDecoder s a Source #

default decCBORFromCBOR a ⇒ Decoder s a Source #

dropCBORProxy a → Decoder s () Source #

Validate decoding of a Haskell value, without the need to actually construct it. Could be slightly faster than decCBOR, however it should respect this law:

dropCBOR (proxy :: Proxy a) = () <$ (decCBOR :: Decoder s a)

labelProxy a → Text Source #

Instances

Instances details
DecCBOR Void Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Int16 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Int32 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Int64 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Int8 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Rational Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Word16 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Word32 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Word64 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Word8 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ByteString Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ByteString Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ShortByteString Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Proof Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR SignKey Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR VerKey Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Version Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR BlockNo Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR EpochInterval Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR EpochNo Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR EpochSize Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR SlotNo Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR SystemStart Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ByteArray Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR SlicedByteArray Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Term Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ByteArray Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR IPv4 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR IPv6 Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Data Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ScriptContext Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ScriptContext Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR ScriptContext Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Text Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR UTCTime Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Integer Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Natural Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR () Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s () Source #

dropCBORProxy () → Decoder s () Source #

labelProxy () → Text Source #

DecCBOR Bool Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Double Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Float Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Int Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR Word Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DSIGNAlgorithm v ⇒ DecCBOR (SigDSIGN v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DSIGNAlgorithm v ⇒ DecCBOR (SignKeyDSIGN v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DSIGNAlgorithm v ⇒ DecCBOR (VerKeyDSIGN v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

KESAlgorithm k ⇒ DecCBOR (SigKES k) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (SigKES k) Source #

dropCBORProxy (SigKES k) → Decoder s () Source #

labelProxy (SigKES k) → Text Source #

KESAlgorithm k ⇒ DecCBOR (VerKeyKES k) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (CertVRF MockVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (CertVRF SimpleVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (CertVRF PraosVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Typeable v ⇒ DecCBOR (OutputVRF v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (SignKeyVRF MockVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (SignKeyVRF SimpleVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (SignKeyVRF PraosVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (VerKeyVRF MockVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (VerKeyVRF SimpleVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (VerKeyVRF PraosVRF) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR (Annotator Data) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

DecCBOR a ⇒ DecCBOR (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

decCBORDecoder s (Sized a) Source #

dropCBORProxy (Sized a) → Decoder s () Source #

labelProxy (Sized a) → Text Source #

(DecCBORGroup a, EncCBORGroup a) ⇒ DecCBOR (CBORGroup a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Group

(Serialise t, Typeable t) ⇒ DecCBOR (WithOrigin t) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR a ⇒ DecCBOR (StrictMaybe a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR a ⇒ DecCBOR (StrictSeq a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR a ⇒ DecCBOR (Seq a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Seq a) Source #

dropCBORProxy (Seq a) → Decoder s () Source #

labelProxy (Seq a) → Text Source #

(Ord a, DecCBOR a) ⇒ DecCBOR (Set a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Set a) Source #

dropCBORProxy (Set a) → Decoder s () Source #

labelProxy (Set a) → Text Source #

DecCBOR a ⇒ DecCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Vector a) Source #

dropCBORProxy (Vector a) → Decoder s () Source #

labelProxy (Vector a) → Text Source #

(DecCBOR a, Prim a) ⇒ DecCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Vector a) Source #

dropCBORProxy (Vector a) → Decoder s () Source #

labelProxy (Vector a) → Text Source #

(DecCBOR a, Storable a) ⇒ DecCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Vector a) Source #

dropCBORProxy (Vector a) → Decoder s () Source #

labelProxy (Vector a) → Text Source #

(DecCBOR a, Unbox a) ⇒ DecCBOR (Vector a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Vector a) Source #

dropCBORProxy (Vector a) → Decoder s () Source #

labelProxy (Vector a) → Text Source #

DecCBOR a ⇒ DecCBOR (NonEmpty a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

DecCBOR a ⇒ DecCBOR (Maybe a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Maybe a) Source #

dropCBORProxy (Maybe a) → Decoder s () Source #

labelProxy (Maybe a) → Text Source #

DecCBOR a ⇒ DecCBOR [a] Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s [a] Source #

dropCBORProxy [a] → Decoder s () Source #

labelProxy [a] → Text Source #

(DecCBOR a, DecCBOR b) ⇒ DecCBOR (Either a b) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Either a b) Source #

dropCBORProxy (Either a b) → Decoder s () Source #

labelProxy (Either a b) → Text Source #

Typeable p ⇒ DecCBOR (Fixed p) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Fixed p) Source #

dropCBORProxy (Fixed p) → Decoder s () Source #

labelProxy (Fixed p) → Text Source #

(DSIGNAlgorithm v, Typeable a) ⇒ DecCBOR (SignedDSIGN v a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

(HashAlgorithm h, Typeable a) ⇒ DecCBOR (Hash h a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Hash h a) Source #

dropCBORProxy (Hash h a) → Decoder s () Source #

labelProxy (Hash h a) → Text Source #

(VRFAlgorithm v, Typeable a) ⇒ DecCBOR (CertifiedVRF v a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

(Ord k, DecCBOR k, DecCBOR v) ⇒ DecCBOR (Map k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (Map k v) Source #

dropCBORProxy (Map k v) → Decoder s () Source #

labelProxy (Map k v) → Text Source #

(DecCBOR a, DecCBOR b) ⇒ DecCBOR (a, b) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b) Source #

dropCBORProxy (a, b) → Decoder s () Source #

labelProxy (a, b) → Text Source #

(Typeable s, DecCBOR a) ⇒ DecCBOR (Tagged s a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s0 (Tagged s a) Source #

dropCBORProxy (Tagged s a) → Decoder s0 () Source #

labelProxy (Tagged s a) → Text Source #

(DecCBOR a, DecCBOR b, DecCBOR c) ⇒ DecCBOR (a, b, c) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b, c) Source #

dropCBORProxy (a, b, c) → Decoder s () Source #

labelProxy (a, b, c) → Text Source #

(Ord k, DecCBOR k, DecCBOR a, Typeable kv, Typeable av, Vector kv k, Vector av a) ⇒ DecCBOR (VMap kv av k a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (VMap kv av k a) Source #

dropCBORProxy (VMap kv av k a) → Decoder s () Source #

labelProxy (VMap kv av k a) → Text Source #

(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d) ⇒ DecCBOR (a, b, c, d) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b, c, d) Source #

dropCBORProxy (a, b, c, d) → Decoder s () Source #

labelProxy (a, b, c, d) → Text Source #

(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d, DecCBOR e) ⇒ DecCBOR (a, b, c, d, e) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b, c, d, e) Source #

dropCBORProxy (a, b, c, d, e) → Decoder s () Source #

labelProxy (a, b, c, d, e) → Text Source #

(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d, DecCBOR e, DecCBOR f) ⇒ DecCBOR (a, b, c, d, e, f) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b, c, d, e, f) Source #

dropCBORProxy (a, b, c, d, e, f) → Decoder s () Source #

labelProxy (a, b, c, d, e, f) → Text Source #

(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d, DecCBOR e, DecCBOR f, DecCBOR g) ⇒ DecCBOR (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.DecCBOR

Methods

decCBORDecoder s (a, b, c, d, e, f, g) Source #

dropCBORProxy (a, b, c, d, e, f, g) → Decoder s () Source #

labelProxy (a, b, c, d, e, f, g) → Text Source #

fromByronCBORDecCBOR a ⇒ Decoder s a Source #

Convert a versioned DecCBOR instance to a plain Decoder using Byron protocol version and empty ByteString.

class Monoid (Share a) ⇒ DecShareCBOR a where Source #

Minimal complete definition

(decShareCBOR | decSharePlusCBOR)

Associated Types

type Share a ∷ Type Source #

type Share a = ()

Methods

getShare ∷ a → Share a Source #

Whenever fromShareCBOR is being used for defining the instance this function should return the state that can be added whenever user invokes decSharePlusCBOR. mempty is returned by default.

decShareCBORShare a → Decoder s a Source #

Utilize sharing when decoding, but do not add anything to the state for future sharing.

decSharePlusCBORStateT (Share a) (Decoder s) a Source #

Deserialize with sharing and add to the state that is used for sharing. Default implementation will add value returned by getShare for adding to the state.

Instances

Instances details
(Ord k, DecCBOR k, DecCBOR v) ⇒ DecShareCBOR (Map k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (Map k v) Source #

Methods

getShareMap k v → Share (Map k v) Source #

decShareCBORShare (Map k v) → Decoder s (Map k v) Source #

decSharePlusCBORStateT (Share (Map k v)) (Decoder s) (Map k v) Source #

(Ord k, DecCBOR k, DecCBOR v) ⇒ DecShareCBOR (VMap VB VB k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (VMap VB VB k v) Source #

Methods

getShareVMap VB VB k v → Share (VMap VB VB k v) Source #

decShareCBORShare (VMap VB VB k v) → Decoder s (VMap VB VB k v) Source #

decSharePlusCBORStateT (Share (VMap VB VB k v)) (Decoder s) (VMap VB VB k v) Source #

(Ord k, DecCBOR k, DecCBOR v, Prim v) ⇒ DecShareCBOR (VMap VB VP k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (VMap VB VP k v) Source #

Methods

getShareVMap VB VP k v → Share (VMap VB VP k v) Source #

decShareCBORShare (VMap VB VP k v) → Decoder s (VMap VB VP k v) Source #

decSharePlusCBORStateT (Share (VMap VB VP k v)) (Decoder s) (VMap VB VP k v) Source #

newtype Interns a Source #

Constructors

Interns [Intern a] 

Instances

Instances details
Monoid (Interns a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Methods

memptyInterns a Source #

mappendInterns a → Interns a → Interns a Source #

mconcat ∷ [Interns a] → Interns a Source #

Semigroup (Interns a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Methods

(<>)Interns a → Interns a → Interns a Source #

sconcatNonEmpty (Interns a) → Interns a Source #

stimesIntegral b ⇒ b → Interns a → Interns a Source #

data Intern a Source #

This is an abstract interface that does the interning. In other words it does the actual sharing by looking up the supplied value in some existing data structure and uses that value instead. Relying on this interface gives us the benefit of ignoring the type of underlying data structure and allows us to compose many Interns with the monoidal interface provided by Interns wrapper. In order to create an Intern see the internsFromMap or internsFromVMap functions.

Constructors

Intern 

Fields

  • internMaybe ∷ a → Maybe a

    Function that will do the interning. If value is not available then Nothing is returned.

  • internWeight ∷ !Int

    Used for sorting. Normally set to the size of the underlying data structure. Keeping interns sorted with respect to how many elements is in the underlying data structure in theory gives a better chance of successful intern hit sooner rather than later.

decSharePlusLensCBORDecShareCBOR b ⇒ Lens' bs (Share b) → StateT bs (Decoder s) b Source #

Just like decSharePlusCBOR, except allows to transform the shared state with a lens.

decNoShareCBORDecShareCBOR a ⇒ Decoder s a Source #

Use DecShareCBOR class while ignoring sharing

internsInterns k → k → k Source #

internsFromMapOrd k ⇒ Map k a → Interns k Source #

internsFromVMapOrd k ⇒ VMap VB kv k a → Interns k Source #

toMemptyLensMonoid a ⇒ Lens' a b → Lens' c b → Lens' c a Source #

Using this function it is possible to compose two lenses. One will extract a value and another will used it for placing it into a empty monoid. Here is an example of how a second element of a tuple can be projected on the third element of a 3-tuple.

toMemptyLens _3 _2 == lens (\(_, b) -> (mempty, mempty, b)) (\(a, _) (_, _, b) -> (a, b))

Here is an example where we extract a second element of a tuple and insert it at third position of a three tuple while all other elements are set to mempty:

>>> import Lens.Micro
>>> ("foo","bar") ^. toMemptyLens _3 _2 :: (Maybe String, (), String)
(Nothing,(),"bar")

In the opposite direction of extracting the third element of a 3-tuple and replacing the second element of the tuple the setter is being applied to

>>> ("foo","bar") & toMemptyLens _3 _2 .~ (Just "baz", (), "booyah") :: (String, String)
("foo","booyah")

decShareMonadCBOR ∷ (DecCBOR (f b), Monad f) ⇒ Interns b → Decoder s (f b) Source #

Share every item in a functor, have deserializing it

type ByteOffset = Int64 Source #

A 0-based offset within the overall byte sequence that makes up the input to the Decoder.

This is an Int64 since Decoder is incremental and can decode more data than fits in memory at once. This is also compatible with the result type of length.

data TokenType Source #

The type of a token, which a decoder can ask for at an arbitrary time.

Since: cborg-0.2.0.0

data DecodeAction s a Source #

An action, representing a step for a decoder to taken and a continuation to invoke with the expected value.

Since: cborg-0.2.0.0

Constructors

ConsumeWord (Word#ST s (DecodeAction s a)) 
ConsumeWord8 (Word#ST s (DecodeAction s a)) 
ConsumeWord16 (Word#ST s (DecodeAction s a)) 
ConsumeWord32 (Word#ST s (DecodeAction s a)) 
ConsumeNegWord (Word#ST s (DecodeAction s a)) 
ConsumeInt (Int#ST s (DecodeAction s a)) 
ConsumeInt8 (Int#ST s (DecodeAction s a)) 
ConsumeInt16 (Int#ST s (DecodeAction s a)) 
ConsumeInt32 (Int#ST s (DecodeAction s a)) 
ConsumeListLen (Int#ST s (DecodeAction s a)) 
ConsumeMapLen (Int#ST s (DecodeAction s a)) 
ConsumeTag (Word#ST s (DecodeAction s a)) 
ConsumeInteger (IntegerST s (DecodeAction s a)) 
ConsumeFloat (Float#ST s (DecodeAction s a)) 
ConsumeDouble (Double#ST s (DecodeAction s a)) 
ConsumeBytes (ByteStringST s (DecodeAction s a)) 
ConsumeByteArray (ByteArrayST s (DecodeAction s a)) 
ConsumeString (TextST s (DecodeAction s a)) 
ConsumeUtf8ByteArray (ByteArrayST s (DecodeAction s a)) 
ConsumeBool (BoolST s (DecodeAction s a)) 
ConsumeSimple (Word#ST s (DecodeAction s a)) 
ConsumeBytesIndef (ST s (DecodeAction s a)) 
ConsumeStringIndef (ST s (DecodeAction s a)) 
ConsumeListLenIndef (ST s (DecodeAction s a)) 
ConsumeMapLenIndef (ST s (DecodeAction s a)) 
ConsumeNull (ST s (DecodeAction s a)) 
ConsumeListLenOrIndef (Int#ST s (DecodeAction s a)) 
ConsumeMapLenOrIndef (Int#ST s (DecodeAction s a)) 
ConsumeBreakOr (BoolST s (DecodeAction s a)) 
PeekTokenType (TokenTypeST s (DecodeAction s a)) 
PeekAvailable (Int#ST s (DecodeAction s a)) 
PeekByteOffset (Int#ST s (DecodeAction s a)) 
ConsumeWordCanonical (Word#ST s (DecodeAction s a)) 
ConsumeWord8Canonical (Word#ST s (DecodeAction s a)) 
ConsumeWord16Canonical (Word#ST s (DecodeAction s a)) 
ConsumeWord32Canonical (Word#ST s (DecodeAction s a)) 
ConsumeNegWordCanonical (Word#ST s (DecodeAction s a)) 
ConsumeIntCanonical (Int#ST s (DecodeAction s a)) 
ConsumeInt8Canonical (Int#ST s (DecodeAction s a)) 
ConsumeInt16Canonical (Int#ST s (DecodeAction s a)) 
ConsumeInt32Canonical (Int#ST s (DecodeAction s a)) 
ConsumeListLenCanonical (Int#ST s (DecodeAction s a)) 
ConsumeMapLenCanonical (Int#ST s (DecodeAction s a)) 
ConsumeTagCanonical (Word#ST s (DecodeAction s a)) 
ConsumeIntegerCanonical (IntegerST s (DecodeAction s a)) 
ConsumeFloat16Canonical (Float#ST s (DecodeAction s a)) 
ConsumeFloatCanonical (Float#ST s (DecodeAction s a)) 
ConsumeDoubleCanonical (Double#ST s (DecodeAction s a)) 
ConsumeBytesCanonical (ByteStringST s (DecodeAction s a)) 
ConsumeByteArrayCanonical (ByteArrayST s (DecodeAction s a)) 
ConsumeStringCanonical (TextST s (DecodeAction s a)) 
ConsumeUtf8ByteArrayCanonical (ByteArrayST s (DecodeAction s a)) 
ConsumeSimpleCanonical (Word#ST s (DecodeAction s a)) 
Fail String 
Done a 

cborError ∷ (MonadFail m, Buildable e) ⇒ e → m a Source #

Convert a Buildable error message into a MonadFail failure.

toCborError ∷ (MonadFail m, Buildable e) ⇒ Either e a → m a Source #

Convert an Either-encoded failure to a MonadFail failure using the Buildable insatance

invalidKeyMonadFail m ⇒ Word → m a Source #

Report an error when a numeric key of the type constructor doesn't match.

data Decoder s a Source #

Instances

Instances details
MonadFail (Decoder s) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Decoder

Methods

failStringDecoder s a Source #

Applicative (Decoder s) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Decoder

Methods

pure ∷ a → Decoder s a Source #

(<*>)Decoder s (a → b) → Decoder s a → Decoder s b Source #

liftA2 ∷ (a → b → c) → Decoder s a → Decoder s b → Decoder s c Source #

(*>)Decoder s a → Decoder s b → Decoder s b Source #

(<*)Decoder s a → Decoder s b → Decoder s a Source #

Functor (Decoder s) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Decoder

Methods

fmap ∷ (a → b) → Decoder s a → Decoder s b Source #

(<$) ∷ a → Decoder s b → Decoder s a Source #

Monad (Decoder s) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Decoder

Methods

(>>=)Decoder s a → (a → Decoder s b) → Decoder s b Source #

(>>)Decoder s a → Decoder s b → Decoder s b Source #

return ∷ a → Decoder s a Source #

fromPlainDecoderDecoder s a → Decoder s a Source #

Promote a regular Decoder to a versioned one. Which means it will work for all versions.

toPlainDecoder Source #

Arguments

Maybe ByteString

Some decoders require the original bytes to be supplied as well. Such decoders will fail whenever Nothing is supplied.

Version 
Decoder s a 
Decoder s a 

Extract the underlying Decoder by optionally supplying the original bytes and specifying the concrete version to be used.

withPlainDecoderDecoder s a → (Decoder s a → Decoder s b) → Decoder s b Source #

Use the supplied decoder as a plain decoder with current version.

enforceDecoderVersionVersionDecoder s a → Decoder s a Source #

Ignore the current version of the decoder and enforce the supplied one instead.

getDecoderVersionDecoder s Version Source #

Extract current version of the decoder

>>> import Cardano.Ledger.Decoding
>>> decodeFullDecoder 3 "Version" getDecoderVersion ""
Right 3

ifDecoderVersionAtLeast Source #

Arguments

Version 
Decoder s a

Use this decoder if current decoder version is larger or equal to the supplied Version

Decoder s a

Use this decoder if current decoder version is lower than the supplied Version

Decoder s a 

Conditionally choose the newer or older decoder, depending on the current version. Version in the context of encoders/decoders is the major protocol version. Supplied version acts as a pivot.

Example
Expand

Let's say prior to the version 2 some type Foo was backed by Word16, but at the 2nd version onwards it was switched to Word32 instead. In order to support both versions, we change the type, but we also use this condition to keep backwards compatibility of the decoder:

>>> newtype Foo = Foo Word32
>>> decFoo = Foo <$> ifDecoderVersionAtLeast 2 decodeWord32 (fromIntegral <$> decodeWord16)

whenDecoderVersionAtLeast Source #

Arguments

Version 
Decoder s a

Run this decoder whenever current decoder version is larger or equal to the supplied Version

Decoder s () 

Optionally run a decoder depending on the current version and the supplied one.

unlessDecoderVersionAtLeast Source #

Arguments

Version 
Decoder s a

Run this decoder whenever current decoder version is smaller to the supplied Version

Decoder s () 

Optionally run a decoder depending on the current version and the supplied one.

decodeRationalDecoder s Rational Source #

Decoder for Rational. Versions variance:

  • [>= 9] - Allows variable as well as exact list length encoding. Consumes tag 30 if one is present, but does not enforce it.
  • [>= 2] - Allows variable as well as exact list length encoding.
  • [== 1] - Expects exact list length encoding.

decodeListDecoder s a → Decoder s [a] Source #

Decoder for list.

  • [>= 2] - Allows variable as well as exact list length encoding.
  • [< 2] - Expects variable list length encoding

decodeMaybeDecoder s a → Decoder s (Maybe a) Source #

Decoder for Maybe. Versions variance:

  • [>= 2] - Allows variable as well as exact list length encoding.
  • [< 2] - Expects exact list length encoding

decodeNullMaybeDecoder s a → Decoder s (Maybe a) Source #

Alternative way to decode a Maybe type.

Note - this is not the default method for decoding Maybe, use decodeMaybe instead.

decodeStrictMaybeDecoder s a → Decoder s (StrictMaybe a) Source #

Unlike decodeMaybe this allows variable as well as exact list length encoding for all versions, because Byron never used StrictMaybe type.

decodeNullStrictMaybeDecoder s a → Decoder s (StrictMaybe a) Source #

Alternative way to decode a StrictMaybe type.

Note - this is not the default method for decoding StrictMaybe, use decodeStrictMaybe instead.

decodeEitherDecoder s a → Decoder s b → Decoder s (Either a b) Source #

decodeRecordNamedText → (a → Int) → Decoder s a → Decoder s a Source #

decodeRecordNamedT ∷ (MonadTrans m, Monad (m (Decoder s))) ⇒ Text → (a → Int) → m (Decoder s) a → m (Decoder s) a Source #

decodeRecordSumText → (WordDecoder s (Int, a)) → Decoder s a Source #

decodeListLike Source #

Arguments

Text

Name for error reporting

Decoder s a

Decoder for the datastructure itself

→ (a → IntDecoder s ())

In case when length was encoded, act upon it.

Decoder s a 

Use this decoder for any list like structure that accepts fixed or variable list length encoding.

decodeListLikeT Source #

Arguments

∷ (MonadTrans m, Monad (m (Decoder s))) 
Text

Name for error reporting

→ m (Decoder s) a

Decoder for the datastructure itself

→ (a → Int → m (Decoder s) ())

In case when length was encoded, act upon it.

→ m (Decoder s) a 

decodeEnumBounded ∷ ∀ a s. (Enum a, Bounded a, Typeable a) ⇒ Decoder s a Source #

decodeMapOrd k ⇒ Decoder s k → Decoder s v → Decoder s (Map k v) Source #

Decoder for Map. Versions variance:

  • [>= 9] - Allows variable as well as exact list length encoding. Duplicate keys will result in a deserialization failure
  • [>= 2] - Allows variable as well as exact list length encoding. Duplicate keys are silently ignored
  • [< 2] - Expects exact list length encoding and enforces strict order without any duplicates.

An example of how to use versioning

>>> :set -XOverloadedStrings
>>> import Codec.CBOR.FlatTerm
>>> fromFlatTerm (toPlainDecoder 1 (decodeMap decodeInt decodeBytes)) [TkMapLen 2,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar"]
Right (fromList [(1,"Foo"),(2,"Bar")])
>>> fromFlatTerm (toPlainDecoder 1 (decodeMap decodeInt decodeBytes)) [TkMapBegin,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar"]
Left "decodeMapLen: unexpected token TkMapBegin"
>>> fromFlatTerm (toPlainDecoder 2 (decodeMap decodeInt decodeBytes)) [TkMapBegin,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar",TkBreak]
Right (fromList [(1,"Foo"),(2,"Bar")])

decodeMapByKeyOrd k ⇒ Decoder s k → (k → Decoder s v) → Decoder s (Map k v) Source #

Just like decodeMap, but also gives access to the key for the value decoder.

decodeMapLikeEnforceNoDuplicatesOrd k ⇒ Decoder s (Maybe Int) → Decoder s (k, v) → Decoder s (Map k v) Source #

Similar to decodeMapByKey, except it gives access to the key value decoder as a pair and allows for different type of length encoding

decodeVMap ∷ (Vector kv k, Vector vv v, Ord k) ⇒ Decoder s k → Decoder s v → Decoder s (VMap kv vv k v) Source #

Decode VMap. Unlike decodeMap it does not behavee differently for version prior to 2.

setTagWord Source #

We stitch a `258` in from of a (Hash)Set, so that tools which programmatically check for canonicity can recognise it from a normal array. Why 258? This will be formalised pretty soon, but IANA allocated 256...18446744073709551615 to "First come, first served": https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml Currently `258` is the first unassigned tag and as it requires 2 bytes to be encoded, it sounds like the best fit.

https://github.com/input-output-hk/cbor-sets-spec/blob/master/CBOR_SETS.md

decodeSetOrd a ⇒ Decoder s a → Decoder s (Set a) Source #

Decoder for Set. Versions variance:

  • [>= 9] - Allows variable as well as exact list length encoding. Duplicates are not allowed. Set tag 258 is permitted, but not enforced.
  • [>= 2, < 9] - Allows variable as well as exact list length encoding. Duplicates are silently ignored, set tag 258 is not permitted.
  • [< 2] - Expects exact list length encoding and enforces strict order without any duplicates. Also enforces special set tag 258, which was abandoned starting with version 2

decodeListLikeWithCount Source #

Arguments

∷ ∀ s a b. Monoid b 
Decoder s (Maybe Int)

Length decoder that produces the expected number of elements. When Nothing is decoded the decodeBreakOr will be used as termination indicator.

→ (a → b → b)

Add an element into the decoded List like data structure

→ (b → Decoder s a)

Decoder for the values. Current accumulator is supplied as an argument

Decoder s (Int, b) 

Decode a collection of values with ability to supply length decoder. Number of decoded elements will be returned together with the data structure

decodeListLikeEnforceNoDuplicates Source #

Arguments

∷ ∀ s a b c. Monoid b 
Decoder s (Maybe Int) 
→ (a → b → b)

Add an element into the decoded List like data structure

→ (b → (Int, c))

Get the final data structure and the number of elements it has.

Decoder s a 
Decoder s c 

Decode a collection of values with ability to supply length decoder. Duplicates are not allowed.

decodeSetLikeEnforceNoDuplicates Source #

Arguments

∷ ∀ s a b c. Monoid b 
⇒ (a → b → b)

Add an element into the decoded Set like data structure

→ (b → (Int, c))

Get the final data structure from the decoded sequence of values and the number of elements it contains. This is useful when a sequence on the wire is represented by a set, namely no duplicates are allowed, while the Haskell representation uses some other data structure that enforces no duplicates by some other means. For example a Map, where keys are hashes of the values encoded on the wire. The size of the final data structure will be used to enforce the invariant that the number of elements decoded matches the final size of the Set like data structure, thus ensuring no duplicates were encountered.

Decoder s a 
Decoder s c 

Decode a Set as a either a definite or indefinite list. Duplicates are not allowed. Set tag 258 is permitted, but not enforced.

decodeVectorVector vec a ⇒ Decoder s a → Decoder s (vec a) Source #

Generic decoder for vectors. Its intended use is to allow easy definition of Serialise instances for custom vector

decodeSeqDecoder s a → Decoder s (Seq a) Source #

Decoder for Seq. Same behavior for all versions, allows variable as well as exact list length encoding

decodeStrictSeqDecoder s a → Decoder s (StrictSeq a) Source #

Decoder for StrictSeq. Same behavior for all versions, allows variable as well as exact list length encoding.

decodeMapTraverse ∷ (Ord a, Applicative t) ⇒ Decoder s (t a) → Decoder s (t b) → Decoder s (t (Map a b)) Source #

decodeMapContentsTraverseApplicative t ⇒ Decoder s (t a) → Decoder s (t b) → Decoder s (t [(a, b)]) Source #

decodeUTCTimeDecoder s UTCTime Source #

Decoder for UTCTime. Versions variance:

  • [>= 2] - Allows variable list length encoding, but still expects number of elements to be 3.
  • [< 2] - Expects exact list length encoding to be 3

binaryGetDecoder Source #

Arguments

Bool

Flag to allow left over at the end or not

Text

Name of the function or type for error reporting

Get a

Deserializer for the binary package

Decoder s a 

Convert a Get monad from binary package into a Decoder

enforceSizeTextIntDecoder s () Source #

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

matchSizeTextIntIntDecoder s () Source #

Compare two sizes, failing if they are not equal

decodeSequenceLenIndef ∷ (r → a → r) → r → (r → b) → Decoder s a → Decoder s b Source #

decodeSequenceLenN ∷ (r → a → r) → r → (r → b) → IntDecoder s a → Decoder s b Source #

data Sized a Source #

A CBOR deserialized value together with its size. When deserializing use either decodeSized or its DecCBOR instance.

Use mkSized to construct such value.

Constructors

Sized 

Fields

  • sizedValue ∷ !a
     
  • sizedSizeInt64

    Overhead in bytes. The field is lazy on purpose, because it might not be needed, but it can be expensive to compute.

Instances

Instances details
Generic (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Associated Types

type Rep (Sized a) ∷ TypeType Source #

Methods

fromSized a → Rep (Sized a) x Source #

toRep (Sized a) x → Sized a Source #

Show a ⇒ Show (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

showsPrecIntSized a → ShowS Source #

showSized a → String Source #

showList ∷ [Sized a] → ShowS Source #

DecCBOR a ⇒ DecCBOR (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

decCBORDecoder s (Sized a) Source #

dropCBORProxy (Sized a) → Decoder s () Source #

labelProxy (Sized a) → Text Source #

EncCBOR a ⇒ EncCBOR (Sized a) Source #

Discards the size.

Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

encCBORSized a → Encoding Source #

encodedSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy (Sized a) → Size Source #

encodedListSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy [Sized a] → Size Source #

NFData a ⇒ NFData (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

rnfSized a → () Source #

Eq a ⇒ Eq (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

Methods

(==)Sized a → Sized a → Bool Source #

(/=)Sized a → Sized a → Bool Source #

NoThunks a ⇒ NoThunks (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

type Rep (Sized a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sized

type Rep (Sized a) = D1 ('MetaData "Sized" "Cardano.Ledger.Binary.Decoding.Sized" "cardano-ledger-binary-1.6.0.0-inplace" 'False) (C1 ('MetaCons "Sized" 'PrefixI 'True) (S1 ('MetaSel ('Just "sizedValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "sizedSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64)))

mkSizedEncCBOR a ⇒ Version → a → Sized a Source #

Construct a Sized value by serializing it first and recording the amount of bytes it requires. Note, however, CBOR serialization is not canonical, therefore it is *NOT* a requirement that this property holds:

sizedSize (mkSized a) === sizedSize (unsafeDeserialize (serialize a) :: a)

toSizedLEncCBOR s ⇒ VersionLens' s a → Lens' (Sized s) a Source #

Take a lens that operates on a particular type and convert it into a lens that operates on the Sized version of the type.

type Dropper s = Decoder s () Source #

dropListDropper s → Dropper s Source #

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

dropTripleDropper s → Dropper s → Dropper s → Dropper s Source #

Annotated

The regular CBOR Decoder does not support access to the original ByteString that is being read during deserialization. The Annotator and Annotated recover this ability.

  1. ByteSpan A pair of indexes into a bytestring, indicating a substring.
  2. Annotated Used in practice to pair a value with a ByteSpan. Mostly used in Byron codebase.
  3. FullByteString A newtype (around a bytestring) used to store the original bytestring being deserialized.
  4. Annotator An explict reader monad whose environment is a FullByteString

The basic idea is, for a given type t, where we need the original ByteString, either

  1. To complete the deserialization, or
  2. To combine the deserialized answer with the original ByteString.

We should proceed as follows: Define instances (DecCBOR (Annotator t)) instead of (DecCBOR t). When making this instance we may freely use that both Decoder and Annotator are both monads, and that functions withSlice and annotatorSlice provide access to the original bytes, or portions thereof, inside of decoders. Then, to actually decode a value of type t, we use something similar to the following code fragment.

howToUseFullBytes bytes = do
  Annotator f <- decodeFullDecoder "DecodingAnnotator" (decCBOR :: forall s. Decoder s (Annotator t)) bytes
  pure (f (Full bytes))

Decode the bytes to get an (Annotator f) where f is a function that when given original bytes produces a value of type t, then apply f to (Full bytes) to get the answer.

data Annotated b a Source #

Constructors

Annotated 

Fields

Instances

Instances details
Bifunctor Annotated Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.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.Ledger.Binary.Decoding.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.Ledger.Binary.Decoding.Annotated

ToJSON b ⇒ ToJSON (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Generic (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Associated Types

type Rep (Annotated b a) ∷ TypeType Source #

Methods

fromAnnotated b a → Rep (Annotated b a) x Source #

toRep (Annotated b a) x → Annotated b a Source #

(Show b, Show a) ⇒ Show (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Methods

showsPrecIntAnnotated b a → ShowS Source #

showAnnotated b a → String Source #

showList ∷ [Annotated b a] → ShowS Source #

Decoded (Annotated b ByteString) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Associated Types

type BaseType (Annotated b ByteString) Source #

(NFData b, NFData a) ⇒ NFData (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Methods

rnfAnnotated b a → () Source #

(Eq b, Eq a) ⇒ Eq (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.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.Ledger.Binary.Decoding.Annotated

Methods

compareAnnotated 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 #

maxAnnotated b a → Annotated b a → Annotated b a Source #

minAnnotated b a → Annotated b a → Annotated b a Source #

(NoThunks b, NoThunks a) ⇒ NoThunks (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

type Rep (Annotated b a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

type Rep (Annotated b a) = D1 ('MetaData "Annotated" "Cardano.Ledger.Binary.Decoding.Annotated" "cardano-ledger-binary-1.6.0.0-inplace" '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.Ledger.Binary.Decoding.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.Ledger.Binary.Decoding.Annotated

Generic ByteSpan Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Associated Types

type Rep ByteSpanTypeType Source #

Show ByteSpan Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

type Rep ByteSpan Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

type Rep ByteSpan = D1 ('MetaData "ByteSpan" "Cardano.Ledger.Binary.Decoding.Annotated" "cardano-ledger-binary-1.6.0.0-inplace" 'False) (C1 ('MetaCons "ByteSpan" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteOffset) :*: S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteOffset)))

class Decoded t where Source #

Associated Types

type BaseType t ∷ Type Source #

Methods

recoverBytes ∷ t → ByteString Source #

Instances

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

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Associated Types

type BaseType (Annotated b ByteString) Source #

annotatedDecoderDecoder 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.

sliceByteStringByteSpanByteString Source #

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

decCBORAnnotatedDecCBOR 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.

reAnnotateEncCBOR a ⇒ VersionAnnotated 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 serialize). 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 EncCBOR 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 (serialize (encCBOR i <> encCBOR b))

instance EncCBOR Inner where
  encCBOR (Inner _ _ bytes) = encodePreEncoded bytes

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

if an Outer type has a field of type Inner, with a (EncCBOR (Annotator Inner)) instance, the Outer type must also have a (EncCBOR (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 EncCBOR Outer where
  encCBOR (Outer t i) = encCBOR t <> encCBOR i

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

Constructors

Annotator 

Fields

Instances

Instances details
Applicative Annotator Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.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.Ledger.Binary.Decoding.Annotated

Methods

fmap ∷ (a → b) → Annotator a → Annotator b Source #

(<$) ∷ a → Annotator b → Annotator a Source #

Monad Annotator Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

Methods

(>>=)Annotator a → (a → Annotator b) → Annotator b Source #

(>>)Annotator a → Annotator b → Annotator b Source #

return ∷ a → Annotator a Source #

DecCBOR (Annotator Data) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Annotated

annotatorSliceDecoder 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.

withSliceDecoder 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 

Nested CBOR in CBOR

decodeNestedCborDecCBOR 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.

decodeNestedCborBytesDecoder 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.

Unsafe deserialization

unsafeDeserializeDecCBOR a ⇒ VersionByteString → a Source #

Deserialize a Haskell value from the external binary representation, which have been made using serialize or a matching serialization functionilty in another language that uses CBOR format. Accepts lazy ByteString as input, for strict variant use unsafeDeserialize` instead.

This deserializaer is not safe for these reasons:

  • Throws: DeserialiseFailure if the given external representation is invalid or does not correspond to a value of the expected type.
  • Decoding will not fail when the binary input is not consumed in full.

unsafeDeserialize'DecCBOR a ⇒ VersionByteString → a Source #

Variant of unsafeDeserialize that accepts a strict ByteString as input.

Helpers

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