cborg-0.2.10.0: Concise Binary Object Representation (CBOR)

Copyright | (c) Duncan Coutts 2015-2017
License | BSD3-style (see LICENSE.txt)
Maintainer | duncan@community.haskell.org
Stability | experimental
Portability | non-portable (GHC extensions)
Safe Haskell | None
Language | Haskell2010

Codec.CBOR.FlatTerm

Contents

- Types
- Functions

Description

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.

Synopsis

- type FlatTerm = [TermToken]
- data TermToken
  - = TkInt !Int
  - | TkInteger !Integer
  - | TkBytes !ByteString
  - | TkBytesBegin
  - | TkString !Text
  - | TkStringBegin
  - | TkListLen !Word
  - | TkListBegin
  - | TkMapLen !Word
  - | TkMapBegin
  - | TkBreak
  - | TkTag !Word64
  - | TkBool !Bool
  - | TkNull
  - | TkSimple !Word8
  - | TkFloat16 !Float
  - | TkFloat32 !Float
  - | TkFloat64 !Double
- toFlatTerm :: Encoding -> FlatTerm
- fromFlatTerm :: (forall s. Decoder s a) -> FlatTerm -> Either String a
- validFlatTerm :: FlatTerm -> Bool
- decodeTermToken :: Decoder s TermToken

# Types

type FlatTerm = [TermToken] #

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

Since: 0.2.0.0

data TermToken #

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

Since: 0.2.0.0

Constructors

TkInt !Int |
TkInteger !Integer |
TkBytes !ByteString |
TkBytesBegin |
TkString !Text |
TkStringBegin |
TkListLen !Word |
TkListBegin |
TkMapLen !Word |
TkMapBegin |
TkBreak |
TkTag !Word64 |
TkBool !Bool |
TkNull |
TkSimple !Word8 |
TkFloat16 !Float |
TkFloat32 !Float |
TkFloat64 !Double |

#### Instances

Instances details

Show TermToken # |
Instance details Defined in Codec.CBOR.FlatTerm Methods showsPrec :: Int -> TermToken -> ShowS # show :: TermToken -> String # showList :: [TermToken] -> ShowS #
Eq TermToken # |
Instance details Defined in Codec.CBOR.FlatTerm Methods (==) :: TermToken -> TermToken -> Bool # (/=) :: TermToken -> TermToken -> Bool #
Ord TermToken # |
Instance details Defined in Codec.CBOR.FlatTerm Methods compare :: TermToken -> TermToken -> Ordering # (<) :: TermToken -> TermToken -> Bool # (<=) :: TermToken -> TermToken -> Bool # (>) :: TermToken -> TermToken -> Bool # (>=) :: TermToken -> TermToken -> Bool # max :: TermToken -> TermToken -> TermToken # min :: TermToken -> TermToken -> TermToken #

# Functions

toFlatTerm #

Arguments

:: Encoding | The input `Encoding`.
-> FlatTerm | The resulting `FlatTerm`.

Convert an arbitrary `Encoding` into a `FlatTerm`.

Since: 0.2.0.0

fromFlatTerm #

Arguments

:: (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: 0.2.0.0

validFlatTerm #

Arguments

:: FlatTerm | The input `FlatTerm`
-> Bool | `True` if valid, `False` otherwise.

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

Since: 0.2.0.0

decodeTermToken :: Decoder s TermToken #