serialise-0.2.6.1: 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 | None
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 #

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 #

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 #

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

Since: 0.2.0.0

# Deserialisation exceptions

data DeserialiseFailure #

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

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

# 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 #

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) #

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 #

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 #

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 #

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 #

decode :: Decoder s a #

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

Since: 0.2.0.0

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

encodeList :: [a] -> Encoding #

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] #

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 ByteString # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ByteString -> Encoding # decode :: Decoder s ByteString # encodeList :: [ByteString] -> Encoding # decodeList :: Decoder s [ByteString] #
Serialise ByteString # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ByteString -> Encoding # decode :: Decoder s ByteString # encodeList :: [ByteString] -> Encoding # decodeList :: Decoder s [ByteString] #
Serialise ShortByteString # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ShortByteString -> Encoding # decode :: Decoder s ShortByteString # encodeList :: [ShortByteString] -> Encoding # decodeList :: Decoder s [ShortByteString] #
Serialise Term # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Term -> Encoding # decode :: Decoder s Term # encodeList :: [Term] -> Encoding # decodeList :: Decoder s [Term] #
Serialise IntSet # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: IntSet -> Encoding # decode :: Decoder s IntSet # encodeList :: [IntSet] -> Encoding # decodeList :: Decoder s [IntSet] #
Serialise Void # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Void -> Encoding # decode :: Decoder s Void # encodeList :: [Void] -> Encoding # decodeList :: Decoder s [Void] #
Serialise All # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: All -> Encoding # decode :: Decoder s All # encodeList :: [All] -> Encoding # decodeList :: Decoder s [All] #
Serialise Any # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Any -> Encoding # decode :: Decoder s Any # encodeList :: [Any] -> Encoding # decodeList :: Decoder s [Any] #
Serialise SomeTypeRep # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: SomeTypeRep -> Encoding # decode :: Decoder s SomeTypeRep # encodeList :: [SomeTypeRep] -> Encoding # decodeList :: Decoder s [SomeTypeRep] #
Serialise Version # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Version -> Encoding # decode :: Decoder s Version # encodeList :: [Version] -> Encoding # decodeList :: Decoder s [Version] #
Serialise Fingerprint # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Fingerprint -> Encoding # decode :: Decoder s Fingerprint # encodeList :: [Fingerprint] -> Encoding # decodeList :: Decoder s [Fingerprint] #
Serialise CChar # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CChar -> Encoding # decode :: Decoder s CChar # encodeList :: [CChar] -> Encoding # decodeList :: Decoder s [CChar] #
Serialise CClock # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CClock -> Encoding # decode :: Decoder s CClock # encodeList :: [CClock] -> Encoding # decodeList :: Decoder s [CClock] #
Serialise CDouble # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CDouble -> Encoding # decode :: Decoder s CDouble # encodeList :: [CDouble] -> Encoding # decodeList :: Decoder s [CDouble] #
Serialise CFloat # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CFloat -> Encoding # decode :: Decoder s CFloat # encodeList :: [CFloat] -> Encoding # decodeList :: Decoder s [CFloat] #
Serialise CInt # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CInt -> Encoding # decode :: Decoder s CInt # encodeList :: [CInt] -> Encoding # decodeList :: Decoder s [CInt] #
Serialise CIntMax # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CIntMax -> Encoding # decode :: Decoder s CIntMax # encodeList :: [CIntMax] -> Encoding # decodeList :: Decoder s [CIntMax] #
Serialise CIntPtr # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CIntPtr -> Encoding # decode :: Decoder s CIntPtr # encodeList :: [CIntPtr] -> Encoding # decodeList :: Decoder s [CIntPtr] #
Serialise CLLong # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CLLong -> Encoding # decode :: Decoder s CLLong # encodeList :: [CLLong] -> Encoding # decodeList :: Decoder s [CLLong] #
Serialise CLong # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CLong -> Encoding # decode :: Decoder s CLong # encodeList :: [CLong] -> Encoding # decodeList :: Decoder s [CLong] #
Serialise CPtrdiff # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CPtrdiff -> Encoding # decode :: Decoder s CPtrdiff # encodeList :: [CPtrdiff] -> Encoding # decodeList :: Decoder s [CPtrdiff] #
Serialise CSChar # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSChar -> Encoding # decode :: Decoder s CSChar # encodeList :: [CSChar] -> Encoding # decodeList :: Decoder s [CSChar] #
Serialise CSUSeconds # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSUSeconds -> Encoding # decode :: Decoder s CSUSeconds # encodeList :: [CSUSeconds] -> Encoding # decodeList :: Decoder s [CSUSeconds] #
Serialise CShort # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CShort -> Encoding # decode :: Decoder s CShort # encodeList :: [CShort] -> Encoding # decodeList :: Decoder s [CShort] #
Serialise CSigAtomic # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSigAtomic -> Encoding # decode :: Decoder s CSigAtomic # encodeList :: [CSigAtomic] -> Encoding # decodeList :: Decoder s [CSigAtomic] #
Serialise CSize # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CSize -> Encoding # decode :: Decoder s CSize # encodeList :: [CSize] -> Encoding # decodeList :: Decoder s [CSize] #
Serialise CTime # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CTime -> Encoding # decode :: Decoder s CTime # encodeList :: [CTime] -> Encoding # decodeList :: Decoder s [CTime] #
Serialise CUChar # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUChar -> Encoding # decode :: Decoder s CUChar # encodeList :: [CUChar] -> Encoding # decodeList :: Decoder s [CUChar] #
Serialise CUInt # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUInt -> Encoding # decode :: Decoder s CUInt # encodeList :: [CUInt] -> Encoding # decodeList :: Decoder s [CUInt] #
Serialise CUIntMax # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUIntMax -> Encoding # decode :: Decoder s CUIntMax # encodeList :: [CUIntMax] -> Encoding # decodeList :: Decoder s [CUIntMax] #
Serialise CUIntPtr # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUIntPtr -> Encoding # decode :: Decoder s CUIntPtr # encodeList :: [CUIntPtr] -> Encoding # decodeList :: Decoder s [CUIntPtr] #
Serialise CULLong # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CULLong -> Encoding # decode :: Decoder s CULLong # encodeList :: [CULLong] -> Encoding # decodeList :: Decoder s [CULLong] #
Serialise CULong # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CULong -> Encoding # decode :: Decoder s CULong # encodeList :: [CULong] -> Encoding # decodeList :: Decoder s [CULong] #
Serialise CUSeconds # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUSeconds -> Encoding # decode :: Decoder s CUSeconds # encodeList :: [CUSeconds] -> Encoding # decodeList :: Decoder s [CUSeconds] #
Serialise CUShort # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CUShort -> Encoding # decode :: Decoder s CUShort # encodeList :: [CUShort] -> Encoding # decodeList :: Decoder s [CUShort] #
Serialise CWchar # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: CWchar -> Encoding # decode :: Decoder s CWchar # encodeList :: [CWchar] -> Encoding # decodeList :: Decoder s [CWchar] #
Serialise ExitCode # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ExitCode -> Encoding # decode :: Decoder s ExitCode # encodeList :: [ExitCode] -> Encoding # decodeList :: Decoder s [ExitCode] #
Serialise Int16 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int16 -> Encoding # decode :: Decoder s Int16 # encodeList :: [Int16] -> Encoding # decodeList :: Decoder s [Int16] #
Serialise Int32 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int32 -> Encoding # decode :: Decoder s Int32 # encodeList :: [Int32] -> Encoding # decodeList :: Decoder s [Int32] #
Serialise Int64 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int64 -> Encoding # decode :: Decoder s Int64 # encodeList :: [Int64] -> Encoding # decodeList :: Decoder s [Int64] #
Serialise Int8 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int8 -> Encoding # decode :: Decoder s Int8 # encodeList :: [Int8] -> Encoding # decodeList :: Decoder s [Int8] #
Serialise Word16 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word16 -> Encoding # decode :: Decoder s Word16 # encodeList :: [Word16] -> Encoding # decodeList :: Decoder s [Word16] #
Serialise Word32 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word32 -> Encoding # decode :: Decoder s Word32 # encodeList :: [Word32] -> Encoding # decodeList :: Decoder s [Word32] #
Serialise Word64 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word64 -> Encoding # decode :: Decoder s Word64 # encodeList :: [Word64] -> Encoding # decodeList :: Decoder s [Word64] #
Serialise Word8 # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word8 -> Encoding # decode :: Decoder s Word8 # encodeList :: [Word8] -> Encoding # decodeList :: Decoder s [Word8] #
Serialise KindRep # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: KindRep -> Encoding # decode :: Decoder s KindRep # encodeList :: [KindRep] -> Encoding # decodeList :: Decoder s [KindRep] #
Serialise Ordering # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Ordering -> Encoding # decode :: Decoder s Ordering # encodeList :: [Ordering] -> Encoding # decodeList :: Decoder s [Ordering] #
Serialise TyCon # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TyCon -> Encoding # decode :: Decoder s TyCon # encodeList :: [TyCon] -> Encoding # decodeList :: Decoder s [TyCon] #
Serialise TypeLitSort # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TypeLitSort -> Encoding # decode :: Decoder s TypeLitSort # encodeList :: [TypeLitSort] -> Encoding # decodeList :: Decoder s [TypeLitSort] #
Serialise Half # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Half -> Encoding # decode :: Decoder s Half # encodeList :: [Half] -> Encoding # decodeList :: Decoder s [Half] #
Serialise Text # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Text -> Encoding # decode :: Decoder s Text # encodeList :: [Text] -> Encoding # decodeList :: Decoder s [Text] #
Serialise Text # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Text -> Encoding # decode :: Decoder s Text # encodeList :: [Text] -> Encoding # decodeList :: Decoder s [Text] #
Serialise UTCTime # | `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 # decode :: Decoder s UTCTime # encodeList :: [UTCTime] -> Encoding # decodeList :: Decoder s [UTCTime] #
Serialise Integer # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Integer -> Encoding # decode :: Decoder s Integer # encodeList :: [Integer] -> Encoding # decodeList :: Decoder s [Integer] #
Serialise Natural # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Natural -> Encoding # decode :: Decoder s Natural # encodeList :: [Natural] -> Encoding # decodeList :: Decoder s [Natural] #
Serialise () # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: () -> Encoding # decode :: Decoder s () # encodeList :: [()] -> Encoding # decodeList :: Decoder s [()] #
Serialise Bool # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Bool -> Encoding # decode :: Decoder s Bool # encodeList :: [Bool] -> Encoding # decodeList :: Decoder s [Bool] #
Serialise Char # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Char -> Encoding # decode :: Decoder s Char # encodeList :: [Char] -> Encoding # decodeList :: Decoder s [Char] #
Serialise Double # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Double -> Encoding # decode :: Decoder s Double # encodeList :: [Double] -> Encoding # decodeList :: Decoder s [Double] #
Serialise Float # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Float -> Encoding # decode :: Decoder s Float # encodeList :: [Float] -> Encoding # decodeList :: Decoder s [Float] #
Serialise Int # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Int -> Encoding # decode :: Decoder s Int # encodeList :: [Int] -> Encoding # decodeList :: Decoder s [Int] #
Serialise Levity # | Since: 0.2.6.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Levity -> Encoding # decode :: Decoder s Levity # encodeList :: [Levity] -> Encoding # decodeList :: Decoder s [Levity] #
Serialise RuntimeRep # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: RuntimeRep -> Encoding # decode :: Decoder s RuntimeRep # encodeList :: [RuntimeRep] -> Encoding # decodeList :: Decoder s [RuntimeRep] #
Serialise VecCount # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: VecCount -> Encoding # decode :: Decoder s VecCount # encodeList :: [VecCount] -> Encoding # decodeList :: Decoder s [VecCount] #
Serialise VecElem # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: VecElem -> Encoding # decode :: Decoder s VecElem # encodeList :: [VecElem] -> Encoding # decodeList :: Decoder s [VecElem] #
Serialise Word # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Word -> Encoding # decode :: Decoder s Word # encodeList :: [Word] -> Encoding # decodeList :: Decoder s [Word] #
Serialise a => Serialise (Complex a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Complex a -> Encoding # decode :: Decoder s (Complex a) # encodeList :: [Complex a] -> Encoding # decodeList :: Decoder s [Complex a] #
Serialise a => Serialise (First a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: First a -> Encoding # decode :: Decoder s (First a) # encodeList :: [First a] -> Encoding # decodeList :: Decoder s [First a] #
Serialise a => Serialise (Last a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Last a -> Encoding # decode :: Decoder s (Last a) # encodeList :: [Last a] -> Encoding # decodeList :: Decoder s [Last a] #
Serialise a => Serialise (Max a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Max a -> Encoding # decode :: Decoder s (Max a) # encodeList :: [Max a] -> Encoding # decodeList :: Decoder s [Max a] #
Serialise a => Serialise (Min a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Min a -> Encoding # decode :: Decoder s (Min a) # encodeList :: [Min a] -> Encoding # decodeList :: Decoder s [Min a] #
Serialise a => Serialise (WrappedMonoid a) # |
Instance details Defined in Codec.Serialise.Class Methods encode :: WrappedMonoid a -> Encoding # decode :: Decoder s (WrappedMonoid a) # encodeList :: [WrappedMonoid a] -> Encoding # decodeList :: Decoder s [WrappedMonoid a] #
Serialise a => Serialise (IntMap a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: IntMap a -> Encoding # decode :: Decoder s (IntMap a) # encodeList :: [IntMap a] -> Encoding # decodeList :: Decoder s [IntMap a] #
Serialise a => Serialise (Seq a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Seq a -> Encoding # decode :: Decoder s (Seq a) # encodeList :: [Seq a] -> Encoding # decodeList :: Decoder s [Seq a] #
(Ord a, Serialise a) => Serialise (Set a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Set a -> Encoding # decode :: Decoder s (Set a) # encodeList :: [Set a] -> Encoding # decodeList :: Decoder s [Set a] #
Serialise a => Serialise (Tree a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Tree a -> Encoding # decode :: Decoder s (Tree a) # encodeList :: [Tree a] -> Encoding # decodeList :: Decoder s [Tree a] #
Serialise a => Serialise (NonEmpty a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: NonEmpty a -> Encoding # decode :: Decoder s (NonEmpty a) # encodeList :: [NonEmpty a] -> Encoding # decodeList :: Decoder s [NonEmpty a] #
Serialise a => Serialise (Identity a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Identity a -> Encoding # decode :: Decoder s (Identity a) # encodeList :: [Identity a] -> Encoding # decodeList :: Decoder s [Identity a] #
Serialise a => Serialise (First a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: First a -> Encoding # decode :: Decoder s (First a) # encodeList :: [First a] -> Encoding # decodeList :: Decoder s [First a] #
Serialise a => Serialise (Last a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Last a -> Encoding # decode :: Decoder s (Last a) # encodeList :: [Last a] -> Encoding # decodeList :: Decoder s [Last a] #
Serialise a => Serialise (Down a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Down a -> Encoding # decode :: Decoder s (Down a) # encodeList :: [Down a] -> Encoding # decodeList :: Decoder s [Down a] #
Serialise a => Serialise (Dual a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Dual a -> Encoding # decode :: Decoder s (Dual a) # encodeList :: [Dual a] -> Encoding # decodeList :: Decoder s [Dual a] #
Serialise a => Serialise (Product a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Product a -> Encoding # decode :: Decoder s (Product a) # encodeList :: [Product a] -> Encoding # decodeList :: Decoder s [Product a] #
Serialise a => Serialise (Sum a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Sum a -> Encoding # decode :: Decoder s (Sum a) # encodeList :: [Sum a] -> Encoding # decodeList :: Decoder s [Sum a] #
Serialise a => Serialise (ZipList a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: ZipList a -> Encoding # decode :: Decoder s (ZipList a) # encodeList :: [ZipList a] -> Encoding # decodeList :: Decoder s [ZipList a] #
(Serialise a, Integral a) => Serialise (Ratio a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Ratio a -> Encoding # decode :: Decoder s (Ratio a) # encodeList :: [Ratio a] -> Encoding # decodeList :: Decoder s [Ratio a] #
Serialise a => Serialise (Maybe a) # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Maybe a -> Encoding # decode :: Decoder s (Maybe a) # encodeList :: [Maybe a] -> Encoding # decodeList :: Decoder s [Maybe a] #
(Serialise a, Hashable a, Eq a) => Serialise (HashSet a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: HashSet a -> Encoding # decode :: Decoder s (HashSet a) # encodeList :: [HashSet a] -> Encoding # decodeList :: Decoder s [HashSet a] #
Serialise a => Serialise (Vector a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding # decode :: Decoder s (Vector a) # encodeList :: [Vector a] -> Encoding # decodeList :: Decoder s [Vector a] #
(Serialise a, Prim a) => Serialise (Vector a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding # decode :: Decoder s (Vector a) # encodeList :: [Vector a] -> Encoding # decodeList :: Decoder s [Vector a] #
(Serialise a, Storable a) => Serialise (Vector a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding # decode :: Decoder s (Vector a) # encodeList :: [Vector a] -> Encoding # decodeList :: Decoder s [Vector a] #
(Serialise a, Unbox a) => Serialise (Vector a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Vector a -> Encoding # decode :: Decoder s (Vector a) # encodeList :: [Vector a] -> Encoding # decodeList :: Decoder s [Vector a] #
Serialise a => Serialise (Maybe a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Maybe a -> Encoding # decode :: Decoder s (Maybe a) # encodeList :: [Maybe a] -> Encoding # decodeList :: Decoder s [Maybe a] #
Serialise a => Serialise [a] # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: [a] -> Encoding # decode :: Decoder s [a] # encodeList :: [[a]] -> Encoding # decodeList :: Decoder s [[a]] #
Serialise (Fixed e) # | 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 # decode :: Decoder s (Fixed e) # encodeList :: [Fixed e] -> Encoding # decodeList :: Decoder s [Fixed e] #
(Ord k, Serialise k, Serialise v) => Serialise (Map k v) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Map k v -> Encoding # decode :: Decoder s (Map k v) # encodeList :: [Map k v] -> Encoding # decodeList :: Decoder s [Map k v] #
(Serialise a, Serialise b) => Serialise (Either a b) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Either a b -> Encoding # decode :: Decoder s (Either a b) # encodeList :: [Either a b] -> Encoding # decodeList :: Decoder s [Either a b] #
Serialise (Proxy a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Proxy a -> Encoding # decode :: Decoder s (Proxy a) # encodeList :: [Proxy a] -> Encoding # decodeList :: Decoder s [Proxy a] #
Typeable a => Serialise (TypeRep a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: TypeRep a -> Encoding # decode :: Decoder s (TypeRep a) # encodeList :: [TypeRep a] -> Encoding # decodeList :: Decoder s [TypeRep a] #
(Serialise a, Serialise b) => Serialise (Either a b) # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Either a b -> Encoding # decode :: Decoder s (Either a b) # encodeList :: [Either a b] -> Encoding # decodeList :: Decoder s [Either a b] #
(Serialise a, Serialise b) => Serialise (These a b) # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: These a b -> Encoding # decode :: Decoder s (These a b) # encodeList :: [These a b] -> Encoding # decodeList :: Decoder s [These a b] #
(Serialise a, Serialise b) => Serialise (Pair a b) # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Pair a b -> Encoding # decode :: Decoder s (Pair a b) # encodeList :: [Pair a b] -> Encoding # decodeList :: Decoder s [Pair a b] #
(Serialise a, Serialise b) => Serialise (These a b) # | Since: 0.2.4.0
Instance details Defined in Codec.Serialise.Class Methods encode :: These a b -> Encoding # decode :: Decoder s (These a b) # encodeList :: [These a b] -> Encoding # decodeList :: Decoder s [These a b] #
(Serialise k, Hashable k, Eq k, Serialise v) => Serialise (HashMap k v) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: HashMap k v -> Encoding # decode :: Decoder s (HashMap k v) # encodeList :: [HashMap k v] -> Encoding # decodeList :: Decoder s [HashMap k v] #
(Serialise a, Serialise b) => Serialise (a, b) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b) -> Encoding # decode :: Decoder s (a, b) # encodeList :: [(a, b)] -> Encoding # decodeList :: Decoder s [(a, b)] #
Serialise a => Serialise (Const a b) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Const a b -> Encoding # decode :: Decoder s (Const a b) # encodeList :: [Const a b] -> Encoding # decodeList :: Decoder s [Const a b] #
Serialise (f a) => Serialise (Alt f a) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: Alt f a -> Encoding # decode :: Decoder s (Alt f a) # encodeList :: [Alt f a] -> Encoding # decodeList :: Decoder s [Alt f a] #
(Serialise a, Serialise b, Serialise c) => Serialise (a, b, c) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c) -> Encoding # decode :: Decoder s (a, b, c) # encodeList :: [(a, b, c)] -> Encoding # decodeList :: Decoder s [(a, b, c)] #
(Serialise a, Serialise b, Serialise c, Serialise d) => Serialise (a, b, c, d) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d) -> Encoding # decode :: Decoder s (a, b, c, d) # encodeList :: [(a, b, c, d)] -> Encoding # decodeList :: Decoder s [(a, b, c, d)] #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e) => Serialise (a, b, c, d, e) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e) -> Encoding # decode :: Decoder s (a, b, c, d, e) # encodeList :: [(a, b, c, d, e)] -> Encoding # decodeList :: Decoder s [(a, b, c, d, e)] #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f) => Serialise (a, b, c, d, e, f) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f) -> Encoding # decode :: Decoder s (a, b, c, d, e, f) # encodeList :: [(a, b, c, d, e, f)] -> Encoding # decodeList :: Decoder s [(a, b, c, d, e, f)] #
(Serialise a, Serialise b, Serialise c, Serialise d, Serialise e, Serialise f, Serialise g) => Serialise (a, b, c, d, e, f, g) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g) -> Encoding # decode :: Decoder s (a, b, c, d, e, f, g) # encodeList :: [(a, b, c, d, e, f, g)] -> Encoding # decodeList :: Decoder s [(a, b, c, d, e, f, g)] #
(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) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g, h) -> Encoding # decode :: Decoder s (a, b, c, d, e, f, g, h) # encodeList :: [(a, b, c, d, e, f, g, h)] -> Encoding # decodeList :: Decoder s [(a, b, c, d, e, f, g, h)] #
(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) # | Since: 0.2.0.0
Instance details Defined in Codec.Serialise.Class Methods encode :: (a, b, c, d, e, f, g, h, i) -> Encoding # decode :: Decoder s (a, b, c, d, e, f, g, h, i) # encodeList :: [(a, b, c, d, e, f, g, h, i)] -> Encoding # decodeList :: Decoder s [(a, b, c, d, e, f, g, h, i)] #

# IO operations

Convenient utilities for basic ``IO`` operations.

## ``FilePath`` API

writeFileSerialise #

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 #

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 #

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