Simple and stupid byte-format reading DSL.
Clojure
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/balabit
test/balabit
.gitignore
.travis.yml
CHANGES.md
README.md
project.clj

README.md

balabit.blobbity

Build Status

This library was born out of a need to have a simply extensible binary data decoding library, which can work iteratively. That is all it does, and hopefully does it well.

Installation

Blobbity is available on Clojars. Add this dependency to your Leiningen project.clj:

[com.balabit/balabit.blobbity "0.1.2"]

Usage

Examples:

(require '[balabit.blobbity :as blob])

To extract information from a buffer that has a 4-byte magic identifier, followed by a 16-bit header length, and a 32-bit offset, pointing to the end of the last written record, one can use the following spec:

(blob/decode-blob buffer [:magic [:string 4]
                          :header-len :uint16
                          :tail-offset :uint32])

As an example for extending the decoders, to parse a netstring, we'd only need to introduce a decoder for it:

(defmethod blob/decode-frame :netstring
  [#^ByteBuffer buffer _]

  (let [len (Integer/parseInt (blob/decode-frame buffer :delimited-string [\:]))
        netstr (blob/decode-frame buffer :string len)]
    (blob/decode-frame buffer :skip 1)
    netstr))

For more information, see the API documentation.

License

Copyright © 2012-2013 Gergely Nagy algernon@balabit.hu

Distributed under the Eclipse Public License, which is also used by Clojure.