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.Term

Description

This module provides an interface for decoding and encoding arbitrary CBOR values (ones that, for example, may not have been generated by this library).

Using `decodeTerm`, you can decode an arbitrary CBOR value given to you into a `Term`, which represents a CBOR value as an AST.

Similarly, if you wanted to encode some value into a CBOR value directly, you can wrap it in a `Term` constructor and use `encodeTerm`. This would be useful, as an example, if you needed to serialise some value into a CBOR term that is not compatible with that types `Serialise` instance.

Because this interface gives you the ability to decode or encode any arbitrary CBOR term, it can also be seen as an alternative interface to the `Encoding` and `Decoding` modules.

Synopsis

- data Term
  - = TInt !Int
  - | TInteger !Integer
  - | TBytes !ByteString
  - | TBytesI !ByteString
  - | TString !Text
  - | TStringI !Text
  - | TList ![Term]
  - | TListI ![Term]
  - | TMap ![(Term, Term)]
  - | TMapI ![(Term, Term)]
  - | TTagged !Word64 !Term
  - | TBool !Bool
  - | TNull
  - | TSimple !Word8
  - | THalf !Float
  - | TFloat !Float
  - | TDouble !Double
- encodeTerm :: Term -> Encoding
- decodeTerm :: Decoder s Term

# Documentation

data Term Source #

A general CBOR term, which can be used to serialise or deserialise arbitrary CBOR terms for interoperability or debugging. This type is essentially a direct reflection of the CBOR abstract syntax tree as a Haskell data type.

The `Term` type also comes with a `Serialise` instance, so you can easily use ``decode` :: `Decoder` `Term`` to directly decode any arbitrary CBOR value into Haskell with ease, and likewise with `encode`.

Since: 0.2.0.0

Constructors

TInt !Int |
TInteger !Integer |
TBytes !ByteString |
TBytesI !ByteString |
TString !Text |
TStringI !Text |
TList ![Term] |
TListI ![Term] |
TMap ![(Term, Term)] |
TMapI ![(Term, Term)] |
TTagged !Word64 !Term |
TBool !Bool |
TNull |
TSimple !Word8 |
THalf !Float |
TFloat !Float |
TDouble !Double |

#### Instances

Instances details

Read Term Source # |
Instance details Defined in Codec.CBOR.Term Methods readsPrec :: Int -> ReadS Term Source # readList :: ReadS [Term] Source # readPrec :: ReadPrec Term Source # readListPrec :: ReadPrec [Term] Source #
Show Term Source # |
Instance details Defined in Codec.CBOR.Term Methods showsPrec :: Int -> Term -> ShowS Source # show :: Term -> String Source # showList :: [Term] -> ShowS Source #
Eq Term Source # |
Instance details Defined in Codec.CBOR.Term Methods (==) :: Term -> Term -> Bool Source # (/=) :: Term -> Term -> Bool Source #
Ord Term Source # |
Instance details Defined in Codec.CBOR.Term Methods compare :: Term -> Term -> Ordering Source # (<) :: Term -> Term -> Bool Source # (<=) :: Term -> Term -> Bool Source # (>) :: Term -> Term -> Bool Source # (>=) :: Term -> Term -> Bool Source # max :: Term -> Term -> Term Source # min :: Term -> Term -> Term Source #

encodeTerm :: Term -> Encoding Source #

Encode an arbitrary `Term` into an `Encoding` for later serialization.

Since: 0.2.0.0

decodeTerm :: Decoder s Term Source #

Decode some arbitrary CBOR value into a `Term`.

Since: 0.2.0.0