Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
-
data
Encode
(w ::
Wrapped
) t
where
- 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
- MapE :: (a -> b) -> Encode w a -> Encode w b
- ED :: Dual t -> t -> Encode (' Closed ' Dense ) t
- OmitC :: t -> Encode w t
- Tag :: Word -> Encode (' Closed x) t -> Encode (' Closed x) 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
- 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
- TagD :: Word -> Decode (' Closed x) t -> Decode (' Closed x) 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)
- ApplyErr :: Decode w1 (a -> Either String t) -> Decode (' Closed d) a -> Decode w1 t
- (!>) :: Encode w (a -> t) -> Encode (' Closed r) a -> Encode w t
- (<!) :: Decode w1 (a -> t) -> Decode (' Closed w) a -> Decode w1 t
- (<*!) :: Decode w1 ( Annotator (a -> t)) -> Decode (' Closed d) ( Annotator a) -> Decode w1 ( Annotator t)
- (<?) :: Decode w1 (a -> Either String t) -> Decode (' Closed d) a -> Decode w1 t
- data Density
- data Wrapped where
-
newtype
Annotator
a =
Annotator
{
- runAnnotator :: FullByteString -> a
- data Dual t = Dual (t -> Encoding ) ( forall s. Decoder s t)
- data Field t where
- ofield :: ( StrictMaybe x -> t -> t) -> Decode (' Closed d) x -> Field t
- invalidField :: forall t. Word -> Field t
- field :: (x -> t -> t) -> Decode (' Closed d) x -> Field t
- fieldA :: Applicative ann => (x -> t -> t) -> Decode (' Closed d) x -> Field (ann t)
- fieldAA :: Applicative ann => (x -> t -> t) -> Decode (' Closed d) (ann x) -> Field (ann t)
- encode :: Encode w t -> Encoding
- decode :: Decode w t -> Decoder s t
- runE :: Encode w t -> t
- decodeList :: Decoder s a -> Decoder s [a]
- decodePair :: Decoder s a -> Decoder s b -> Decoder s (a, b)
- decodeSeq :: Decoder s a -> Decoder s ( Seq a)
- decodeStrictSeq :: Decoder s a -> Decoder s ( StrictSeq a)
- decodeSet :: Ord a => Decoder s a -> Decoder s ( Set a)
- decodeAnnSet :: Ord t => Decoder s ( Annotator t) -> Decoder s ( Annotator ( Set t))
- decodeRecordNamed :: Text -> (a -> Int ) -> Decoder s a -> Decoder s a
- decodeRecordNamedT :: ( MonadTrans m, Monad (m ( Decoder s))) => Text -> (a -> Int ) -> m ( Decoder s) a -> m ( Decoder s) a
- decodeRecordSum :: String -> ( Word -> Decoder s ( Int , a)) -> Decoder s a
- invalidKey :: Word -> Decoder s a
- unusedRequiredKeys :: Set Word -> [( Word , String )] -> String -> Decoder s a
- duplicateKey :: String -> Word -> Decoder s a
- wrapCBORArray :: Word -> Encoding -> Encoding
- encodePair :: (a -> Encoding ) -> (b -> Encoding ) -> (a, b) -> Encoding
- encodeFoldable :: ( ToCBOR a, Foldable f) => f a -> Encoding
- encodeFoldableAsDefinite :: ( ToCBOR a, Foldable f) => f a -> Encoding
- encodeFoldableAsIndefinite :: ( ToCBOR a, Foldable f) => f a -> Encoding
- encodeFoldableMapPairs :: ( ToCBOR a, ToCBOR b, Foldable f) => f (a, b) -> Encoding
- decodeCollectionWithLen :: Decoder s ( Maybe Int ) -> Decoder s a -> Decoder s ( Int , [a])
- decodeCollection :: Decoder s ( Maybe Int ) -> Decoder s a -> Decoder s [a]
- encodeFoldableEncoder :: Foldable f => (a -> Encoding ) -> f a -> Encoding
- encodeMap :: (a -> Encoding ) -> (b -> Encoding ) -> Map a b -> Encoding
- encodeVMap :: ( Vector vk k, Vector vv v) => (k -> Encoding ) -> (v -> Encoding ) -> VMap vk vv k v -> Encoding
- wrapCBORMap :: Word -> Encoding -> Encoding
- decodeMap :: Ord a => Decoder s a -> Decoder s b -> Decoder s ( Map a b)
- decodeVMap :: ( Vector kv k, Vector vv v, Ord k) => Decoder s k -> Decoder s v -> Decoder s ( VMap kv vv k v)
- decodeMapNoDuplicates :: Ord a => Decoder s a -> Decoder s b -> Decoder s ( Map a b)
- decodeMapByKey :: ( IsList t, Item t ~ (k, v)) => Decoder s k -> (k -> Decoder s v) -> Decoder s t
- decodeMapContents :: Decoder s a -> Decoder s [a]
- decodeMapTraverse :: ( Ord a, Applicative t) => Decoder s (t a) -> Decoder s (t b) -> Decoder s (t ( Map a b))
- decodeMapContentsTraverse :: Applicative t => Decoder s (t a) -> Decoder s (t b) -> Decoder s (t [(a, b)])
- dualList :: ( ToCBOR a, FromCBOR a) => Dual [a]
- dualSeq :: ( ToCBOR a, FromCBOR a) => Dual ( Seq a)
- dualSet :: ( Ord a, ToCBOR a, FromCBOR a) => Dual ( Set a)
- dualMaybeAsList :: ( ToCBOR a, FromCBOR a) => Dual ( Maybe a)
- dualMaybeAsNull :: ( ToCBOR a, FromCBOR a) => Dual ( Maybe a)
- dualText :: Dual Text
- dualStrictSeq :: ( ToCBOR a, FromCBOR a) => Dual ( StrictSeq a)
- dualCBOR :: ( ToCBOR a, FromCBOR a) => Dual a
- to :: ( ToCBOR t, FromCBOR t) => t -> Encode (' Closed ' Dense ) t
- from :: ( ToCBOR t, FromCBOR t) => Decode (' Closed ' Dense ) t
- data Decoder s a
- data Encoding
- encodeNullMaybe :: (a -> Encoding ) -> Maybe a -> Encoding
- encodeKeyedStrictMaybeWith :: Word -> (a -> Encoding ) -> StrictMaybe a -> Encode (' Closed ' Sparse ) ( StrictMaybe a)
- encodeKeyedStrictMaybe :: ToCBOR a => Word -> StrictMaybe a -> Encode (' Closed ' Sparse ) ( StrictMaybe a)
- decodeNullMaybe :: Decoder s a -> Decoder s ( Maybe a)
- decodeSparse :: Typeable a => String -> a -> ( Word -> Field a) -> [( Word , String )] -> Decoder s a
- mapEncode :: ( ToCBOR k, ToCBOR v) => Map k v -> Encode (' Closed ' Dense ) ( Map k v)
- mapDecode :: ( Ord k, FromCBOR k, FromCBOR v) => Decode (' Closed ' Dense ) ( Map k v)
- mapDecodeA :: Ord k => Decode (' Closed ' Dense ) ( Annotator k) -> Decode (' Closed ' Dense ) ( Annotator v) -> Decode (' Closed ' Dense ) ( Annotator ( Map k v))
- vMapEncode :: ( Vector kv k, Vector vv v, ToCBOR k, ToCBOR v) => VMap kv vv k v -> Encode (' Closed ' Dense ) ( VMap kv vv k v)
- vMapDecode :: ( Vector kv k, Vector vv v, Ord k, FromCBOR k, FromCBOR v) => Decode (' Closed ' Dense ) ( VMap kv vv k v)
- setEncode :: ToCBOR v => Set v -> Encode (' Closed ' Dense ) ( Set v)
- setDecode :: ( Ord v, FromCBOR v) => Decode (' Closed ' Dense ) ( Set v)
- setDecodeA :: Ord x => Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator ( Set x))
- listEncode :: ToCBOR v => [v] -> Encode (' Closed ' Dense ) [v]
- listDecode :: FromCBOR v => Decode (' Closed ' Dense ) [v]
- listDecodeA :: Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator [x])
- pairDecodeA :: Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator y) -> Decode (' Closed ' Dense ) ( Annotator (x, y))
- cborError :: Buildable e => e -> Decoder s a
Documentation
data Encode (w :: Wrapped ) t where Source #
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 | |
MapE :: (a -> b) -> Encode w a -> Encode w b | |
ED :: Dual t -> t -> Encode (' Closed ' Dense ) t | |
OmitC :: t -> Encode w t | |
Tag :: Word -> Encode (' Closed x) t -> Encode (' Closed x) 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 #
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 | |
TagD :: Word -> Decode (' Closed x) t -> Decode (' Closed x) 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) | |
ApplyErr :: Decode w1 (a -> Either String t) -> Decode (' Closed d) a -> Decode w1 t |
Instances
Functor ( Decode w) Source # | |
Applicative ( Decode (' Closed d)) Source # | |
Defined in Data.Coders pure :: a -> Decode (' Closed d) a Source # (<*>) :: Decode (' Closed d) (a -> b) -> Decode (' Closed d) a -> Decode (' Closed d) b Source # liftA2 :: (a -> b -> c) -> Decode (' Closed d) a -> Decode (' Closed d) b -> Decode (' Closed d) c Source # (*>) :: Decode (' Closed d) a -> Decode (' Closed d) b -> Decode (' Closed d) b Source # (<*) :: Decode (' Closed d) a -> Decode (' Closed d) b -> Decode (' Closed d) a Source # |
(<*!) :: Decode w1 ( Annotator (a -> t)) -> Decode (' Closed d) ( Annotator a) -> Decode w1 ( Annotator t) infixl 4 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)
A value of type `Annotator a` is one that needs access to the entire | bytestring used during decoding to finish construction.
Annotator | |
|
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.
A Field pairs an update function and a decoder for one field of a Sparse record.
invalidField :: forall t. Word -> Field t Source #
fieldAA :: Applicative ann => (x -> t -> t) -> Decode (' Closed d) (ann x) -> Field (ann t) Source #
decodeList :: 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 #
invalidKey :: Word -> Decoder s a Source #
decodeCollectionWithLen :: Decoder s ( Maybe Int ) -> Decoder s a -> Decoder s ( Int , [a]) Source #
encodeVMap :: ( Vector vk k, Vector vv v) => (k -> Encoding ) -> (v -> Encoding ) -> VMap vk vv k v -> Encoding Source #
decodeVMap :: ( Vector kv k, Vector vv v, Ord k) => Decoder s k -> Decoder s v -> Decoder s ( VMap kv vv k v) 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
decodeMapByKey :: ( IsList t, Item t ~ (k, v)) => Decoder s k -> (k -> Decoder s v) -> Decoder s t Source #
decodeMapContents :: Decoder s a -> Decoder s [a] Source #
decodeMapTraverse :: ( Ord a, Applicative t) => Decoder s (t a) -> Decoder s (t b) -> Decoder s (t ( Map a b)) Source #
decodeMapContentsTraverse :: Applicative t => Decoder s (t a) -> Decoder s (t b) -> Decoder s (t [(a, b)]) 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
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
Monad ( Decoder s) |
Since: cborg-0.2.0.0 |
Functor ( Decoder s) |
Since: cborg-0.2.0.0 |
MonadFail ( Decoder s) |
Since: cborg-0.2.0.0 |
Applicative ( Decoder s) |
Since: cborg-0.2.0.0 |
Defined in Codec.CBOR.Decoding |
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
encodeKeyedStrictMaybeWith :: Word -> (a -> Encoding ) -> StrictMaybe a -> Encode (' Closed ' Sparse ) ( StrictMaybe a) Source #
encodeKeyedStrictMaybe :: ToCBOR a => Word -> StrictMaybe a -> Encode (' Closed ' Sparse ) ( StrictMaybe a) Source #
decodeSparse :: Typeable a => String -> a -> ( Word -> Field a) -> [( Word , String )] -> Decoder s a Source #
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)
mapDecodeA :: Ord k => Decode (' Closed ' Dense ) ( Annotator k) -> Decode (' Closed ' Dense ) ( Annotator v) -> Decode (' Closed ' Dense ) ( Annotator ( Map k v)) Source #
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)
setDecodeA :: Ord x => Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator ( Set x)) Source #
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)
listDecodeA :: Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator [x]) Source #
pairDecodeA :: Decode (' Closed ' Dense ) ( Annotator x) -> Decode (' Closed ' Dense ) ( Annotator y) -> Decode (' Closed ' Dense ) ( Annotator (x, y)) Source #