Data.Serialize

cereal-0.5.8.2: A binary serialization library

Copyright | Lennart Kolmodin Galois Inc. 2009
License | BSD3-style (see LICENSE)
Maintainer | Trevor Elliott <trevor@galois.com>
Stability |
Portability |
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Serialize

Contents

- The Serialize class
- Serialize serialisation
- Generic deriving

Description

Synopsis

- class Serialize t where
  - put :: Putter t
  - get :: Get t
- encode :: Serialize a => a -> ByteString
- encodeLazy :: Serialize a => a -> ByteString
- decode :: Serialize a => ByteString -> Either String a
- decodeLazy :: Serialize a => ByteString -> Either String a
- expect :: (Eq a, Serialize a) => a -> Get a
- module Data.Serialize.Get
- module Data.Serialize.Put
- module Data.Serialize.IEEE754
- class GSerializePut f where
  - gPut :: Putter (f a)
- class GSerializeGet f where
  - gGet :: Get (f a)

# The Serialize class

class Serialize t where #

If your compiler has support for the `DeriveGeneric` and `DefaultSignatures` language extensions (`ghc >= 7.2.1`), the `put` and `get` methods will have default generic implementations.

To use this option, simply add a `deriving `Generic`` clause to your datatype and declare a `Serialize` instance for it without giving a definition for `put` and `get`.

Minimal complete definition

Nothing

Methods

put :: Putter t #

Encode a value in the Put monad.

default put :: (Generic t, GSerializePut (Rep t)) => Putter t #

get :: Get t #

Decode a value in the Get monad

default get :: (Generic t, GSerializeGet (Rep t)) => Get t #

#### Instances

Instances details

Serialize All # |
Instance details Defined in Data.Serialize Methods put :: Putter All # get :: Get All #
Serialize Any # |
Instance details Defined in Data.Serialize Methods put :: Putter Any # get :: Get Any #
Serialize Int16 # |
Instance details Defined in Data.Serialize Methods put :: Putter Int16 # get :: Get Int16 #
Serialize Int32 # |
Instance details Defined in Data.Serialize Methods put :: Putter Int32 # get :: Get Int32 #
Serialize Int64 # |
Instance details Defined in Data.Serialize Methods put :: Putter Int64 # get :: Get Int64 #
Serialize Int8 # |
Instance details Defined in Data.Serialize Methods put :: Putter Int8 # get :: Get Int8 #
Serialize Word16 # |
Instance details Defined in Data.Serialize Methods put :: Putter Word16 # get :: Get Word16 #
Serialize Word32 # |
Instance details Defined in Data.Serialize Methods put :: Putter Word32 # get :: Get Word32 #
Serialize Word64 # |
Instance details Defined in Data.Serialize Methods put :: Putter Word64 # get :: Get Word64 #
Serialize Word8 # |
Instance details Defined in Data.Serialize Methods put :: Putter Word8 # get :: Get Word8 #
Serialize ByteString # |
Instance details Defined in Data.Serialize Methods put :: Putter ByteString # get :: Get ByteString #
Serialize ByteString # |
Instance details Defined in Data.Serialize Methods put :: Putter ByteString # get :: Get ByteString #
Serialize ShortByteString # |
Instance details Defined in Data.Serialize Methods put :: Putter ShortByteString # get :: Get ShortByteString #
Serialize IntSet # |
Instance details Defined in Data.Serialize Methods put :: Putter IntSet # get :: Get IntSet #
Serialize Ordering # |
Instance details Defined in Data.Serialize Methods put :: Putter Ordering # get :: Get Ordering #
Serialize Integer # |
Instance details Defined in Data.Serialize Methods put :: Putter Integer # get :: Get Integer #
Serialize Natural # |
Instance details Defined in Data.Serialize Methods put :: Putter Natural # get :: Get Natural #
Serialize () # |
Instance details Defined in Data.Serialize Methods put :: Putter () # get :: Get () #
Serialize Bool # |
Instance details Defined in Data.Serialize Methods put :: Putter Bool # get :: Get Bool #
Serialize Char # |
Instance details Defined in Data.Serialize Methods put :: Putter Char # get :: Get Char #
Serialize Double # |
Instance details Defined in Data.Serialize Methods put :: Putter Double # get :: Get Double #
Serialize Float # |
Instance details Defined in Data.Serialize Methods put :: Putter Float # get :: Get Float #
Serialize Int # |
Instance details Defined in Data.Serialize Methods put :: Putter Int # get :: Get Int #
Serialize Word # |
Instance details Defined in Data.Serialize Methods put :: Putter Word # get :: Get Word #
Serialize a => Serialize (First a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (First a) # get :: Get (First a) #
Serialize a => Serialize (Last a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Last a) # get :: Get (Last a) #
Serialize a => Serialize (Dual a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Dual a) # get :: Get (Dual a) #
Serialize a => Serialize (Product a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Product a) # get :: Get (Product a) #
Serialize a => Serialize (Sum a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Sum a) # get :: Get (Sum a) #
(Serialize a, Integral a) => Serialize (Ratio a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Ratio a) # get :: Get (Ratio a) #
Serialize e => Serialize (IntMap e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (IntMap e) # get :: Get (IntMap e) #
Serialize e => Serialize (Seq e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Seq e) # get :: Get (Seq e) #
(Ord a, Serialize a) => Serialize (Set a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Set a) # get :: Get (Set a) #
Serialize e => Serialize (Tree e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Tree e) # get :: Get (Tree e) #
Serialize a => Serialize (Maybe a) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Maybe a) # get :: Get (Maybe a) #
Serialize a => Serialize [a] # |
Instance details Defined in Data.Serialize Methods put :: Putter [a] # get :: Get [a] #
(Serialize i, Ix i, Serialize e, IArray UArray e) => Serialize (UArray i e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (UArray i e) # get :: Get (UArray i e) #
(Serialize a, Serialize b) => Serialize (Either a b) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Either a b) # get :: Get (Either a b) #
(Serialize i, Ix i, Serialize e) => Serialize (Array i e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Array i e) # get :: Get (Array i e) #
(Ord k, Serialize k, Serialize e) => Serialize (Map k e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (Map k e) # get :: Get (Map k e) #
(Serialize a, Serialize b) => Serialize (a, b) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b) # get :: Get (a, b) #
(Serialize a, Serialize b, Serialize c) => Serialize (a, b, c) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c) # get :: Get (a, b, c) #
(Serialize a, Serialize b, Serialize c, Serialize d) => Serialize (a, b, c, d) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d) # get :: Get (a, b, c, d) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e) => Serialize (a, b, c, d, e) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e) # get :: Get (a, b, c, d, e) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e, Serialize f) => Serialize (a, b, c, d, e, f) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e, f) # get :: Get (a, b, c, d, e, f) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e, Serialize f, Serialize g) => Serialize (a, b, c, d, e, f, g) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e, f, g) # get :: Get (a, b, c, d, e, f, g) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e, Serialize f, Serialize g, Serialize h) => Serialize (a, b, c, d, e, f, g, h) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e, f, g, h) # get :: Get (a, b, c, d, e, f, g, h) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e, Serialize f, Serialize g, Serialize h, Serialize i) => Serialize (a, b, c, d, e, f, g, h, i) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e, f, g, h, i) # get :: Get (a, b, c, d, e, f, g, h, i) #
(Serialize a, Serialize b, Serialize c, Serialize d, Serialize e, Serialize f, Serialize g, Serialize h, Serialize i, Serialize j) => Serialize (a, b, c, d, e, f, g, h, i, j) # |
Instance details Defined in Data.Serialize Methods put :: Putter (a, b, c, d, e, f, g, h, i, j) # get :: Get (a, b, c, d, e, f, g, h, i, j) #

# Serialize serialisation

encode :: Serialize a => a -> ByteString #

Encode a value using binary serialization to a strict ByteString.

encodeLazy :: Serialize a => a -> ByteString #

Encode a value using binary serialization to a lazy ByteString.

decode :: Serialize a => ByteString -> Either String a #

Decode a value from a strict ByteString, reconstructing the original structure.

decodeLazy :: Serialize a => ByteString -> Either String a #

Decode a value from a lazy ByteString, reconstructing the original structure.

expect :: (Eq a, Serialize a) => a -> Get a #

Perform an action, failing if the read result does not match the argument provided.

module Data.Serialize.Get

module Data.Serialize.Put

module Data.Serialize.IEEE754

# Generic deriving

class GSerializePut f where #

Methods

gPut :: Putter (f a) #

#### Instances

Instances details

GSerializePut (U1 :: Type -> Type) # |
Instance details Defined in Data.Serialize Methods gPut :: Putter (U1 a) #
GSerializePut (V1 :: Type -> Type) # | Always fails to serialize
Instance details Defined in Data.Serialize Methods gPut :: Putter (V1 a) #
(GSerializePut a, GSerializePut b) => GSerializePut (a :*: b) # |
Instance details Defined in Data.Serialize Methods gPut :: Putter ((a :*: b) a0) #
(PutSum a, PutSum b, SumSize a, SumSize b) => GSerializePut (a :+: b) # |
Instance details Defined in Data.Serialize Methods gPut :: Putter ((a :+: b) a0) #
Serialize a => GSerializePut (K1 i a :: Type -> Type) # |
Instance details Defined in Data.Serialize Methods gPut :: Putter (K1 i a a0) #
GSerializePut a => GSerializePut (M1 i c a) # |
Instance details Defined in Data.Serialize Methods gPut :: Putter (M1 i c a a0) #

class GSerializeGet f where #

Methods

gGet :: Get (f a) #

#### Instances

Instances details

GSerializeGet (U1 :: Type -> Type) # |
Instance details Defined in Data.Serialize Methods gGet :: Get (U1 a) #
GSerializeGet (V1 :: Type -> Type) # | Always fails to deserialize
Instance details Defined in Data.Serialize Methods gGet :: Get (V1 a) #
(GSerializeGet a, GSerializeGet b) => GSerializeGet (a :*: b) # |
Instance details Defined in Data.Serialize Methods gGet :: Get ((a :*: b) a0) #
(GetSum a, GetSum b, SumSize a, SumSize b) => GSerializeGet (a :+: b) # |
Instance details Defined in Data.Serialize Methods gGet :: Get ((a :+: b) a0) #
Serialize a => GSerializeGet (K1 i a :: Type -> Type) # |
Instance details Defined in Data.Serialize Methods gGet :: Get (K1 i a a0) #
GSerializeGet a => GSerializeGet (M1 i c a) # |
Instance details Defined in Data.Serialize Methods gGet :: Get (M1 i c a a0) #