cborg-0.2.3.0: Concise Binary Object Representation (CBOR)

Copyright(c) Duncan Coutts 2015-2017
LicenseBSD3-style (see LICENSE.txt)
Maintainerduncan@community.haskell.org
Stabilityexperimental
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Codec.CBOR.Encoding

Contents

Description

High level API for encoding values, for later serialization into CBOR binary format, using a Monoid based interface.

Synopsis

Encoding implementation

newtype Encoding Source #

An intermediate form used during serialisation, specified as a Monoid. It supports efficient concatenation, and is equivalent to a specialised Endo Tokens type.

It is used for the stage in serialisation where we flatten out the Haskell data structure but it is independent of any specific external binary or text format.

Traditionally, to build any arbitrary Encoding value, you specify larger structures from smaller ones and append the small ones together using mconcat.

Since: 0.2.0.0

Constructors

Encoding (Tokens -> Tokens) 
Instances
Show Encoding Source # 
Instance details

Defined in Codec.CBOR.Encoding

Semigroup Encoding Source #

Since: 0.2.0.0

Instance details

Defined in Codec.CBOR.Encoding

Monoid Encoding Source #

Since: 0.2.0.0

Instance details

Defined in Codec.CBOR.Encoding

Encoding API for serialisation

encodeWord :: Word -> Encoding Source #

Encode a Word in a flattened format.

Since: 0.2.0.0

encodeWord8 :: Word8 -> Encoding Source #

Encode a Word8 in a flattened format.

Since: 0.2.0.0

encodeWord16 :: Word16 -> Encoding Source #

Encode a Word16 in a flattened format.

Since: 0.2.0.0

encodeWord32 :: Word32 -> Encoding Source #

Encode a Word32 in a flattened format.

Since: 0.2.0.0

encodeWord64 :: Word64 -> Encoding Source #

Encode a Word64 in a flattened format.

Since: 0.2.0.0

encodeInt :: Int -> Encoding Source #

Encode an Int in a flattened format.

Since: 0.2.0.0

encodeInt8 :: Int8 -> Encoding Source #

Encode an Int8 in a flattened format.

Since: 0.2.0.0

encodeInt16 :: Int16 -> Encoding Source #

Encode an Int16 in a flattened format.

Since: 0.2.0.0

encodeInt32 :: Int32 -> Encoding Source #

Encode an Int32 in a flattened format.

Since: 0.2.0.0

encodeInt64 :: Int64 -> Encoding Source #

Encode an @Int64 in a flattened format.

Since: 0.2.0.0

encodeInteger :: Integer -> Encoding Source #

Encode an arbitrarily large @Integer in a flattened format.

Since: 0.2.0.0

encodeBytes :: ByteString -> Encoding Source #

Encode an arbitrary strict ByteString in a flattened format.

Since: 0.2.0.0

encodeBytesIndef :: Encoding Source #

Encode a token specifying the beginning of a string of bytes of indefinite length. In reality, this specifies a stream of many occurrences of encodeBytes, each specifying a single chunk of the overall string. After all the bytes desired have been encoded, you should follow it with a break token (see encodeBreak).

Since: 0.2.0.0

encodeByteArray :: SlicedByteArray -> Encoding Source #

Encode a bytestring in a flattened format.

Since: 0.2.0.0

encodeString :: Text -> Encoding Source #

Encode a Text in a flattened format.

Since: 0.2.0.0

encodeStringIndef :: Encoding Source #

Encode the beginning of an indefinite string.

Since: 0.2.0.0

encodeUtf8ByteArray :: SlicedByteArray -> Encoding Source #

Encode a UTF-8 string in a flattened format. Note that the contents is not validated to be well-formed UTF-8.

Since: 0.2.0.0

encodeListLen :: Word -> Encoding Source #

Encode the length of a list, used to indicate that the following tokens represent the list values.

Since: 0.2.0.0

encodeListLenIndef :: Encoding Source #

Encode a token specifying that this is the beginning of an indefinite list of unknown size. Tokens representing the list are expected afterwords, followed by a break token (see encodeBreak) when the list has ended.

Since: 0.2.0.0

encodeMapLen :: Word -> Encoding Source #

Encode the length of a Map, used to indicate that the following tokens represent the map values.

Since: 0.2.0.0

encodeMapLenIndef :: Encoding Source #

Encode a token specifying that this is the beginning of an indefinite map of unknown size. Tokens representing the map are expected afterwords, followed by a break token (see encodeBreak) when the map has ended.

Since: 0.2.0.0

encodeBreak :: Encoding Source #

Encode a 'break', used to specify the end of indefinite length objects like maps or lists.

Since: 0.2.0.0

encodeTag :: Word -> Encoding Source #

Encode an arbitrary Word tag.

Since: 0.2.0.0

encodeTag64 :: Word64 -> Encoding Source #

Encode an arbitrary 64-bit Word64 tag.

Since: 0.2.0.0

encodeBool :: Bool -> Encoding Source #

Encode a Bool.

Since: 0.2.0.0

encodeUndef :: Encoding Source #

Encode an Undef value.

Since: 0.2.0.0

encodeNull :: Encoding Source #

Encode a Null value.

Since: 0.2.0.0

encodeSimple :: Word8 -> Encoding Source #

Encode a 'simple' CBOR token that can be represented with an 8-bit word. You probably don't ever need this.

Since: 0.2.0.0

encodeFloat16 :: Float -> Encoding Source #

Encode a small 16-bit Float in a flattened format.

Since: 0.2.0.0

encodeFloat :: Float -> Encoding Source #

Encode a full precision Float in a flattened format.

Since: 0.2.0.0

encodeDouble :: Double -> Encoding Source #

Encode a Double in a flattened format.

Since: 0.2.0.0

encodePreEncoded :: ByteString -> Encoding Source #

Include pre-encoded valid CBOR data into the Encoding.

The data is included into the output as-is without any additional wrapper.

This should be used with care. The data must be a valid CBOR encoding, but this is not checked.

This is useful when you have CBOR data that you know is already valid, e.g. previously validated and stored on disk, and you wish to include it without having to decode and re-encode it.

Since: 0.2.2.0