binary

Binary serialisation for Haskell values using lazy ByteStrings https://github.com/kolmodin/binary

LTS Haskell 8.5:0.8.3.0
Stackage Nightly 2017-03-20:0.8.3.0
Latest on Hackage:0.9.0.0
BSD3 licensed by Lennart Kolmodin
Maintained by Lennart Kolmodin, Don Stewart

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.

Changes

binary

binary-0.9.0.0

  • Add Binary instances for Typeable TypeReps, #131.

binary-0.8.4.1

  • Fix compilation with bytestring < 0.10.4.

binary-0.8.4.0

  • binary supports GHC >= 7.4.2
  • Performance improvements for Alternative functions.
  • put/get functions for IEEE-754 floats and doubles, #119.
  • Fix performance bugs, #115.
  • Binary instances for datatypes in Data.Monoid and Data.Semigroup, #114.

binary-0.8.3.0

  • Replace binary's home grown Builder with Data.ByteString.Builder. Data.Binary.Builder now exports Data.ByteString.Builder.Builder.
  • Add putList :: [a] -> Put to the Binary class. This is used to be able to use the list writing primitives of the new Builder. This brought a number of speedups; Encoding a String is now 70% faster. [Word8] is 76% faster, which also makes Integer 34% faster. Similar numbers for all [IntXX] and [WordXX].
  • Fail gracefully within Get when decoding Bool and Ordering. Previously when decoding invalid data these instances would fail with error.
  • Add Binary instance for Complex a.
  • Add Monoid and Semigroup instance for Put.

binary-0.8.2.1

  • Fix compilation error when using older GHC versions and clang. clang barfs on some of its CPP input (#105).

binary-0.8.2.0

  • When using GHC >= 8, Data.Binary.Get.Get implements MonadFail and delegates its fail to MonadFail.fail.

binary-0.8.1.0

  • Add binary instance for Data.ByteString.Short.
  • Add get/put functions for all Int sizes to Data.Binary.Builder, Data.Binary.Get and Data.Binary.Put.

binary-0.8.0.1

  • Address compiler warnings.

binary-0.8.0.0

  • Added binary instance for Version from Data.Version.
  • Added binary instance for Void from GHC 7.10.1.
  • Added binary instance for (Data.Fixed a) from GHC 7.8.1.
  • Added semigroup instance for Data.Binary.Builder from GHC 8.0.

binary-0.7.6.1

  • Fix compilation for GHC == 7.2.*.

binary-0.7.6.0

  • Added binary instance for GHC.Fingerprint (from GHC >= 7.4).

binary-0.7.5.0

  • Fix performance bug that was noticable when you get a big strict ByteString and the input to the decoder consists of many small chunks. - https://github.com/kolmodin/binary/issues/73 - https://github.com/kolmodin/binary/pull/76
  • Fix memory leak when decoding Double and Float.
    • Commit 497a181c083fa9faf7fa3aa64d1d8deb9ac76ecb
  • We now require QuickCheck >= 2.8. Remove our version of arbitrarySizedNatural.

binary-0.7.4.0

  • Some invalid UTF-8 strings caused an exception when decoded. Those errors will now now fail in the Get monad instead. See #70. Patch contributed by @ttuegel.

binary-0.7.3.0

  • Add Binary instance for Natural (only with base > 4.8).

binary-0.7.2.3

  • Remove INLINEs from GBinary/GSum methods. These interact very badly with the GHC 7.9.x simplifier. See also; - https://github.com/kolmodin/binary/pull/62 - https://ghc.haskell.org/trac/ghc/ticket/9630 - https://ghc.haskell.org/trac/ghc/ticket/9583

binary-0.7.2.2

  • Make import of GHC.Base future-proof (https://github.com/kolmodin/binary/pull/59).

binary-0.7.2.1

  • Fix to compile on GHC 6.10.4 and older (https://github.com/kolmodin/binary/issues/55).

binary-0.7.2.0

  • Add isolate :: Int -> Get a -> Get a.
  • Add label :: String -> Get a -> Get a.

binary-0.7.1.0

  • Add lookAheadE :: Get (Either a b) -> Get (Either a b).
  • Add MonadPlus instance for Get.

binary-0.7.0.1

  • Updates to documentation.

binary-0.7.0.0

  • Add lookAhead :: Get a -> Get a.
  • Add lookAheadM :: Get (Maybe a) -> Get (Maybe a).
  • Add Alternative instance for Get (provides <|>).
  • Add decodeOrFail :: Binary a => L.ByteString -> Either (L.ByteString, ByteOffset, String) (L.ByteString, ByteOffset, a)
  • Add decodeFileOrFail :: Binary a => FilePath -> IO (Either (ByteOffset, String) a).
  • Remove Ord class constraint from Set and Map Binary instances.

binary-0.6.4

  • Add runGetOrFail :: Get a -> L.ByteString -> Either (L.ByteString, ByteOffset, String) (L.ByteString, ByteOffset, a).

binary-0.6.3

  • Documentation tweeks, internal restructuring, more tests.

binary-0.6.2

  • some and many more efficient.
  • Fix bug where bytesRead returned the wrong value.
  • Documentation improvements.

binary-0.6.1

  • Fix bug where a decoder could return with Partial after the previous reply was Nothing.

binary-0.6.0.0

Used by 713 packages:
AERN-Net, AERN-RnToRm, AERN-RnToRm-Plot, Agda, ApplePush, BiobaseInfernal, BiobaseNewick, BiobaseTypes, BiobaseXNA, CBOR, CV, Cabal, Cabal-ide-backend, Chitra, ConcurrentUtils, Condor, CurryDB, DMuCheck, DSA, Dao, DefendTheKing, Dust, Dust-crypto, Dust-tools, Dust-tools-pcap, Elm, Etherbunny, FComp, FileSystem, FontyFruity, GenI, GoogleSB, GrowlNotify, HAppS-Data, HAppS-State, HGraphStorage, HLearn-classification, HPDF, HSoundFile, HXMPP, HarmTrace, HarmTrace-Base, Hayoo, Holumbus-Distribution, Holumbus-MapReduce, Holumbus-Searchengine, Holumbus-Storage, JYU-Utils, Javasf, JuicyPixels, JunkDB, LambdaCalculator, LambdaHack, LambdaNet, Lambdaya, Lazy-Pbkdf2, LinguisticsTypes, Mhailist, Network-NineP, NineP, Ninjas, NumLazyByteString, OpenAFP, OpenAFP-Utils, PBKDF2, Parry, PerfectHash, PrimitiveArray, Pugs, RFC1751, RSA, RefSerialize, Rlang-QQ, SHA, SWMMoutGetMB, Scurry, SimpleAES, SoccerFun, SoccerFunGL, Stomp, SuffixStructures, TernaryTrees, Thrift, TigerHash, Twofish, WMSigner, Workflow, Xec, accelerate-cuda, accelerate-examples, adict, adobe-swatch-exchange, agentx, aivika-distributed, ajhc, amqp, analyze, apotiki, approximate, arbtt, arff, arith-encode, ascii-vector-avc, asil, azure-service-api, b-tree, b9, base32string, base58address, base58string, bash, bed-and-breakfast, bencode, berkeleydb, bert, bet, bimap-server, bimaps, binary-bits, binary-communicator, binary-conduit, binary-derive, binary-enum, binary-ext, binary-generic, binary-ieee754, binary-list, binary-orphans, binary-parsers, binary-protocol, binary-protocol-zmq, binary-shared, binary-state, binary-store, binary-streams, binary-tagged, binary-typed, bindings-codec2, bindynamic, bini, bio, biohazard, biophd, biosff, bitcoin-api, bitcoin-api-extra, bitcoin-block, bitcoin-hs, bitcoin-script, bitcoin-tx, bitcoin-types, bitmaps, bittorrent, bliplib, bloomfilter-redis, bmp, bond-haskell, bound, breve, brillig, bson, buster, buster-gtk, buster-network, bytes, byteset, bytestring-show, bytestring-trie, bytestring-typenats, cabal-install, cabin, cached-traversable, cake, carray, casadi-bindings, cassy, cayley-client, ceilometer-common, chalkboard, chorale-geo, chunky, clustering, cnc-spec-compiler, codec, codec-libevent, coin, compact, compact-map, compact-socket, compensated, compiler-warnings, concraft, concraft-hr, concraft-pl, concrete-typerep, condor, constraints, cpio-conduit, crf-chain1, crf-chain1-constrained, crf-chain2-generic, crf-chain2-tiers, criterion, d-bus, dao, darcs, darkplaces-demo, data-binary-ieee754, data-dispersal, data-msgpack, data-named, data-r-tree, data-serializer, data-stringmap, dawg, dbf, dbjava, dbus-core, decoder-conduit, definitive-graphics, delimited-text, delta-h, dense, detrospector, dicom, dictionaries, distributed-closure, distributed-process, distributed-process-async, distributed-process-azure, distributed-process-client-server, distributed-process-execution, distributed-process-extras, distributed-process-p2p, distributed-process-platform, distributed-process-registry, distributed-process-simplelocalnet, distributed-process-supervisor, distributed-process-systest, distributed-process-task, distributed-process-tests, distributed-process-zookeeper, distributed-static, dns, doc-review, domain-auth, dtab, dwarf, dwarf-el, dynamic-state, dynobud, dyre, easy-bitcoin, edentv, eigen, elf, elm-compiler, elm-get, elm-make, elm-package, elm-repl, encoding, enumeration, erlang, estimators, ethereum-client-haskell, ethereum-merkle-patricia-db, eths-rlp, exinst, external-sort, family-tree, feed-gipeda, fernet, fixed-vector-binary, flaccuraterip, flowdock-rest, flower, freekick2, gasp, generic-accessors, generic-binary, geniconvert, genvalidity-hspec-binary, geo-uk, ghc-boot, ghc-events, ghc-events-parallel, ghc-heap-view, ghc-mod, ghc-simple, ghci, ghcjs-websockets, ght, ginsu, github, gitlib-s3, greg-client, hOpenPGP, hackage-server, hackport, hails, hakyll, hakyll-contrib-links, hakyll-convert, handa-gdata, handa-opengl, happstack-data, happstack-state, harchive, hasbolt, hascar, hascas, hashed-storage, haskell-igraph, haskell-tor, haskell-tyrant, haskelm, haskintex, haskoin, haskoin-crypto, haskoin-protocol, haskoin-script, haskoin-util, haste-compiler, haxl, haxparse, hbayes, hcoap, hedis-pile, hemkay, hemkay-core, hexif, hexstring, hgearman, hgis, hi3status, himpy, hinterface, hist-pl-dawg, hist-pl-fusion, hist-pl-lexicon, hist-pl-types, histogram-fill-binary, hmatrix, hmatrix-gsl-stats, hmatrix-tests, hmemdb, hmp3, hnn, hoauth, hoodle-core, hoodle-extra, hoogle, hopenpgp-tools, hora, hosc, hpdft, hprotoc, hprotoc-fork, hriemann, hs-java, hs-watchman, hsc3, hsc3-graphs, hsexif, hsignal, hspread, hstox, hunt-searchengine, hunt-server, hunt-server-cli, hxt, hxt-binary, hxt-cache, hydrogen-prelude, hyperloglog, ide-backend, ide-backend-common, identifiers, idris, ieee754-parser, iff, infinity, inline-c, inline-java, intricacy, intro, ip2location, ipc, ipcvar, irc-dcc, iso8583-bitmaps, ivor, iyql, jacobi-roots, jarfind, javasf, jdi, jvm-parser, kafka-device, kafka-device-joystick, kafka-device-spacenav, keyvaluehash, krapsh, lambda-devs, lambdabot-core, lambdabot-novelty-plugins, lambdabot-social-plugins, lambdabot-utils, lambdacube-engine, language-eiffel, language-java-classfile, largeword, legion, legion-discovery, legion-extra, leksah, leksah-server, lhc, libGenI, libconfig, liblawless, libmolude, linear, linode, linux-perf, linx-gateway, liquid-fixpoint, list-tries, llsd, log-domain, logging, loshadka, lua-bc, luachunk, luautils, lz4-conduit, maccatcher, machines-binary, macho, manatee, manatee-browser, manatee-core, manatee-curl, manatee-editor, manatee-filemanager, manatee-imageviewer, manatee-ircclient, manatee-mplayer, manatee-pdfviewer, manatee-processmanager, manatee-reader, manatee-template, manatee-terminal, manatee-welcome, marquise, mathgenealogy, memcache, midi, minesweeper, miniutter, minst-idx, mmtf, mnist-idx, moan, moesocks, monad-codec, monarch, mongoDB, morfette, morte, mp, mqtt, msgpack, msgpack-rpc, multipass, multirec-binary, mvclient, mysql-haskell, named-records, nanomsg-haskell, nerf, netcore, netlist, netspec, nettle-frp, nettle-openflow, network-dbus, network-dns, network-metrics, network-minihttp, network-msg, network-msgpack-rpc, network-rpca, network-stream, network-transport, network-transport-zeromq, networked-game, not-gloss, np-linear, obj, octane, openflow, opengl-spacenavigator, openpgp, openpgp-Crypto, openpgp-crypto-api, opensoundcontrol-ht, opentype, osc, osx-ar, ot, packed-dawg, packman, pandoc, paprika, parconc-examples, parsestar, partly, pbkdf, pcd-loader, pdf2line, pecoff, penny-lib, peparser, perdure, persistent-map, persistent-redis, persistent-zookeeper, pgdl, pgsql-simple, phone-push, pi-calculus, pipes-binary, pipes-p2p, pipes-p2p-examples, pointedlist, polh-lexicon, polimorf, pontarius-xmpp, postgresql-typed, postmark-streams, potato-tool, progressive, prologue, protobuf-simple, protocol-buffers, protocol-buffers-fork, pure-cdb, pureMD5, pvss, pwstore-fast, qtah-examples, qtah-qt5, quickcheck-text, quiver-binary, raft, raketka, random-stream, random-variates, randomgen, rank1dynamic, rasterific-svg, rattletrap, rclient, rdf4h, readshp, redis-simple, regular-extras, remote, repa-io, rethinkdb, rethinkdb-client-driver, riak, riff, ripple, rlglue, roshask, rosmsg, rtcm, ruin, rws, safe-money, sarsi, sbp, sbp2udp, scholdoc, scientific, scrabble-bot, sdnv, second-transfer, secp256k1, secret-sharing, semigroups, sequor, serial-test-generators, serokell-util, sessions, sexpr, sgd, sha-streams, shadowsocks, shake, shake-persist, shapefile, shell-escape, sirkel, skylighting, snappy-framing, sndfile-enumerators, snmp, snow-white, sock2stream, sparkle, spatial-math, sphinx, ssh, sstable, stable-tree, stack, starling, statistics, stdf, storablevector-streamfusion, strict-base-types, stringtable-atom, stunts, svm-simple, swapper, synthesizer, synthesizer-core, system-uuid, tables, tagged-binary, tagged-list, tagset-positional, tai64, tamarin-prover, tamarin-prover-term, tamarin-prover-theory, tamarin-prover-utils, task-distribution, tbox, tdigest, templatepg, temporal-music-notation-demo, text, text-binary, text-show-instances, text1, tftp, themoviedb, these, threadscope, thrift, timberc, time-warp, timezone-olson, torrent, tpar, tttool, twentefp-websockets, twidge, txt-sushi, typehash, tz, u2f, udbus, uhc-light, uhc-util, unbound, universal-binary, unix-time, uuid, uuid-types, vector-binary, vector-binary-instances, vector-clock, verbosity, vivid, waddle, wai-middleware-auth, wai-middleware-cache, wai-middleware-cache-redis, wai-middleware-crowd, wavesurfer, wavy, web-push, webapi, webify, websockets, wire-streams, woffex, word-trie, xhb, xhb-ewmh, yesod-auth, yesod-session-redis, yi-core, yi-fuzzy-open, yi-ireader, yi-keymap-vim, yi-language, yi-misc-modes, yi-mode-haskell, yi-mode-javascript, yi-rope, yi-snippet, yxdb-utils, zim-parser, zip-archive, zmidi-core, zmidi-score
comments powered byDisqus