cereal-0.5.0.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

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

# 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

Instances

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

# 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