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

Modulecereal-0.5.8.3Haskell2010

Data.Serialize.Get

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

  • 2 types
  • 52 values
  • Packagecereal-0.5.8.3
  • Exports54
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceGet.hs

The Get type

5 declarations
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
valuerunGetLazy :: Get a -> ByteString -> Either String a
#

Run the Get monad over a Lazy ByteString. Note that this will not run the Get parser lazily, but will operate on lazy ByteStrings.

valuerunGetState :: Get a -> ByteString -> Int -> Either String (a, ByteString)
#

Run the Get monad applies a get-based parser on the input ByteString, starting at the specified offset. In addition to the result of get it returns the rest of the input.

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

10 declarations
valueensure :: Int -> Get ByteString
#

If at least n bytes of input are available, return the current input, otherwise fail.

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

3 declarations
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

2 declarations

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

valuegetWordhost :: Get Word
#

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

valuegetNested :: Get Int -> Get a -> Get a
#

Read in a length and then read a nested structure of that length.