HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulecereal-0.5.8.3Haskell2010

Data.Serialize.Get

The Get monad. A monad for efficiently building structures from strict ByteStrings

Contents
  1. The Get type
  2. Incremental interface
  3. Parsing
  4. Utility
  5. Parsing particular types
  6. ByteStrings
  7. Big-endian reads
  8. Little-endian reads
  9. Host-endian, unaligned reads
  10. Containers
Synopsis
  • Packagecereal-0.5.8.3
  • Exports54
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceGet.hs

The Get type

newtypenewtype Get a

The Get monad is an Exception and State monad.

Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
  • Monad GetDefined in cereal-0.5.8.3 · Data.Serialize.Get
  • Functor GetDefined in cereal-0.5.8.3 · Data.Serialize.Get
  • MonadFail GetDefined in cereal-0.5.8.3 · Data.Serialize.Get
  • Applicative GetDefined in cereal-0.5.8.3 · Data.Serialize.Get
  • Alternative GetDefined in cereal-0.5.8.3 · Data.Serialize.Get
  • MonadPlus GetDefined in cereal-0.5.8.3 · Data.Serialize.Get

Incremental interface

datadata Result r

The result of a parse.

Constructors

  • Fail String ByteString

    The parse failed. The String is the message describing the error, if any.

  • Partial (ByteString -> Result r)

    Supply this continuation with more input so that the parser can resume. To indicate that no more input is available, use an empty string.

  • Done r ByteString

    The parse succeeded. The ByteString is the input that had not yet been consumed (if any) when the parse succeeded.

Instances2Functor, Show
valuerunGetChunk :: Get a -> Maybe Int -> ByteString -> Result a

Run the get monad on a single chunk, providing an optional length for the remaining, unseen input, with Nothing indicating that it's not clear how much input is left. For example, with a lazy ByteString, the optional length represents the sum of the lengths of all remaining chunks.

Parsing

valueisolate :: Int -> Get a -> Get a

Isolate an action to operating within a fixed block of bytes. The action is required to consume all the bytes that it is isolated to.

valueskip :: Int -> Get ()

Skip ahead n bytes. Fails if fewer than n bytes are available.

valueuncheckedSkip :: Int -> Get ()

Skip ahead up to n bytes in the current chunk. No error if there aren't enough bytes, or if less than n bytes are skipped.

valuelookAhead :: Get a -> Get a

Run ga, but return without consuming its input. Fails if ga fails.

Utility

valueremaining :: Get Int

Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed.

WARNING: when run with runGetPartial, remaining will only return the number of bytes that are remaining in the current input.

valueisEmpty :: Get Bool

Test whether all input has been consumed.

WARNING: when run with runGetPartial, isEmpty will only tell you if you're at the end of the current chunk.

Parsing particular types

ByteStrings

An efficient get method for strict ByteStrings. Fails if fewer than n bytes are left in the input. This function creates a fresh copy of the underlying bytes.

Big-endian reads

Little-endian reads

Host-endian, unaligned reads

O(1). Read a single native machine word. The word is read 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.

Containers

valuegetListOf :: Get a -> Get [a]

Get a list in the following format: Word64 (big endian format) element 1 ... element n

valuegetIArrayOf :: (Ix i, IArray a e) => Get i -> Get e -> Get (a i e)

Get an IArray in the following format: index (lower bound) index (upper bound) Word64 (big endian format) element 1 ... element n

valuegetSeqOf :: Get a -> Get (Seq a)

Get a sequence in the following format: Word64 (big endian format) element 1 ... element n

valuegetMaybeOf :: Get a -> Get (Maybe a)

Read in a Maybe in the following format: Word8 (0 for Nothing, anything else for Just) element (when Just)

valuegetEitherOf :: Get a -> Get b -> Get (Either a b)

Read an Either, in the following format: Word8 (0 for Left, anything else for Right) element a when 0, element b otherwise