bytes-0.17.4: Sharing code for serialization between binary and cereal

Copyright | (c) Edward Kmett 2013-2015
License | BSD3
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Bytes.Put

Description

This module generalizes the `binary` `PutM` and `cereal` `PutM` monads in an ad hoc fashion to permit code to be written that is compatible across them.

Moreover, this class permits code to be written to be portable over various monad transformers applied to these as base monads.

Synopsis

- class (Applicative m, Monad m) => MonadPut (m :: Type -> Type) where
  - putWord8 :: Word8 -> m ()
  - putByteString :: ByteString -> m ()
  - putLazyByteString :: ByteString -> m ()
  - flush :: m ()
  - putWord16le :: Word16 -> m ()
  - putWord16be :: Word16 -> m ()
  - putWord16host :: Word16 -> m ()
  - putWord32le :: Word32 -> m ()
  - putWord32be :: Word32 -> m ()
  - putWord32host :: Word32 -> m ()
  - putWord64le :: Word64 -> m ()
  - putWord64be :: Word64 -> m ()
  - putWord64host :: Word64 -> m ()
  - putWordhost :: Word -> m ()
- runPutL :: Put -> ByteString
- runPutS :: Put -> ByteString

# Documentation

class (Applicative m, Monad m) => MonadPut (m :: Type -> Type) where Source #

Minimal complete definition

Nothing

Methods

putWord8 :: Word8 -> m () Source #

Efficiently write a byte into the output buffer

default putWord8 :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word8 -> m () Source #

putByteString :: ByteString -> m () Source #

An efficient primitive to write a strict `ByteString` into the output buffer.

In `binary` this flushes the current buffer, and writes the argument into a new chunk.

default putByteString :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => ByteString -> m () Source #

putLazyByteString :: ByteString -> m () Source #

Write a lazy `ByteString` efficiently.

With `binary`, this simply appends the chunks to the output buffer

default putLazyByteString :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => ByteString -> m () Source #

flush :: m () Source #

Pop the `ByteString` we have constructed so far, if any, yielding a new chunk in the result `ByteString`.

If we're building a strict `ByteString` with `cereal` then this does nothing.

default flush :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => m () Source #

putWord16le :: Word16 -> m () Source #

Write a `Word16` in little endian format

default putWord16le :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word16 -> m () Source #

putWord16be :: Word16 -> m () Source #

Write a `Word16` in big endian format

default putWord16be :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word16 -> m () Source #

putWord16host :: Word16 -> m () Source #

O(1). Write a `Word16` in native host order and host endianness. For portability issues see `putWordhost`.

default putWord16host :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word16 -> m () Source #

putWord32le :: Word32 -> m () Source #

Write a `Word32` in little endian format

default putWord32le :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word32 -> m () Source #

putWord32be :: Word32 -> m () Source #

Write a `Word32` in big endian format

default putWord32be :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word32 -> m () Source #

putWord32host :: Word32 -> m () Source #

O(1). Write a `Word32` in native host order and host endianness. For portability issues see `putWordhost`.

default putWord32host :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word32 -> m () Source #

putWord64le :: Word64 -> m () Source #

Write a `Word64` in little endian format

default putWord64le :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word64 -> m () Source #

putWord64be :: Word64 -> m () Source #

Write a `Word64` in big endian format

default putWord64be :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word64 -> m () Source #

putWord64host :: Word64 -> m () Source #

O(1). Write a `Word64` in native host order and host endianness. For portability issues see `putWordhost`.

default putWord64host :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word64 -> m () Source #

putWordhost :: Word -> m () Source #

O(1). Write a single native machine word. The word is written in host order, host endian form, for the machine you're on. On a 64 bit machine the Word is an 8 byte value, on a 32 bit machine, 4 bytes. Values written this way are not portable to different endian or word sized machines, without conversion.

default putWordhost :: forall (t :: (Type -> Type) -> Type -> Type) (n :: Type -> Type). (m ~ t n, MonadTrans t, MonadPut n) => Word -> m () Source #

#### Instances

Instances details

MonadPut PutM Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> PutM () Source #

putByteString :: ByteString -> PutM () Source #

putLazyByteString :: ByteString -> PutM () Source #

flush :: PutM () Source #

putWord16le :: Word16 -> PutM () Source #

putWord16be :: Word16 -> PutM () Source #

putWord16host :: Word16 -> PutM () Source #

putWord32le :: Word32 -> PutM () Source #

putWord32be :: Word32 -> PutM () Source #

putWord32host :: Word32 -> PutM () Source #

putWord64le :: Word64 -> PutM () Source #

putWord64be :: Word64 -> PutM () Source #

putWord64host :: Word64 -> PutM () Source #

putWordhost :: Word -> PutM () Source #

MonadPut PutM Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> PutM () Source #

putByteString :: ByteString -> PutM () Source #

putLazyByteString :: ByteString -> PutM () Source #

flush :: PutM () Source #

putWord16le :: Word16 -> PutM () Source #

putWord16be :: Word16 -> PutM () Source #

putWord16host :: Word16 -> PutM () Source #

putWord32le :: Word32 -> PutM () Source #

putWord32be :: Word32 -> PutM () Source #

putWord32host :: Word32 -> PutM () Source #

putWord64le :: Word64 -> PutM () Source #

putWord64be :: Word64 -> PutM () Source #

putWord64host :: Word64 -> PutM () Source #

putWordhost :: Word -> PutM () Source #

MonadPut m => MonadPut (ExceptT e m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> ExceptT e m () Source #

putByteString :: ByteString -> ExceptT e m () Source #

putLazyByteString :: ByteString -> ExceptT e m () Source #

flush :: ExceptT e m () Source #

putWord16le :: Word16 -> ExceptT e m () Source #

putWord16be :: Word16 -> ExceptT e m () Source #

putWord16host :: Word16 -> ExceptT e m () Source #

putWord32le :: Word32 -> ExceptT e m () Source #

putWord32be :: Word32 -> ExceptT e m () Source #

putWord32host :: Word32 -> ExceptT e m () Source #

putWord64le :: Word64 -> ExceptT e m () Source #

putWord64be :: Word64 -> ExceptT e m () Source #

putWord64host :: Word64 -> ExceptT e m () Source #

putWordhost :: Word -> ExceptT e m () Source #

MonadPut m => MonadPut (ReaderT e m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> ReaderT e m () Source #

putByteString :: ByteString -> ReaderT e m () Source #

putLazyByteString :: ByteString -> ReaderT e m () Source #

flush :: ReaderT e m () Source #

putWord16le :: Word16 -> ReaderT e m () Source #

putWord16be :: Word16 -> ReaderT e m () Source #

putWord16host :: Word16 -> ReaderT e m () Source #

putWord32le :: Word32 -> ReaderT e m () Source #

putWord32be :: Word32 -> ReaderT e m () Source #

putWord32host :: Word32 -> ReaderT e m () Source #

putWord64le :: Word64 -> ReaderT e m () Source #

putWord64be :: Word64 -> ReaderT e m () Source #

putWord64host :: Word64 -> ReaderT e m () Source #

putWordhost :: Word -> ReaderT e m () Source #

MonadPut m => MonadPut (StateT s m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> StateT s m () Source #

putByteString :: ByteString -> StateT s m () Source #

putLazyByteString :: ByteString -> StateT s m () Source #

flush :: StateT s m () Source #

putWord16le :: Word16 -> StateT s m () Source #

putWord16be :: Word16 -> StateT s m () Source #

putWord16host :: Word16 -> StateT s m () Source #

putWord32le :: Word32 -> StateT s m () Source #

putWord32be :: Word32 -> StateT s m () Source #

putWord32host :: Word32 -> StateT s m () Source #

putWord64le :: Word64 -> StateT s m () Source #

putWord64be :: Word64 -> StateT s m () Source #

putWord64host :: Word64 -> StateT s m () Source #

putWordhost :: Word -> StateT s m () Source #

MonadPut m => MonadPut (StateT s m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> StateT s m () Source #

putByteString :: ByteString -> StateT s m () Source #

putLazyByteString :: ByteString -> StateT s m () Source #

flush :: StateT s m () Source #

putWord16le :: Word16 -> StateT s m () Source #

putWord16be :: Word16 -> StateT s m () Source #

putWord16host :: Word16 -> StateT s m () Source #

putWord32le :: Word32 -> StateT s m () Source #

putWord32be :: Word32 -> StateT s m () Source #

putWord32host :: Word32 -> StateT s m () Source #

putWord64le :: Word64 -> StateT s m () Source #

putWord64be :: Word64 -> StateT s m () Source #

putWord64host :: Word64 -> StateT s m () Source #

putWordhost :: Word -> StateT s m () Source #

(MonadPut m, Monoid w) => MonadPut (WriterT w m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> WriterT w m () Source #

putByteString :: ByteString -> WriterT w m () Source #

putLazyByteString :: ByteString -> WriterT w m () Source #

flush :: WriterT w m () Source #

putWord16le :: Word16 -> WriterT w m () Source #

putWord16be :: Word16 -> WriterT w m () Source #

putWord16host :: Word16 -> WriterT w m () Source #

putWord32le :: Word32 -> WriterT w m () Source #

putWord32be :: Word32 -> WriterT w m () Source #

putWord32host :: Word32 -> WriterT w m () Source #

putWord64le :: Word64 -> WriterT w m () Source #

putWord64be :: Word64 -> WriterT w m () Source #

putWord64host :: Word64 -> WriterT w m () Source #

putWordhost :: Word -> WriterT w m () Source #

(MonadPut m, Monoid w) => MonadPut (WriterT w m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> WriterT w m () Source #

putByteString :: ByteString -> WriterT w m () Source #

putLazyByteString :: ByteString -> WriterT w m () Source #

flush :: WriterT w m () Source #

putWord16le :: Word16 -> WriterT w m () Source #

putWord16be :: Word16 -> WriterT w m () Source #

putWord16host :: Word16 -> WriterT w m () Source #

putWord32le :: Word32 -> WriterT w m () Source #

putWord32be :: Word32 -> WriterT w m () Source #

putWord32host :: Word32 -> WriterT w m () Source #

putWord64le :: Word64 -> WriterT w m () Source #

putWord64be :: Word64 -> WriterT w m () Source #

putWord64host :: Word64 -> WriterT w m () Source #

putWordhost :: Word -> WriterT w m () Source #

(MonadPut m, Monoid w) => MonadPut (RWST r w s m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> RWST r w s m () Source #

putByteString :: ByteString -> RWST r w s m () Source #

putLazyByteString :: ByteString -> RWST r w s m () Source #

flush :: RWST r w s m () Source #

putWord16le :: Word16 -> RWST r w s m () Source #

putWord16be :: Word16 -> RWST r w s m () Source #

putWord16host :: Word16 -> RWST r w s m () Source #

putWord32le :: Word32 -> RWST r w s m () Source #

putWord32be :: Word32 -> RWST r w s m () Source #

putWord32host :: Word32 -> RWST r w s m () Source #

putWord64le :: Word64 -> RWST r w s m () Source #

putWord64be :: Word64 -> RWST r w s m () Source #

putWord64host :: Word64 -> RWST r w s m () Source #

putWordhost :: Word -> RWST r w s m () Source #

(MonadPut m, Monoid w) => MonadPut (RWST r w s m) Source # |

Instance details

Defined in Data.Bytes.Put

Methods

putWord8 :: Word8 -> RWST r w s m () Source #

putByteString :: ByteString -> RWST r w s m () Source #

putLazyByteString :: ByteString -> RWST r w s m () Source #

flush :: RWST r w s m () Source #

putWord16le :: Word16 -> RWST r w s m () Source #

putWord16be :: Word16 -> RWST r w s m () Source #

putWord16host :: Word16 -> RWST r w s m () Source #

putWord32le :: Word32 -> RWST r w s m () Source #

putWord32be :: Word32 -> RWST r w s m () Source #

putWord32host :: Word32 -> RWST r w s m () Source #

putWord64le :: Word64 -> RWST r w s m () Source #

putWord64be :: Word64 -> RWST r w s m () Source #

putWord64host :: Word64 -> RWST r w s m () Source #

putWordhost :: Word -> RWST r w s m () Source #

runPutL :: Put -> ByteString Source #

Put a value into a lazy `ByteString` using `runPut`.

runPutS :: Put -> ByteString Source #

Put a value into a strict `ByteString` using `runPut`.