serialise-0.2.6.0: A binary serialisation library for Haskell values.

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 | Safe-Inferred
Language | Haskell2010

Codec.Serialise

Contents

- High level, one-shot API
- Deserialisation exceptions
- Incremental encoding interface
- The ``Serialise`` class
- IO operations
  - ``FilePath`` API
  - ``Handle`` API

Description

This module provides functions to serialise and deserialise Haskell values for storage or transmission, to and from lazy ``ByteString``s. It also provides a type class and utilities to help you make your types serialisable.

For a full tutorial on using this module, see Codec.Serialise.Tutorial.

Synopsis

- serialise :: Serialise a => a -> ByteString
- deserialise :: Serialise a => ByteString -> a
- deserialiseOrFail :: Serialise a => ByteString -> Either DeserialiseFailure a
- data DeserialiseFailure = DeserialiseFailure ByteOffset String
- serialiseIncremental :: Serialise a => a -> Builder
- deserialiseIncremental :: Serialise a => ST s (IDecode s a)
- data IDecode s a
  - = Partial (Maybe ByteString -> ST s (IDecode s a))
  - | Done !ByteString !ByteOffset a
  - | Fail !ByteString !ByteOffset DeserialiseFailure
- class Serialise a where
  - encode :: a -> Encoding
  - decode :: Decoder s a
  - encodeList :: [a] -> Encoding
  - decodeList :: Decoder s [a]
- writeFileSerialise :: Serialise a => FilePath -> a -> IO ()
- readFileDeserialise :: Serialise a => FilePath -> IO a
- hPutSerialise :: Serialise a => Handle -> a -> IO ()

# High level, one-shot API

The following API exposes a high level interface allowing you to quickly convert between arbitrary Haskell values (which are an instance of ``Serialise``) and lazy ``ByteString``s.

serialise :: Serialise a => a -> ByteString Source #

Serialise a Haskell value to an external binary representation.

The output is represented as a lazy `ByteString` and is constructed incrementally.

Since: 0.2.0.0

deserialise :: Serialise a => ByteString -> a Source #

Deserialise a Haskell value from the external binary representation (which must have been made using `serialise` or related function).

Throws: ``DeserialiseFailure`` if the given external representation is invalid or does not correspond to a value of the expected type.

Since: 0.2.0.0

deserialiseOrFail :: Serialise a => ByteString -> Either DeserialiseFailure a Source #

Deserialise a Haskell value from the external binary representation, or get back a ``DeserialiseFailure``.

Since: 0.2.0.0

# Deserialisation exceptions

data DeserialiseFailure Source #

An exception type that may be returned (by pure functions) or thrown (by IO actions) that fail to deserialise a given input.

Since: cborg-0.2.0.0

Constructors

DeserialiseFailure ByteOffset String |

#### Instances

Instances details

Exception DeserialiseFailure |
Instance details Defined in Codec.CBOR.Read Methods toException :: DeserialiseFailure -> SomeException Source # fromException :: SomeException -> Maybe DeserialiseFailure Source # displayException :: DeserialiseFailure -> String Source #
Show DeserialiseFailure |
Instance details Defined in Codec.CBOR.Read Methods showsPrec :: Int -> DeserialiseFailure -> ShowS Source # show :: DeserialiseFailure -> String Source # showList :: [DeserialiseFailure] -> ShowS Source #
NFData DeserialiseFailure |
Instance details Defined in Codec.CBOR.Read Methods rnf :: DeserialiseFailure -> () Source #
Eq DeserialiseFailure |
Instance details Defined in Codec.CBOR.Read Methods (==) :: DeserialiseFailure -> DeserialiseFailure -> Bool Source # (/=) :: DeserialiseFailure -> DeserialiseFailure -> Bool Source #

# Incremental encoding interface

The following API allows you to encode or decode CBOR values incrementally, which is useful for large structures that require you to stream values in over time.

serialiseIncremental :: Serialise a => a -> Builder Source #

Serialise a Haskell value to an external binary representation.

The output is represented as a `Builder` and is constructed incrementally. The representation as a `Builder` allows efficient concatenation with other data.

Since: 0.2.0.0

deserialiseIncremental :: Serialise a => ST s (IDecode s a) Source #

Deserialise a Haskell value from the external binary representation.

This allows input data to be provided incrementally, rather than all in one go. It also gives an explicit representation of deserialisation errors.

Note that the incremental behaviour is only for the input data, not the output value: the final deserialised value is constructed and returned as a whole, not incrementally.

Since: 0.2.0.0

data IDecode s a Source #

An Incremental decoder, used to represent the result of attempting to run a decoder over a given input, and return a value of type `a`.

Constructors

Partial (Maybe ByteString -> ST s (IDecode s a)) | The decoder has consumed the available input and needs more to continue. Provide `Just` if more input is available and `Nothing` otherwise, and you will get a new `IDecode`.
Done !ByteString !ByteOffset a | The decoder has successfully finished. Except for the output value you also get any unused input as well as the number of bytes consumed.
Fail !ByteString !ByteOffset DeserialiseFailure | The decoder ran into an error. The decoder either used `fail` or was not provided enough input. Contains any unconsumed input, the number of bytes consumed, and a `DeserialiseFailure` exception describing the reason why the failure occurred.

# The ``Serialise`` class

class Serialise a where Source #

Types that are instances of the ``Serialise`` class allow values to be quickly encoded or decoded directly to a CBOR representation, for object transmission or storage.

Since: 0.2.0.0

Minimal complete definition

Nothing

Methods

encode :: a -> Encoding Source #

Definition for encoding a given type into a binary representation, using the ``Encoding`` ``Monoid``.

Since: 0.2.0.0

default encode :: (Generic a, GSerialiseEncode (Rep a)) => a -> Encoding Source #

decode :: Decoder s a Source #

Definition of a given ``Decoder`` for a type.

Since: 0.2.0.0

default decode :: (Generic a, GSerialiseDecode (Rep a)) => Decoder s a Source #

encodeList :: [a] -> Encoding Source #

Utility to support specialised encoding for some list type - used for ``Char``/``String`` instances in this package.

Since: 0.2.0.0

decodeList :: Decoder s [a] Source #

Utility to support specialised decoding for some list type - used for ``Char``/``String`` instances in this package.

Since: 0.2.0.0

#### Instances

Instances details

Serialise All Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: All -> Encoding Source # decode :: Decoder s All Source # encodeList :: [All] -> Encoding Source # decodeList :: Decoder s [All] Source #
Serialise Any Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Any -> Encoding Source # decode :: Decoder s Any Source # encodeList :: [Any] -> Encoding Source # decodeList :: Decoder s [Any] Source #
Serialise SomeTypeRep Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: SomeTypeRep -> Encoding Source # decode :: Decoder s SomeTypeRep Source # encodeList :: [SomeTypeRep] -> Encoding Source # decodeList :: Decoder s [SomeTypeRep] Source #
Serialise Version Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Version -> Encoding Source # decode :: Decoder s Version Source # encodeList :: [Version] -> Encoding Source # decodeList :: Decoder s [Version] Source #
Serialise Void Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Void -> Encoding Source # decode :: Decoder s Void Source # encodeList :: [Void] -> Encoding Source # decodeList :: Decoder s [Void] Source #
Serialise CChar Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CChar -> Encoding Source # decode :: Decoder s CChar Source # encodeList :: [CChar] -> Encoding Source # decodeList :: Decoder s [CChar] Source #
Serialise CClock Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CClock -> Encoding Source # decode :: Decoder s CClock Source # encodeList :: [CClock] -> Encoding Source # decodeList :: Decoder s [CClock] Source #
Serialise CDouble Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CDouble -> Encoding Source # decode :: Decoder s CDouble Source # encodeList :: [CDouble] -> Encoding Source # decodeList :: Decoder s [CDouble] Source #
Serialise CFloat Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CFloat -> Encoding Source # decode :: Decoder s CFloat Source # encodeList :: [CFloat] -> Encoding Source # decodeList :: Decoder s [CFloat] Source #
Serialise CInt Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CInt -> Encoding Source # decode :: Decoder s CInt Source # encodeList :: [CInt] -> Encoding Source # decodeList :: Decoder s [CInt] Source #
Serialise CIntMax Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CIntMax -> Encoding Source # decode :: Decoder s CIntMax Source # encodeList :: [CIntMax] -> Encoding Source # decodeList :: Decoder s [CIntMax] Source #
Serialise CIntPtr Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CIntPtr -> Encoding Source # decode :: Decoder s CIntPtr Source # encodeList :: [CIntPtr] -> Encoding Source # decodeList :: Decoder s [CIntPtr] Source #
Serialise CLLong Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CLLong -> Encoding Source # decode :: Decoder s CLLong Source # encodeList :: [CLLong] -> Encoding Source # decodeList :: Decoder s [CLLong] Source #
Serialise CLong Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CLong -> Encoding Source # decode :: Decoder s CLong Source # encodeList :: [CLong] -> Encoding Source # decodeList :: Decoder s [CLong] Source #
Serialise CPtrdiff Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CPtrdiff -> Encoding Source # decode :: Decoder s CPtrdiff Source # encodeList :: [CPtrdiff] -> Encoding Source # decodeList :: Decoder s [CPtrdiff] Source #
Serialise CSChar Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSChar -> Encoding Source # decode :: Decoder s CSChar Source # encodeList :: [CSChar] -> Encoding Source # decodeList :: Decoder s [CSChar] Source #
Serialise CSUSeconds Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSUSeconds -> Encoding Source # decode :: Decoder s CSUSeconds Source # encodeList :: [CSUSeconds] -> Encoding Source # decodeList :: Decoder s [CSUSeconds] Source #
Serialise CShort Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CShort -> Encoding Source # decode :: Decoder s CShort Source # encodeList :: [CShort] -> Encoding Source # decodeList :: Decoder s [CShort] Source #
Serialise CSigAtomic Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSigAtomic -> Encoding Source # decode :: Decoder s CSigAtomic Source # encodeList :: [CSigAtomic] -> Encoding Source # decodeList :: Decoder s [CSigAtomic] Source #
Serialise CSize Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSize -> Encoding Source # decode :: Decoder s CSize Source # encodeList :: [CSize] -> Encoding Source # decodeList :: Decoder s [CSize] Source #
Serialise CTime Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CTime -> Encoding Source # decode :: Decoder s CTime Source # encodeList :: [CTime] -> Encoding Source # decodeList :: Decoder s [CTime] Source #
Serialise CUChar Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUChar -> Encoding Source # decode :: Decoder s CUChar Source # encodeList :: [CUChar] -> Encoding Source # decodeList :: Decoder s [CUChar] Source #
Serialise CUInt Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUInt -> Encoding Source # decode :: Decoder s CUInt Source # encodeList :: [CUInt] -> Encoding Source # decodeList :: Decoder s [CUInt] Source #
Serialise CUIntMax Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUIntMax -> Encoding Source # decode :: Decoder s CUIntMax Source # encodeList :: [CUIntMax] -> Encoding Source # decodeList :: Decoder s [CUIntMax] Source #
Serialise CUIntPtr Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUIntPtr -> Encoding Source # decode :: Decoder s CUIntPtr Source # encodeList :: [CUIntPtr] -> Encoding Source # decodeList :: Decoder s [CUIntPtr] Source #
Serialise CULLong Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CULLong -> Encoding Source # decode :: Decoder s CULLong Source # encodeList :: [CULLong] -> Encoding Source # decodeList :: Decoder s [CULLong] Source #
Serialise CULong Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CULong -> Encoding Source # decode :: Decoder s CULong Source # encodeList :: [CULong] -> Encoding Source # decodeList :: Decoder s [CULong] Source #
Serialise CUSeconds Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUSeconds -> Encoding Source # decode :: Decoder s CUSeconds Source # encodeList :: [CUSeconds] -> Encoding Source # decodeList :: Decoder s [CUSeconds] Source #
Serialise CUShort Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUShort -> Encoding Source # decode :: Decoder s CUShort Source # encodeList :: [CUShort] -> Encoding Source # decodeList :: Decoder s [CUShort] Source #
Serialise CWchar Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CWchar -> Encoding Source # decode :: Decoder s CWchar Source # encodeList :: [CWchar] -> Encoding Source # decodeList :: Decoder s [CWchar] Source #
Serialise Fingerprint Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Fingerprint -> Encoding Source # decode :: Decoder s Fingerprint Source # encodeList :: [Fingerprint] -> Encoding Source # decodeList :: Decoder s [Fingerprint] Source #
Serialise ExitCode Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ExitCode -> Encoding Source # decode :: Decoder s ExitCode Source # encodeList :: [ExitCode] -> Encoding Source # decodeList :: Decoder s [ExitCode] Source #
Serialise Int16 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int16 -> Encoding Source # decode :: Decoder s Int16 Source # encodeList :: [Int16] -> Encoding Source # decodeList :: Decoder s [Int16] Source #
Serialise Int32 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int32 -> Encoding Source # decode :: Decoder s Int32 Source # encodeList :: [Int32] -> Encoding Source # decodeList :: Decoder s [Int32] Source #
Serialise Int64 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int64 -> Encoding Source # decode :: Decoder s Int64 Source # encodeList :: [Int64] -> Encoding Source # decodeList :: Decoder s [Int64] Source #
Serialise Int8 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int8 -> Encoding Source # decode :: Decoder s Int8 Source # encodeList :: [Int8] -> Encoding Source # decodeList :: Decoder s [Int8] Source #
Serialise Word16 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word16 -> Encoding Source # decode :: Decoder s Word16 Source # encodeList :: [Word16] -> Encoding Source # decodeList :: Decoder s [Word16] Source #
Serialise Word32 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word32 -> Encoding Source # decode :: Decoder s Word32 Source # encodeList :: [Word32] -> Encoding Source # decodeList :: Decoder s [Word32] Source #
Serialise Word64 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word64 -> Encoding Source # decode :: Decoder s Word64 Source # encodeList :: [Word64] -> Encoding Source # decodeList :: Decoder s [Word64] Source #
Serialise Word8 Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word8 -> Encoding Source # decode :: Decoder s Word8 Source # encodeList :: [Word8] -> Encoding Source # decodeList :: Decoder s [Word8] Source #
Serialise ByteString Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ByteString -> Encoding Source # decode :: Decoder s ByteString Source # encodeList :: [ByteString] -> Encoding Source # decodeList :: Decoder s [ByteString] Source #
Serialise ByteString Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ByteString -> Encoding Source # decode :: Decoder s ByteString Source # encodeList :: [ByteString] -> Encoding Source # decodeList :: Decoder s [ByteString] Source #
Serialise ShortByteString Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ShortByteString -> Encoding Source # decode :: Decoder s ShortByteString Source # encodeList :: [ShortByteString] -> Encoding Source # decodeList :: Decoder s [ShortByteString] Source #
Serialise Term Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Term -> Encoding Source # decode :: Decoder s Term Source # encodeList :: [Term] -> Encoding Source # decodeList :: Decoder s [Term] Source #
Serialise IntSet Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: IntSet -> Encoding Source # decode :: Decoder s IntSet Source # encodeList :: [IntSet] -> Encoding Source # decodeList :: Decoder s [IntSet] Source #
Serialise KindRep Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: KindRep -> Encoding Source # decode :: Decoder s KindRep Source # encodeList :: [KindRep] -> Encoding Source # decodeList :: Decoder s [KindRep] Source #
Serialise Ordering Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Ordering -> Encoding Source # decode :: Decoder s Ordering Source # encodeList :: [Ordering] -> Encoding Source # decodeList :: Decoder s [Ordering] Source #
Serialise TyCon Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TyCon -> Encoding Source # decode :: Decoder s TyCon Source # encodeList :: [TyCon] -> Encoding Source # decodeList :: Decoder s [TyCon] Source #
Serialise TypeLitSort Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TypeLitSort -> Encoding Source # decode :: Decoder s TypeLitSort Source # encodeList :: [TypeLitSort] -> Encoding Source # decodeList :: Decoder s [TypeLitSort] Source #
Serialise Half Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Half -> Encoding Source # decode :: Decoder s Half Source # encodeList :: [Half] -> Encoding Source # decodeList :: Decoder s [Half] Source #
Serialise Text Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Text -> Encoding Source # decode :: Decoder s Text Source # encodeList :: [Text] -> Encoding Source # decodeList :: Decoder s [Text] Source #
Serialise Text Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Text -> Encoding Source # decode :: Decoder s Text Source # encodeList :: [Text] -> Encoding Source # decodeList :: Decoder s [Text] Source #
Serialise UTCTime Source # | `UTCTime` is encoded using the extended time format which is currently in Internet Draft state, https://tools.ietf.org/html/draft-bormann-cbor-time-tag-00. Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: UTCTime -> Encoding Source # decode :: Decoder s UTCTime Source # encodeList :: [UTCTime] -> Encoding Source # decodeList :: Decoder s [UTCTime] Source #
Serialise Integer Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Integer -> Encoding Source # decode :: Decoder s Integer Source # encodeList :: [Integer] -> Encoding Source # decodeList :: Decoder s [Integer] Source #
Serialise Natural Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Natural -> Encoding Source # decode :: Decoder s Natural Source # encodeList :: [Natural] -> Encoding Source # decodeList :: Decoder s [Natural] Source #
Serialise () Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: () -> Encoding Source # decode :: Decoder s () Source # encodeList :: [()] -> Encoding Source # decodeList :: Decoder s [()] Source #
Serialise Bool Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Bool -> Encoding Source # decode :: Decoder s Bool Source # encodeList :: [Bool] -> Encoding Source # decodeList :: Decoder s [Bool] Source #
Serialise Char Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Char -> Encoding Source # decode :: Decoder s Char Source # encodeList :: [Char] -> Encoding Source # decodeList :: Decoder s [Char] Source #
Serialise Double Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Double -> Encoding Source # decode :: Decoder s Double Source # encodeList :: [Double] -> Encoding Source # decodeList :: Decoder s [Double] Source #
Serialise Float Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Float -> Encoding Source # decode :: Decoder s Float Source # encodeList :: [Float] -> Encoding Source # decodeList :: Decoder s [Float] Source #
Serialise Int Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int -> Encoding Source # decode :: Decoder s Int Source # encodeList :: [Int] -> Encoding Source # decodeList :: Decoder s [Int] Source #
Serialise Levity Source # | Since: 0.2.6.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Levity -> Encoding Source # decode :: Decoder s Levity Source # encodeList :: [Levity] -> Encoding Source # decodeList :: Decoder s [Levity] Source #
Serialise RuntimeRep Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: RuntimeRep -> Encoding Source # decode :: Decoder s RuntimeRep Source # encodeList :: [RuntimeRep] -> Encoding Source # decodeList :: Decoder s [RuntimeRep] Source #
Serialise VecCount Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: VecCount -> Encoding Source # decode :: Decoder s VecCount Source # encodeList :: [VecCount] -> Encoding Source # decodeList :: Decoder s [VecCount] Source #
Serialise VecElem Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: VecElem -> Encoding Source # decode :: Decoder s VecElem Source # encodeList :: [VecElem] -> Encoding Source # decodeList :: Decoder s [VecElem] Source #
Serialise Word Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word -> Encoding Source # decode :: Decoder s Word Source # encodeList :: [Word] -> Encoding Source # decodeList :: Decoder s [Word] Source #
Serialise a => Serialise (ZipList a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ZipList a -> Encoding Source # decode :: Decoder s (ZipList a) Source # encodeList :: [ZipList a] -> Encoding Source # decodeList :: Decoder s [ZipList a] Source #
Serialise a => Serialise (Complex a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Complex a -> Encoding Source # decode :: Decoder s (Complex a) Source # encodeList :: [Complex a] -> Encoding Source # decodeList :: Decoder s [Complex a] Source #
Serialise a => Serialise (Identity a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Identity a -> Encoding Source # decode :: Decoder s (Identity a) Source # encodeList :: [Identity a] -> Encoding Source # decodeList :: Decoder s [Identity a] Source #
Serialise a => Serialise (First a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: First a -> Encoding Source # decode :: Decoder s (First a) Source # encodeList :: [First a] -> Encoding Source # decodeList :: Decoder s [First a] Source #
Serialise a => Serialise (Last a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Last a -> Encoding Source # decode :: Decoder s (Last a) Source # encodeList :: [Last a] -> Encoding Source # decodeList :: Decoder s [Last a] Source #
Serialise a => Serialise (Down a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Down a -> Encoding Source # decode :: Decoder s (Down a) Source # encodeList :: [Down a] -> Encoding Source # decodeList :: Decoder s [Down a] Source #
Serialise a => Serialise (First a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: First a -> Encoding Source # decode :: Decoder s (First a) Source # encodeList :: [First a] -> Encoding Source # decodeList :: Decoder s [First a] Source #
Serialise a => Serialise (Last a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Last a -> Encoding Source # decode :: Decoder s (Last a) Source # encodeList :: [Last a] -> Encoding Source # decodeList :: Decoder s [Last a] Source #
Serialise a => Serialise (Max a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Max a -> Encoding Source # decode :: Decoder s (Max a) Source # encodeList :: [Max a] -> Encoding Source # decodeList :: Decoder s [Max a] Source #
Serialise a => Serialise (Min a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Min a -> Encoding Source # decode :: Decoder s (Min a) Source # encodeList :: [Min a] -> Encoding Source # decodeList :: Decoder s [Min a] Source #
Serialise a => Serialise (WrappedMonoid a) Source # |
Instance details Defined in Codec.Serialise.Class Methods encode :: WrappedMonoid a -> Encoding Source # decode :: Decoder s (WrappedMonoid a) Source # encodeList :: [WrappedMonoid a] -> Encoding Source # decodeList :: Decoder s [WrappedMonoid a] Source #
Serialise a => Serialise (Dual a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Dual a -> Encoding Source # decode :: Decoder s (Dual a) Source # encodeList :: [Dual a] -> Encoding Source # decodeList :: Decoder s [Dual a] Source #
Serialise a => Serialise (Product a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Product a -> Encoding Source # decode :: Decoder s (Product a) Source # encodeList :: [Product a] -> Encoding Source # decodeList :: Decoder s [Product a] Source #
Serialise a => Serialise (Sum a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Sum a -> Encoding Source # decode :: Decoder s (Sum a) Source # encodeList :: [Sum a] -> Encoding Source # decodeList :: Decoder s [Sum a] Source #
(Serialise a, Integral a) => Serialise (Ratio a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Ratio a -> Encoding Source # decode :: Decoder s (Ratio a) Source # encodeList :: [Ratio a] -> Encoding Source # decodeList :: Decoder s [Ratio a] Source #
Serialise a => Serialise (IntMap a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: IntMap a -> Encoding Source # decode :: Decoder s (IntMap a) Source # encodeList :: [IntMap a] -> Encoding Source # decodeList :: Decoder s [IntMap a] Source #
Serialise a => Serialise (Seq a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Seq a -> Encoding Source # decode :: Decoder s (Seq a) Source # encodeList :: [Seq a] -> Encoding Source # decodeList :: Decoder s [Seq a] Source #
(Ord a, Serialise a) => Serialise (Set a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Set a -> Encoding Source # decode :: Decoder s (Set a) Source # encodeList :: [Set a] -> Encoding Source # decodeList :: Decoder s [Set a] Source #
Serialise a => Serialise (Tree a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Tree a -> Encoding Source # decode :: Decoder s (Tree a) Source # encodeList :: [Tree a] -> Encoding Source # decodeList :: Decoder s [Tree a] Source #
Serialise a => Serialise (Maybe a) Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Maybe a -> Encoding Source # decode :: Decoder s (Maybe a) Source # encodeList :: [Maybe a] -> Encoding Source # decodeList :: Decoder s [Maybe a] Source #
(Serialise a, Hashable a, Eq a) => Serialise (HashSet a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: HashSet a -> Encoding Source # decode :: Decoder s (HashSet a) Source # encodeList :: [HashSet a] -> Encoding Source # decodeList :: Decoder s [HashSet a] Source #
Serialise a => Serialise (Vector a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding Source # decode :: Decoder s (Vector a) Source # encodeList :: [Vector a] -> Encoding Source # decodeList :: Decoder s [Vector a] Source #
(Serialise a, Prim a) => Serialise (Vector a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding Source # decode :: Decoder s (Vector a) Source # encodeList :: [Vector a] -> Encoding Source # decodeList :: Decoder s [Vector a] Source #
(Serialise a, Storable a) => Serialise (Vector a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding Source # decode :: Decoder s (Vector a) Source # encodeList :: [Vector a] -> Encoding Source # decodeList :: Decoder s [Vector a] Source #
(Serialise a, Unbox a) => Serialise (Vector a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding Source # decode :: Decoder s (Vector a) Source # encodeList :: [Vector a] -> Encoding Source # decodeList :: Decoder s [Vector a] Source #
Serialise a => Serialise (NonEmpty a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: NonEmpty a -> Encoding Source # decode :: Decoder s (NonEmpty a) Source # encodeList :: [NonEmpty a] -> Encoding Source # decodeList :: Decoder s [NonEmpty a] Source #
Serialise a => Serialise (Maybe a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Maybe a -> Encoding Source # decode :: Decoder s (Maybe a) Source # encodeList :: [Maybe a] -> Encoding Source # decodeList :: Decoder s [Maybe a] Source #
Serialise a => Serialise [a] Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: [a] -> Encoding Source # decode :: Decoder s [a] Source # encodeList :: [[a]] -> Encoding Source # decodeList :: Decoder s [[a]] Source #
(Serialise a, Serialise b) => Serialise (Either a b) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Either a b -> Encoding Source # decode :: Decoder s (Either a b) Source # encodeList :: [Either a b] -> Encoding Source # decodeList :: Decoder s [Either a b] Source #
Serialise (Fixed e) Source # | Values are serialised in units of least precision represented as `Integer`. Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Fixed e -> Encoding Source # decode :: Decoder s (Fixed e) Source # encodeList :: [Fixed e] -> Encoding Source # decodeList :: Decoder s [Fixed e] Source #
Serialise (Proxy a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Proxy a -> Encoding Source # decode :: Decoder s (Proxy a) Source # encodeList :: [Proxy a] -> Encoding Source # decodeList :: Decoder s [Proxy a] Source #
Typeable a => Serialise (TypeRep a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TypeRep a -> Encoding Source # decode :: Decoder s (TypeRep a) Source # encodeList :: [TypeRep a] -> Encoding Source # decodeList :: Decoder s [TypeRep a] Source #
(Ord k, Serialise k, Serialise v) => Serialise (Map k v) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Map k v -> Encoding Source # decode :: Decoder s (Map k v) Source # encodeList :: [Map k v] -> Encoding Source # decodeList :: Decoder s [Map k v] Source #
(Serialise a, Serialise b) => Serialise (Either a b) Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Either a b -> Encoding Source # decode :: Decoder s (Either a b) Source # encodeList :: [Either a b] -> Encoding Source # decodeList :: Decoder s [Either a b] Source #
(Serialise a, Serialise b) => Serialise (These a b) Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: These a b -> Encoding Source # decode :: Decoder s (These a b) Source # encodeList :: [These a b] -> Encoding Source # decodeList :: Decoder s [These a b] Source #
(Serialise a, Serialise b) => Serialise (Pair a b) Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Pair a b -> Encoding Source # decode :: Decoder s (Pair a b) Source # encodeList :: [Pair a b] -> Encoding Source # decodeList :: Decoder s [Pair a b] Source #
(Serialise a, Serialise b) => Serialise (These a b) Source # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: These a b -> Encoding Source # decode :: Decoder s (These a b) Source # encodeList :: [These a b] -> Encoding Source # decodeList :: Decoder s [These a b] Source #
(Serialise k, Hashable k, Eq k, Serialise v) => Serialise (HashMap k v) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: HashMap k v -> Encoding Source # decode :: Decoder s (HashMap k v) Source # encodeList :: [HashMap k v] -> Encoding Source # decodeList :: Decoder s [HashMap k v] Source #
(Serialise a, Serialise b) => Serialise (a, b) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b) -> Encoding Source # decode :: Decoder s (a, b) Source # encodeList :: [(a, b)] -> Encoding Source # decodeList :: Decoder s [(a, b)] Source #
Serialise a => Serialise (Const a b) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Const a b -> Encoding Source # decode :: Decoder s (Const a b) Source # encodeList :: [Const a b] -> Encoding Source # decodeList :: Decoder s [Const a b] Source #
Serialise (f a) => Serialise (Alt f a) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Alt f a -> Encoding Source # decode :: Decoder s (Alt f a) Source # encodeList :: [Alt f a] -> Encoding Source # decodeList :: Decoder s [Alt f a] Source #
(Serialise a, Serialise b, Serialise c) => Serialise (a, b, c) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c) -> Encoding Source # decode :: Decoder s (a, b, c) Source # encodeList :: [(a, b, c)] -> Encoding Source # decodeList :: Decoder s [(a, b, c)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d) => Serialise (a, b, c, d) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d) -> Encoding Source # decode :: Decoder s (a, b, c, d) Source # encodeList :: [(a, b, c, d)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e) => Serialise (a, b, c, d, e) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e) -> Encoding Source # decode :: Decoder s (a, b, c, d, e) Source # encodeList :: [(a, b, c, d, e)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d, e)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f) => Serialise (a, b, c, d, e, f) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f) -> Encoding Source # decode :: Decoder s (a, b, c, d, e, f) Source # encodeList :: [(a, b, c, d, e, f)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d, e, f)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f, Serialise g) => Serialise (a, b, c, d, e, f, g) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g) -> Encoding Source # decode :: Decoder s (a, b, c, d, e, f, g) Source # encodeList :: [(a, b, c, d, e, f, g)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d, e, f, g)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f, Serialise g, Serialise h) => Serialise (a, b, c, d, e, f, g, h) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g, h) -> Encoding Source # decode :: Decoder s (a, b, c, d, e, f, g, h) Source # encodeList :: [(a, b, c, d, e, f, g, h)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d, e, f, g, h)] Source #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f, Serialise g, Serialise h, Serialise i) => Serialise (a, b, c, d, e, f, g, h, i) Source # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g, h, i) -> Encoding Source # decode :: Decoder s (a, b, c, d, e, f, g, h, i) Source # encodeList :: [(a, b, c, d, e, f, g, h, i)] -> Encoding Source # decodeList :: Decoder s [(a, b, c, d, e, f, g, h, i)] Source #

# IO operations

Convenient utilities for basic ``IO`` operations.

## ``FilePath`` API

writeFileSerialise Source #

Arguments

:: Serialise a |
=> FilePath | The file to write to.
-> a | The value to be serialised and written.
-> IO () |

Serialise a ``ByteString`` and write it directly to the specified file.

Since: 0.2.0.0

readFileDeserialise Source #

Arguments

:: Serialise a |
=> FilePath | The file to read from.
-> IO a | The deserialised value.

Read the specified file (internally, by reading a ``ByteString``) and attempt to decode it into a Haskell value using ``deserialise`` (the type of which is determined by the choice of the result type).

Throws: ``DeserialiseFailure`` if the file fails to deserialise properly.

Since: 0.2.0.0

## ``Handle`` API

hPutSerialise Source #

Arguments

:: Serialise a |
=> Handle | The ``Handle`` to write to.
-> a | The value to be serialised and written.
-> IO () |

Serialise a ``ByteString`` (via ``serialise``) and write it directly to the specified ``Handle``.

Since: 0.2.0.0