cardano-data-0.1.0.0: Specialized data for Cardano project
Safe Haskell None
Language Haskell2010

Data.Coders

Description

MemoBytes is an abstration for a datetype that encodes its own seriialization. The idea is to use a newtype around a MemoBytes non-memoizing version. For example: newtype Foo = Foo(MemoBytes NonMemoizingFoo) This way all the instances for Foo (Eq,Show,Ord,ToCBOR,FromCBOR,NoThunks,Generic) can be derived for free.

Synopsis

Documentation

data Decode (w :: Wrapped ) t where Source #

(!>) :: Encode w (a -> t) -> Encode (' Closed r) a -> Encode w t infixl 4 Source #

(<!) :: Decode w1 (a -> t) -> Decode (' Closed w) a -> Decode w1 t infixl 4 Source #

data Density Source #

Some CBOR instances wrap encoding sequences with prefixes and suffixes. I.e. prefix , encode, encode, encode , ... , suffix. There are two kinds of wrapping coders: Nary sums, and Sparsely encoded products. Coders in these classes can only be decoded when they are wrapped by their closing forms Summand and SparseKeyed. In another dimension records can be encoded densely (all their fields serialised) or sparsely (only some of their fields). We use indexes to types to try and mark (and enforce) these distinctions.

Record density (all the fields) vs (some of the fields)

Constructors

Dense
Sparse

data Dual t Source #

Analogous to paired ToCBOR and FromCBOR instances with out freezing out alternate ways to code. Unlike ToCBOR and FromCBOR where there is only one instance per type. There can be multiple Duals with the same type.

Constructors

Dual (t -> Encoding ) ( forall s. Decoder s t)

data Field t where Source #

A Field pairs an update function and a decoder for one field of a Sparse record.

Constructors

Field :: (x -> t -> t) -> ( forall s. Decoder s x) -> Field t

field :: (x -> t -> t) -> Decode (' Closed d) x -> Field t Source #

fieldA :: Applicative ann => (x -> t -> t) -> Decode (' Closed d) x -> Field (ann t) Source #

fieldAA :: Applicative ann => (x -> t -> t) -> Decode (' Closed d) (ann x) -> Field (ann t) Source #

decodeMapNoDuplicates :: Ord a => Decoder s a -> Decoder s b -> Decoder s ( Map a b) Source #

Just like decodeMap , but assumes there are no duplicate keys

dualMaybeAsList :: ( ToCBOR a, FromCBOR a) => Dual ( Maybe a) Source #

Good for encoding (Maybe t) if is another Maybe. Uses more space than dualMaybeAsNull

dualMaybeAsNull :: ( ToCBOR a, FromCBOR a) => Dual ( Maybe a) Source #

Good for encoding (Maybe T) as long as T isn't another Maybe

data Decoder s a Source #

A continuation-based decoder, used for decoding values that were previously encoded using the Codec.CBOR.Encoding module. As Decoder has a Monad instance, you can easily write Decoder s monadically for building your deserialisation logic.

Since: cborg-0.2.0.0

Instances

Instances details
Monad ( Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

Functor ( Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

MonadFail ( Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

Applicative ( Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

data Encoding Source #

An intermediate form used during serialisation, specified as a Monoid . It supports efficient concatenation, and is equivalent to a specialised Endo Tokens type.

It is used for the stage in serialisation where we flatten out the Haskell data structure but it is independent of any specific external binary or text format.

Traditionally, to build any arbitrary Encoding value, you specify larger structures from smaller ones and append the small ones together using mconcat .

Since: cborg-0.2.0.0

mapEncode :: ( ToCBOR k, ToCBOR v) => Map k v -> Encode (' Closed ' Dense ) ( Map k v) Source #

(mapEncode x) is self-documenting, correct way to encode Map. use mapDecode as its dual

mapDecode :: ( Ord k, FromCBOR k, FromCBOR v) => Decode (' Closed ' Dense ) ( Map k v) Source #

(mapDecode) is the Dual for (mapEncode x)

vMapEncode :: ( Vector kv k, Vector vv v, ToCBOR k, ToCBOR v) => VMap kv vv k v -> Encode (' Closed ' Dense ) ( VMap kv vv k v) Source #

(vMapEncode x) is self-documenting, correct way to encode VMap. use vMapDecode as its dual

vMapDecode :: ( Vector kv k, Vector vv v, Ord k, FromCBOR k, FromCBOR v) => Decode (' Closed ' Dense ) ( VMap kv vv k v) Source #

(vMapDecode) is the Dual for (vMapEncode x)

setEncode :: ToCBOR v => Set v -> Encode (' Closed ' Dense ) ( Set v) Source #

(setEncode x) is self-documenting (E encodeFoldable x), use setDecode as its dual

setDecode :: ( Ord v, FromCBOR v) => Decode (' Closed ' Dense ) ( Set v) Source #

(setDecode) is the Dual for (setEncode x)

listEncode :: ToCBOR v => [v] -> Encode (' Closed ' Dense ) [v] Source #

(listEncode x) is self-documenting (E encodeFoldable x), use listDecode as its dual

listDecode :: FromCBOR v => Decode (' Closed ' Dense ) [v] Source #

(listDecode) is the Dual for (listEncode x)

Utility functions

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

Convert a Buildable error into a cborg decoder error