binary: Binary serialisation for Haskell values using lazy ByteStrings

[ bsd3, data, library, parsing ] [ Propose Tags ]

Efficient, pure binary serialisation using lazy ByteStrings. Haskell values may be encoded to and from binary formats, written to disk as binary, or sent over the network. Serialisation speeds of over 1 G/sec have been observed, so this library should be suitable for high performance scenarios.


[Skip to Readme]
Versions 0.2, 0.3, 0.4, 0.4.1, 0.4.2, 0.4.3, 0.4.3.1, 0.4.4, 0.4.5, 0.5, 0.5.0.1, 0.5.0.2, 0.5.1.0, 0.5.1.1, 0.6.0.0, 0.6.1.0, 0.6.2.0, 0.6.3.0, 0.6.4.0, 0.7.0.0, 0.7.0.1, 0.7.1.0, 0.7.2.0, 0.7.2.1, 0.7.2.2, 0.7.2.3, 0.7.3.0, 0.7.4.0, 0.7.5.0, 0.7.6.0, 0.7.6.1, 0.8.0.0, 0.8.0.1, 0.8.1.0, 0.8.2.0, 0.8.2.1, 0.8.3.0, 0.8.4.0, 0.8.4.1, 0.8.5.0, 0.8.5.1, 0.9.0.0 (info)
Dependencies array, base (>=3.0 && <4.8), bytestring (>=0.9), containers [details]
License BSD-3-Clause
Author Lennart Kolmodin <kolmodin@gmail.com>
Maintainer Lennart Kolmodin, Don Stewart <dons@galois.com>
Revised Revision 1 made by HerbertValerioRiedel at Sat Jan 10 12:48:38 UTC 2015
Category Data, Parsing
Home page https://github.com/kolmodin/binary
Source repo head: git clone git://github.com/kolmodin/binary.git
Uploaded by LennartKolmodin at Thu Sep 20 07:37:15 UTC 2012
Distributions Arch:0.8.5.1, Debian:0.7.2.1, LTSHaskell:0.8.5.1, NixOS:0.8.5.1, Stackage:0.8.5.1
Downloads 119380 total (513 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
developmentDisabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for binary-0.6.1.0

[back to package description]
  binary: efficient, pure binary serialisation using lazy ByteStrings
------------------------------------------------------------------------

The 'binary' package provides Data.Binary, containing the Binary class,
and associated methods, for serialising values to and from lazy
ByteStrings. 

A key feature of 'binary' is that the interface is both pure, and efficient.

The 'binary' package is portable to GHC and Hugs.

Building:

    runhaskell Setup.lhs configure
    runhaskell Setup.lhs build
    runhaskell Setup.lhs install

First:
    import Data.Binary

and then write an instance of Binary for the type you wish to serialise.
More information in the haddock documentation.

Deriving:

It is possible to mechanically derive new instances of Binary for your
types, if they support the Data and Typeable classes. A script is
provided in tools/derive. Here's an example of its use.

    $ cd binary 
    $ cd tools/derive 

    $ ghci -fglasgow-exts BinaryDerive.hs

    *BinaryDerive> :l Example.hs 

    *Main> deriveM (undefined :: Exp)

    instance Binary Main.Exp where
      put (ExpOr a b) = putWord8 0 >> put a >> put b
      put (ExpAnd a b) = putWord8 1 >> put a >> put b
      put (ExpEq a b) = putWord8 2 >> put a >> put b
      put (ExpNEq a b) = putWord8 3 >> put a >> put b
      put (ExpAdd a b) = putWord8 4 >> put a >> put b
      put (ExpSub a b) = putWord8 5 >> put a >> put b
      put (ExpVar a) = putWord8 6 >> put a
      put (ExpInt a) = putWord8 7 >> put a
      get = do
        tag_ <- getWord8
        case tag_ of
          0 -> get >>= \a -> get >>= \b -> return (ExpOr a b)
          1 -> get >>= \a -> get >>= \b -> return (ExpAnd a b)
          2 -> get >>= \a -> get >>= \b -> return (ExpEq a b)
          3 -> get >>= \a -> get >>= \b -> return (ExpNEq a b)
          4 -> get >>= \a -> get >>= \b -> return (ExpAdd a b)
          5 -> get >>= \a -> get >>= \b -> return (ExpSub a b)
          6 -> get >>= \a -> return (ExpVar a)
          7 -> get >>= \a -> return (ExpInt a)
          _ -> fail "no decoding"

Contributors:

    Lennart Kolmodin
    Duncan Coutts
    Don Stewart
    Spencer Janssen
    David Himmelstrup
    Björn Bringert
    Ross Paterson
    Einar Karttunen
    John Meacham
    Ulf Norell
    Tomasz Zielonka
    Stefan Karrmann
    Bryan O'Sullivan
    Florian Weimer