Data.Serialize

cereal-0.5.4.0: 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 | None
Language | Haskell2010

Data.Serialize

Contents

- The Serialize class
- Serialize serialisation
- Generic deriving

Description

Synopsis

- class Serialize t where
- 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
- class GSerializeGet f where

# 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`.

Methods

put :: Putter t #

Encode a value in the Put monad.

get :: Get t #

Decode a value in the Get monad

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

Encode a value in the Put monad.

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

Decode a value in the Get monad

Instances

Serialize Bool # |
Methods put :: Putter Bool # get :: Get Bool #
Serialize Char # |
Methods put :: Putter Char # get :: Get Char #
Serialize Double # |
Methods put :: Putter Double # get :: Get Double #
Serialize Float # |
Methods put :: Putter Float # get :: Get Float #
Serialize Int # |
Methods put :: Putter Int # get :: Get Int #
Serialize Int8 # |
Methods put :: Putter Int8 # get :: Get Int8 #
Serialize Int16 # |
Methods put :: Putter Int16 # get :: Get Int16 #
Serialize Int32 # |
Methods put :: Putter Int32 # get :: Get Int32 #
Serialize Int64 # |
Methods put :: Putter Int64 # get :: Get Int64 #
Serialize Integer # |
Methods put :: Putter Integer # get :: Get Integer #
Serialize Ordering # |
Methods put :: Putter Ordering # get :: Get Ordering #
Serialize Word # |
Methods put :: Putter Word # get :: Get Word #
Serialize Word8 # |
Methods put :: Putter Word8 # get :: Get Word8 #
Serialize Word16 # |
Methods put :: Putter Word16 # get :: Get Word16 #
Serialize Word32 # |
Methods put :: Putter Word32 # get :: Get Word32 #
Serialize Word64 # |
Methods put :: Putter Word64 # get :: Get Word64 #
Serialize () # |
Methods put :: Putter () # get :: Get () #
Serialize Natural # |
Methods put :: Putter Natural # get :: Get Natural #
Serialize All # |
Methods put :: Putter All # get :: Get All #
Serialize Any # |
Methods put :: Putter Any # get :: Get Any #
Serialize ByteString # |
Methods put :: Putter ByteString # get :: Get ByteString #
Serialize ByteString # |
Methods put :: Putter ByteString # get :: Get ByteString #
Serialize IntSet # |
Methods put :: Putter IntSet # get :: Get IntSet #
Serialize a => Serialize [a] # |
Methods put :: Putter [a] # get :: Get [a] #
Serialize a => Serialize (Maybe a) # |
Methods put :: Putter (Maybe a) # get :: Get (Maybe a) #
(Serialize a, Integral a) => Serialize (Ratio a) # |
Methods put :: Putter (Ratio a) # get :: Get (Ratio a) #
Serialize a => Serialize (Dual a) # |
Methods put :: Putter (Dual a) # get :: Get (Dual a) #
Serialize a => Serialize (Sum a) # |
Methods put :: Putter (Sum a) # get :: Get (Sum a) #
Serialize a => Serialize (Product a) # |
Methods put :: Putter (Product a) # get :: Get (Product a) #
Serialize a => Serialize (First a) # |
Methods put :: Putter (First a) # get :: Get (First a) #
Serialize a => Serialize (Last a) # |
Methods put :: Putter (Last a) # get :: Get (Last a) #
Serialize e => Serialize (Tree e) # |
Methods put :: Putter (Tree e) # get :: Get (Tree e) #
Serialize e => Serialize (Seq e) # |
Methods put :: Putter (Seq e) # get :: Get (Seq e) #
Serialize e => Serialize (IntMap e) # |
Methods put :: Putter (IntMap e) # get :: Get (IntMap e) #
(Ord a, Serialize a) => Serialize (Set a) # |
Methods put :: Putter (Set a) # get :: Get (Set a) #
(Serialize a, Serialize b) => Serialize (Either a b) # |
Methods put :: Putter (Either a b) # get :: Get (Either a b) #
(Serialize a, Serialize b) => Serialize (a, b) # |
Methods put :: Putter (a, b) # get :: Get (a, b) #
(Serialize i, Ix i, Serialize e, IArray UArray e) => Serialize (UArray i e) # |
Methods put :: Putter (UArray i e) # get :: Get (UArray i e) #
(Serialize i, Ix i, Serialize e) => Serialize (Array i e) # |
Methods put :: Putter (Array i e) # get :: Get (Array i e) #
(Ord k, Serialize k, Serialize e) => Serialize (Map k e) # |
Methods put :: Putter (Map k e) # get :: Get (Map k e) #
(Serialize a, Serialize b, Serialize c) => Serialize (a, b, c) # |
Methods put :: Putter (a, b, c) # get :: Get (a, b, c) #
(Serialize a, Serialize b, Serialize c, Serialize d) => Serialize (a, b, c, d) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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) # |
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 #

Minimal complete definition

gPut

Methods

gPut :: Putter (f a) #

Instances

GSerializePut U1 # |
Methods gPut :: Putter (U1 a) #
Serialize a => GSerializePut (K1 i a) # |
Methods gPut :: Putter (K1 i a a) #
(PutSum a, PutSum b, SumSize a, SumSize b) => GSerializePut ((:+:) a b) # |
Methods gPut :: Putter ((a :+: b) a) #
(GSerializePut a, GSerializePut b) => GSerializePut ((:*:) a b) # |
Methods gPut :: Putter ((a :*: b) a) #
GSerializePut a => GSerializePut (M1 i c a) # |
Methods gPut :: Putter (M1 i c a a) #

class GSerializeGet f where #

Minimal complete definition

gGet

Methods

gGet :: Get (f a) #

Instances

GSerializeGet U1 # |
Methods gGet :: Get (U1 a) #
Serialize a => GSerializeGet (K1 i a) # |
Methods gGet :: Get (K1 i a a) #
(GetSum a, GetSum b, SumSize a, SumSize b) => GSerializeGet ((:+:) a b) # |
Methods gGet :: Get ((a :+: b) a) #
(GSerializeGet a, GSerializeGet b) => GSerializeGet ((:*:) a b) # |
Methods gGet :: Get ((a :*: b) a) #
GSerializeGet a => GSerializeGet (M1 i c a) # |
Methods gGet :: Get (M1 i c a a) #