binary: Binary serialisation for Haskell values using lazy ByteStrings

[ bsd3, data, library, parsing ] [ Propose Tags ] [ Report a vulnerability ]

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. The format used can be automatically generated, or you can choose to implement a custom format if needed. Serialisation speeds of over 1 G/sec have been observed, so this library should be suitable for high performance scenarios.


[Skip to Readme]

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

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 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.8.6.0, 0.8.7.0, 0.8.8.0, 0.8.9.0, 0.8.9.1, 0.8.9.2, 0.9.0.0, 0.10.0.0 (info)
Change log changelog.md
Dependencies array, base (>=4.5.0.0 && <4.13), bytestring (>=0.10.4), containers, ghc-prim [details]
Tested with ghc ==7.4.2, ghc ==7.6.3, ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2
License BSD-3-Clause
Author Lennart Kolmodin <kolmodin@gmail.com>
Maintainer Lennart Kolmodin, Don Stewart <dons00@gmail.com>
Revised Revision 1 made by phadej at 2019-05-13T17:52:06Z
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 2017-04-02T16:49:43Z
Distributions Arch:0.8.9.0, Fedora:0.8.9.1
Reverse Dependencies 1115 direct, 13770 indirect [details]
Downloads 197672 total (675 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-04-02 [all 1 reports]

Readme for binary-0.8.5.1

[back to package description]

binary package

Hackage version Stackage version Build Status

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.

Installing binary from Hackage

binary is part of The Glasgow Haskell Compiler (GHC) and therefore if you have either GHC or The Haskell Platform installed, you already have binary.

More recent versions of binary than you might have installed may be available. You can use cabal-install to install a later version from Hackage.

$ cabal update
$ cabal install binary

Building binary

binary comes with both a test suite and a set of benchmarks. While developing, you probably want to enable both. Here's how to get the latest version of the repository, configure and build.

$ git clone git@github.com:kolmodin/binary.git
$ cd binary
$ cabal update
$ cabal configure --enable-tests --enable-benchmarks
$ cabal build

Run the test suite.

$ cabal test

Using binary

First:

import Data.Binary

and then write an instance of Binary for the type you wish to serialise. An example doing exactly this can be found in the Data.Binary module. You can also use the Data.Binary.Builder module to efficiently build lazy bytestrings using the Builder monoid. Or, alternatively, the Data.Binary.Get and Data.Binary.Put to serialize/deserialize using the Get and Put monads.

More information in the haddock documentation.

Deriving binary instances using GHC's Generic

Beginning with GHC 7.2, it is possible to use binary serialization without writing any instance boilerplate code.

{-# LANGUAGE DeriveGeneric #-}

import Data.Binary
import GHC.Generics (Generic)

data Foo = Foo deriving (Generic)

-- GHC will automatically fill out the instance
instance Binary Foo

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
  • Bas van Dijk
  • Florian Weimer

For a full list of contributors, see here.