Copyright | (c) Duncan Coutts 2015-2017 |
---|---|
License | BSD3-style (see LICENSE.txt) |
Maintainer | duncan@community.haskell.org |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
Codec.Serialise.Class
Contents
Description
The
class allows you to encode a given type into a
CBOR object, or decode a CBOR object into the user-specified type.
Serialise
Synopsis
-
class
Serialise
a
where
- encode :: a -> Encoding
- decode :: Decoder s a
- encodeList :: [a] -> Encoding
- decodeList :: Decoder s [a]
- class GSerialiseEncode f where
- class GSerialiseDecode f where
- class GSerialiseProd f where
- class GSerialiseSum f where
- encodeVector :: ( Serialise a, Vector v a) => v a -> Encoding
- decodeVector :: ( Serialise a, Vector v a) => Decoder s (v a)
- encodeContainerSkel :: ( Word -> Encoding ) -> (container -> Int ) -> (accumFunc -> Encoding -> container -> Encoding ) -> accumFunc -> container -> Encoding
- encodeMapSkel :: ( Serialise k, Serialise v) => (m -> Int ) -> ((k -> v -> Encoding -> Encoding ) -> Encoding -> m -> Encoding ) -> m -> Encoding
- decodeMapSkel :: ( Serialise k, Serialise v) => ([(k, v)] -> m) -> Decoder s m
The Serialise class
class Serialise a where Source #
Types that are instances of the
class allow values
to be quickly encoded or decoded directly to a CBOR representation,
for object transmission or storage.
Serialise
Since: 0.2.0.0
Minimal complete definition
Nothing
Methods
encode :: a -> Encoding Source #
Definition for encoding a given type into a binary
representation, using the
Encoding
.
Monoid
Since: 0.2.0.0
decode :: Decoder s a Source #
Definition of a given
for a type.
Decoder
Since: 0.2.0.0
encodeList :: [a] -> Encoding Source #
Utility to support specialised encoding for some list type -
used for
/
Char
instances in this package.
String
Since: 0.2.0.0
decodeList :: Decoder s [a] Source #
Instances
class GSerialiseEncode f where Source #
Since: 0.2.0.0
Instances
GSerialiseEncode ( U1 :: k -> Type ) Source # |
Since: 0.2.0.0 |
GSerialiseEncode ( V1 :: k -> Type ) Source # |
Since: 0.2.0.0 |
Serialise a => GSerialiseEncode ( K1 i a :: k -> Type ) Source # |
Since: 0.2.0.0 |
( GSerialiseProd f, GSerialiseProd g) => GSerialiseEncode (f :*: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
( GSerialiseSum f, GSerialiseSum g) => GSerialiseEncode (f :+: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
GSerialiseEncode a => GSerialiseEncode ( M1 i c a :: k -> Type ) Source # |
Since: 0.2.0.0 |
class GSerialiseDecode f where Source #
Since: 0.2.0.0
Instances
GSerialiseDecode ( U1 :: k -> Type ) Source # |
Since: 0.2.0.0 |
GSerialiseDecode ( V1 :: k -> Type ) Source # |
Since: 0.2.0.0 |
Serialise a => GSerialiseDecode ( K1 i a :: k -> Type ) Source # |
Since: 0.2.0.0 |
( GSerialiseProd f, GSerialiseProd g) => GSerialiseDecode (f :*: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
( GSerialiseSum f, GSerialiseSum g) => GSerialiseDecode (f :+: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
GSerialiseDecode a => GSerialiseDecode ( M1 i c a :: k -> Type ) Source # |
Since: 0.2.0.0 |
class GSerialiseProd f where Source #
Serialization of product types
Methods
nFields :: Proxy f -> Word Source #
Number of fields in product type
encodeSeq :: f a -> Encoding Source #
Encode fields sequentially without writing header
gdecodeSeq :: Decoder s (f a) Source #
Decode fields sequentially without reading header
Instances
GSerialiseProd ( U1 :: k -> Type ) Source # |
Since: 0.2.0.0 |
Serialise a => GSerialiseProd ( K1 i a :: k -> Type ) Source # |
Since: 0.2.0.0 |
( GSerialiseProd f, GSerialiseProd g) => GSerialiseProd (f :*: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
(i ~ S , GSerialiseProd f) => GSerialiseProd ( M1 i c f :: k -> Type ) Source # |
Since: 0.2.0.0 |
class GSerialiseSum f where Source #
Serialization of sum types
Since: 0.2.0.0
Methods
conNumber :: f a -> Word Source #
Number of constructor of given value
numOfFields :: f a -> Word Source #
Number of fields of given value
encodeSum :: f a -> Encoding Source #
Encode field
decodeSum :: Word -> Decoder s (f a) Source #
Decode field
nConstructors :: Proxy f -> Word Source #
Number of constructors
fieldsForCon :: Proxy f -> Word -> Decoder s Word Source #
Number of fields for given constructor number
Instances
( GSerialiseSum f, GSerialiseSum g) => GSerialiseSum (f :+: g :: k -> Type ) Source # |
Since: 0.2.0.0 |
Defined in Codec.Serialise.Class Methods conNumber :: forall (a :: k0). (f :+: g) a -> Word Source # numOfFields :: forall (a :: k0). (f :+: g) a -> Word Source # encodeSum :: forall (a :: k0). (f :+: g) a -> Encoding Source # decodeSum :: forall s (a :: k0). Word -> Decoder s ((f :+: g) a) Source # nConstructors :: Proxy (f :+: g) -> Word Source # fieldsForCon :: Proxy (f :+: g) -> Word -> Decoder s Word Source # |
|
(i ~ C , GSerialiseProd f) => GSerialiseSum ( M1 i c f :: k -> Type ) Source # |
Since: 0.2.0.0 |
Defined in Codec.Serialise.Class Methods conNumber :: forall (a :: k0). M1 i c f a -> Word Source # numOfFields :: forall (a :: k0). M1 i c f a -> Word Source # encodeSum :: forall (a :: k0). M1 i c f a -> Encoding Source # decodeSum :: forall s (a :: k0). Word -> Decoder s ( M1 i c f a) Source # nConstructors :: Proxy ( M1 i c f) -> Word Source # fieldsForCon :: Proxy ( M1 i c f) -> Word -> Decoder s Word Source # |
encodeVector :: ( Serialise a, Vector v a) => v a -> Encoding Source #
Generic encoder for vectors. Its intended use is to allow easy
definition of
Serialise
instances for custom vector
Since: 0.2.0.0
decodeVector :: ( Serialise a, Vector v a) => Decoder s (v a) Source #
Generic decoder for vectors. Its intended use is to allow easy
definition of
Serialise
instances for custom vector
Since: 0.2.0.0
Arguments
:: ( Word -> Encoding ) |
encoder of the length |
-> (container -> Int ) |
length |
-> (accumFunc -> Encoding -> container -> Encoding ) |
foldr |
-> accumFunc | |
-> container | |
-> Encoding |
Patch functions together to obtain an
Encoding
for a container.