binary-0.8.5.1: Binary serialisation for Haskell values using lazy ByteStrings

Copyright | Lennart Kolmodin
License | BSD3-style (see LICENSE)
Maintainer | Lennart Kolmodin <kolmodin@gmail.com>
Stability | stable
Portability | Portable to Hugs and GHC. Requires MPTCs
Safe Haskell | Safe
Language | Haskell98

Data.Binary.Put

Contents

- The Put type
- Flushing the implicit parse state
- Primitives
- Big-endian primitives
- Little-endian primitives
- Host-endian, unaligned writes
- Unicode

Description

The Put monad. A monad for efficiently constructing lazy bytestrings.

Synopsis

- type Put = PutM ()
- newtype PutM a = Put {
  - unPut :: PairS a
  }
- runPut :: Put -> ByteString
- runPutM :: PutM a -> (a, ByteString)
- putBuilder :: Builder -> Put
- execPut :: PutM a -> Builder
- flush :: Put
- putWord8 :: Word8 -> Put
- putInt8 :: Int8 -> Put
- putByteString :: ByteString -> Put
- putLazyByteString :: ByteString -> Put
- putShortByteString :: ShortByteString -> Put
- putWord16be :: Word16 -> Put
- putWord32be :: Word32 -> Put
- putWord64be :: Word64 -> Put
- putInt16be :: Int16 -> Put
- putInt32be :: Int32 -> Put
- putInt64be :: Int64 -> Put
- putFloatbe :: Float -> Put
- putDoublebe :: Double -> Put
- putWord16le :: Word16 -> Put
- putWord32le :: Word32 -> Put
- putWord64le :: Word64 -> Put
- putInt16le :: Int16 -> Put
- putInt32le :: Int32 -> Put
- putInt64le :: Int64 -> Put
- putFloatle :: Float -> Put
- putDoublele :: Double -> Put
- putWordhost :: Word -> Put
- putWord16host :: Word16 -> Put
- putWord32host :: Word32 -> Put
- putWord64host :: Word64 -> Put
- putInthost :: Int -> Put
- putInt16host :: Int16 -> Put
- putInt32host :: Int32 -> Put
- putInt64host :: Int64 -> Put
- putFloathost :: Float -> Put
- putDoublehost :: Double -> Put
- putCharUtf8 :: Char -> Put
- putStringUtf8 :: String -> Put

# The Put type

type Put = PutM () #

Put merely lifts Builder into a Writer monad, applied to ().

newtype PutM a #

The PutM type. A Writer monad over the efficient Builder monoid.

Constructors

Put |

Fields

- unPut :: PairS a

Instances

Monad PutM # |
Methods (>>=) :: PutM a -> (a -> PutM b) -> PutM b Source # (>>) :: PutM a -> PutM b -> PutM b Source # return :: a -> PutM a Source # fail :: String -> PutM a Source #
Functor PutM # |
Methods fmap :: (a -> b) -> PutM a -> PutM b Source # (<$) :: a -> PutM b -> PutM a Source #
Applicative PutM # |
Methods pure :: a -> PutM a Source # (<*>) :: PutM (a -> b) -> PutM a -> PutM b Source # liftA2 :: (a -> b -> c) -> PutM a -> PutM b -> PutM c Source # (*>) :: PutM a -> PutM b -> PutM b Source # (<*) :: PutM a -> PutM b -> PutM a Source #
Semigroup (PutM ()) # |
Methods (<>) :: PutM () -> PutM () -> PutM () Source # sconcat :: NonEmpty (PutM ()) -> PutM () Source # stimes :: Integral b => b -> PutM () -> PutM () Source #
Monoid (PutM ()) # |
Methods mempty :: PutM () Source # mappend :: PutM () -> PutM () -> PutM () Source # mconcat :: [PutM ()] -> PutM () Source #

runPut :: Put -> ByteString #

Run the `Put` monad with a serialiser

runPutM :: PutM a -> (a, ByteString) #

Run the `Put` monad with a serialiser and get its result

putBuilder :: Builder -> Put #

execPut :: PutM a -> Builder #

Run the `Put` monad

# Flushing the implicit parse state

flush :: Put #

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

# Primitives

putWord8 :: Word8 -> Put #

Efficiently write a byte into the output buffer

putInt8 :: Int8 -> Put #

Efficiently write a signed byte into the output buffer

putByteString :: ByteString -> Put #

An efficient primitive to write a strict ByteString into the output buffer. It flushes the current buffer, and writes the argument into a new chunk.

putLazyByteString :: ByteString -> Put #

Write a lazy ByteString efficiently, simply appending the lazy ByteString chunks to the output buffer

putShortByteString :: ShortByteString -> Put #

Write `ShortByteString` to the buffer

# Big-endian primitives

putWord16be :: Word16 -> Put #

Write a Word16 in big endian format

putWord32be :: Word32 -> Put #

Write a Word32 in big endian format

putWord64be :: Word64 -> Put #

Write a Word64 in big endian format

putInt16be :: Int16 -> Put #

Write an Int16 in big endian format

putInt32be :: Int32 -> Put #

Write an Int32 in big endian format

putInt64be :: Int64 -> Put #

Write an Int64 in big endian format

putFloatbe :: Float -> Put #

Write a `Float` in big endian IEEE-754 format.

putDoublebe :: Double -> Put #

Write a `Double` in big endian IEEE-754 format.

# Little-endian primitives

putWord16le :: Word16 -> Put #

Write a Word16 in little endian format

putWord32le :: Word32 -> Put #

Write a Word32 in little endian format

putWord64le :: Word64 -> Put #

Write a Word64 in little endian format

putInt16le :: Int16 -> Put #

Write an Int16 in little endian format

putInt32le :: Int32 -> Put #

Write an Int32 in little endian format

putInt64le :: Int64 -> Put #

Write an Int64 in little endian format

putFloatle :: Float -> Put #

Write a `Float` in little endian IEEE-754 format.

putDoublele :: Double -> Put #

Write a `Double` in little endian IEEE-754 format.

# Host-endian, unaligned writes

putWordhost :: Word -> Put #

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.

putWord16host :: Word16 -> Put #

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

putWord32host :: Word32 -> Put #

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

putWord64host :: Word64 -> Put #

O(1). Write a Word64 in native host order On a 32 bit machine we write two host order Word32s, in big endian form. For portability issues see `putWordhost`.

putInthost :: Int -> Put #

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

putInt16host :: Int16 -> Put #

O(1). Write an Int16 in native host order and host endianness. For portability issues see `putInthost`.

putInt32host :: Int32 -> Put #

O(1). Write an Int32 in native host order and host endianness. For portability issues see `putInthost`.

putInt64host :: Int64 -> Put #

O(1). Write an Int64 in native host order On a 32 bit machine we write two host order Int32s, in big endian form. For portability issues see `putInthost`.

putFloathost :: Float -> Put #

Write a `Float` in native in IEEE-754 format and host endian.

putDoublehost :: Double -> Put #

Write a `Double` in native in IEEE-754 format and host endian.

# Unicode

putCharUtf8 :: Char -> Put #

Write a character using UTF-8 encoding.

putStringUtf8 :: String -> Put #

Write a String using UTF-8 encoding.