small-steps-0.1.0.0: Small step semantics
Safe HaskellNone
LanguageHaskell2010

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 Encode (w :: Wrapped) t where Source #

Constructors

Rec :: t -> Encode ('Closed 'Dense) t 
Sum :: t -> Word -> Encode 'Open t 
Keyed :: t -> Encode ('Closed 'Sparse) t 
To :: ToCBOR a => a -> Encode ('Closed 'Dense) a 
E :: (t -> Encoding) -> t -> Encode ('Closed 'Dense) t 
ED :: Dual t -> t -> Encode ('Closed 'Dense) t 
OmitC :: t -> Encode w t 
Omit :: (t -> Bool) -> Encode ('Closed 'Sparse) t -> Encode ('Closed 'Sparse) t 
Key :: Word -> Encode ('Closed 'Dense) t -> Encode ('Closed 'Sparse) t 
ApplyE :: Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t 

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

Constructors

Summands :: String -> (Word -> Decode 'Open t) -> Decode ('Closed 'Dense) t 
SparseKeyed :: Typeable t => String -> t -> (Word -> Field t) -> [(Word, String)] -> Decode ('Closed 'Dense) t 
SumD :: t -> Decode 'Open t 
RecD :: t -> Decode ('Closed 'Dense) t 
KeyedD :: t -> Decode ('Closed 'Sparse) t 
From :: FromCBOR t => Decode w t 
D :: (forall s. Decoder s t) -> Decode ('Closed 'Dense) t 
ApplyD :: Decode w1 (a -> t) -> Decode ('Closed d) a -> Decode w1 t 
Invalid :: Word -> Decode w t 
Map :: (a -> b) -> Decode w a -> Decode w b 
DD :: Dual t -> Decode ('Closed 'Dense) t 
Emit :: t -> Decode w t 
Ann :: Decode w t -> Decode w (Annotator t) 
ApplyAnn :: Decode w1 (Annotator (a -> t)) -> Decode ('Closed d) (Annotator a) -> Decode w1 (Annotator t) 

Instances

Instances details
Functor (Decode w) Source # 
Instance details

Defined in Data.Coders

Methods

fmap :: (a -> b) -> Decode w a -> Decode w b #

(<$) :: a -> Decode w b -> Decode w a #

Applicative (Decode ('Closed d)) Source # 
Instance details

Defined in Data.Coders

Methods

pure :: a -> Decode ('Closed d) a #

(<*>) :: Decode ('Closed d) (a -> b) -> Decode ('Closed d) a -> Decode ('Closed d) b #

liftA2 :: (a -> b -> c) -> Decode ('Closed d) a -> Decode ('Closed d) b -> Decode ('Closed d) c #

(*>) :: Decode ('Closed d) a -> Decode ('Closed d) b -> Decode ('Closed d) b #

(<*) :: Decode ('Closed d) a -> Decode ('Closed d) b -> Decode ('Closed d) a #

(!>) :: 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 #

(<*!) :: Decode w1 (Annotator (a -> t)) -> Decode ('Closed d) (Annotator a) -> Decode w1 (Annotator 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 Wrapped where Source #

Constructors

Open :: Wrapped 
Closed :: Density -> Wrapped 

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.

Constructors

Annotator 

Instances

Instances details
Monad Annotator 
Instance details

Defined in Cardano.Binary.Annotated

Methods

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

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

return :: a -> Annotator a #

Functor Annotator 
Instance details

Defined in Cardano.Binary.Annotated

Methods

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

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

Applicative Annotator 
Instance details

Defined in Cardano.Binary.Annotated

Methods

pure :: a -> Annotator a #

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

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

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

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

(Typeable t, FromCBOR (Annotator t)) => FromCBOR (Annotator (MemoBytes t)) Source # 
Instance details

Defined in Data.MemoBytes

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 #

decode :: Decode w t -> Decoder s t Source #

runE :: Encode w t -> t Source #

decodeSet :: Ord a => Decoder s a -> Decoder s (Set a) Source #

decodeRecordNamed :: Text -> (a -> Int) -> Decoder s a -> Decoder s a Source #

dualList :: (ToCBOR a, FromCBOR a) => Dual [a] Source #

dualSet :: (Ord a, ToCBOR a, FromCBOR a) => Dual (Set a) Source #

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

to :: (ToCBOR t, FromCBOR t) => t -> Encode ('Closed 'Dense) t Source #

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 Decoders 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

Methods

(>>=) :: Decoder s a -> (a -> Decoder s b) -> Decoder s b #

(>>) :: Decoder s a -> Decoder s b -> Decoder s b #

return :: a -> Decoder s a #

Functor (Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

Methods

fmap :: (a -> b) -> Decoder s a -> Decoder s b #

(<$) :: a -> Decoder s b -> Decoder s a #

MonadFail (Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

Methods

fail :: String -> Decoder s a #

Applicative (Decoder s)

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Decoding

Methods

pure :: a -> Decoder s a #

(<*>) :: Decoder s (a -> b) -> Decoder s a -> Decoder s b #

liftA2 :: (a -> b -> c) -> Decoder s a -> Decoder s b -> Decoder s c #

(*>) :: Decoder s a -> Decoder s b -> Decoder s b #

(<*) :: Decoder s a -> Decoder s b -> Decoder s a #

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

Instances

Instances details
Show Encoding 
Instance details

Defined in Codec.CBOR.Encoding

Semigroup Encoding

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Encoding

Monoid Encoding

Since: cborg-0.2.0.0

Instance details

Defined in Codec.CBOR.Encoding

decodeSparse :: Typeable a => String -> a -> (Word -> Field a) -> [(Word, String)] -> Decoder s a Source #