cborg- Concise Binary Object Representation

Copyright(c) Duncan Coutts 2015-2017
LicenseBSD3-style (see LICENSE.txt)
Portabilitynon-portable (GHC extensions)
Safe HaskellNone




A simpler form than CBOR for writing out Encoding values that allows easier verification and testing. While this library primarily focuses on taking Encoding values (independent of any underlying format) and serializing them into CBOR format, this module offers an alternative format called FlatTerm for serializing Encoding values.

The FlatTerm form is very simple and internally mirrors the original Encoding type very carefully. The intention here is that once you have Encoding and Decoding values for your types, you can round-trip values through FlatTerm to catch bugs more easily and with a smaller amount of code to look through.

For that reason, this module is primarily useful for client libraries, and even then, only for their test suites to offer a simpler form for doing encoding tests and catching problems in an encoder and decoder.



type FlatTerm = [TermToken] Source #

A "flat" representation of an Encoding value, useful for round-tripping and writing tests.

Since: cborg-

data TermToken Source #

A concrete encoding of Encoding values, one which mirrors the original Encoding type closely.

Since: cborg-


toFlatTerm Source #


:: Encoding

The input Encoding.

-> FlatTerm

The resulting FlatTerm.

Convert an arbitrary Encoding into a FlatTerm.

Since: cborg-

fromFlatTerm Source #


:: (forall s. Decoder s a)

A Decoder for a serialised value.

-> FlatTerm

The serialised FlatTerm.

-> Either String a

The deserialised value, or an error.

Given a Decoder, decode a FlatTerm back into an ordinary value, or return an error.

Since: cborg-

validFlatTerm Source #


:: FlatTerm

The input FlatTerm

-> Bool

True if valid, False otherwise.

Ensure a FlatTerm is internally consistent and was created in a valid manner.

Since: cborg-