HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulememory-0.18.0Haskell2010

Data.ByteArray.Pack

Simple Byte Array packer

Simple example:

> flip pack 20 $ putWord8 0x41 >> putByteString "BCD" >> putWord8 0x20 >> putStorable (42 :: Word32)
Right (ABCD *\NUL\NUL\NUL")

Original code from https://hackage.haskell.org/package/bspack generalized and adapted to run on memory, and spellchecked / tweaked. (2015-05) Copyright (c) 2014 Nicolas DI PRIMA

  • 2 types
  • 11 values
  • Packagememory-0.18.0
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourcePack.hs
newtypenewtype Packer a
#

Simple ByteArray Packer

Instances3Monad, Functor, Applicative
  • Monad PackerDefined in memory-0.18.0 · Data.ByteArray.Pack.Internal
  • Functor PackerDefined in memory-0.18.0 · Data.ByteArray.Pack.Internal
  • Applicative PackerDefined in memory-0.18.0 · Data.ByteArray.Pack.Internal
datadata Result a
#

Packing result:

  • PackerMore: the next state of Packing with an arbitrary value

  • PackerFail: an error happened

Instances1Show
  • Show a => Show (Result a)Defined in memory-0.18.0 · Data.ByteArray.Pack.Internal

Operations

0 declarations

put

valueputWord16 :: Word16 -> Packer ()
#

put Word16 in the current position in the stream /! use Host Endianness

valueputWord32 :: Word32 -> Packer ()
#

put Word32 in the current position in the stream /! use Host Endianness

valueputBytes :: ByteArrayAccess ba => ba -> Packer ()
#

Put a Byte Array from the current position in the stream

If the ByteArray is null, then do nothing

valuefillList :: Storable storable => [storable] -> Packer ()
#

Will put the given storable list from the current position in the stream to the end.

This function will fail with not enough storage if the given storable can't be written (not enough space)

Example:

> pack (fillList $ [1..] :: Word8) 9
"\1\2\3\4\5\6\7\8\9"
> pack (fillList $ [1..] :: Word32) 4
"\1\0\0\0"
> pack (fillList $ [1..] :: Word32) 64
.. <..succesful..>
> pack (fillList $ [1..] :: Word32) 1
.. <.. not enough space ..>
> pack (fillList $ [1..] :: Word32) 131
.. <.. not enough space ..>
valuefillUpWith :: Storable storable => storable -> Packer ()
#

Fill up from the current position in the stream to the end

It is equivalent to:

fillUpWith s == fillList (repeat s)

skip

valueskip :: Int -> Packer ()
#

Skip some bytes from the current position in the stream

valueskipStorable :: Storable storable => storable -> Packer ()
#

Skip the size of a storable from the current position in the stream