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

Modulegrpc-spec-1.0.0Haskell2010

Network.GRPC.Spec.Util.Parser

Incremental parser interface

Intended for qualified import.

import Network.GRPC.Spec.Util.Parser (Parser)
import Network.GRPC.Spec.Util.Parser qualified as Parser
  • 4 types
  • 3 values
  • Packagegrpc-spec-1.0.0
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParser.hs
newtypenewtype Parser e a
#

Simple incremental parser

This is used to parse a stream of values, where we know ahead of time for each value how much data to expect (perhaps based on the previous value). Individual values are not parsed incrementally; see consumeExactly or getExactly.

Instances5Bifunctor, Monad, Functor, MonadFail, Applicative
  • Bifunctor ParserDefined in grpc-spec-1.0.0 · Network.GRPC.Spec.Util.Parser
  • Monad (Parser e)Defined in grpc-spec-1.0.0 · Network.GRPC.Spec.Util.Parser
  • Functor (Parser e)Defined in grpc-spec-1.0.0 · Network.GRPC.Spec.Util.Parser
  • MonadFail (Parser String)Defined in grpc-spec-1.0.0 · Network.GRPC.Spec.Util.Parser
  • Applicative (Parser e)Defined in grpc-spec-1.0.0 · Network.GRPC.Spec.Util.Parser

Construction

2 declarations
valueconsumeExactly
  1. :: Int64

    Length

  2. -> (ByteString -> Either e a)

    Parser

  3. -> Parser e a
#

Consume a specified number of bytes

In order to use the Parser interface we must know for each value exactly how big it will be ahead of time. Typically this will be done by first calling consumeExactly for some kind of fixed size header, indicating how big the value actual value is, which will then inform the next call to consumeExactly.

Execution

4 declarations
typetype IsFinal = Bool
#

Is this the final chunk in the input?

datadata ProcessResult e b
#

Result from processing all chunks in the input

See processAll.

Constructors

  • ProcessError e

    Parse error during processing

  • ProcessedWithFinal b Leftover

    Parsing succeeded (compare to ProcessedWithoutFinal)

  • ProcessedWithoutFinal Leftover

    Parsing succeeded, but we did not recognize the final message on time

    There are two ways that parsing can terminate: the final few chunks may look like this:

    chunk1       -- not marked final
    chunk2       -- not marked final
    chunk3       -- marked final

    or like this:

    chunk1       -- not marked final
    chunk2       -- not marked final
    chunk3       -- not marked final
    empty chunk  -- marked final

    In the former case, we know that we are processing the final message as we are processing it (ProcessedWithFinal); in the latter case, we realize this only after we receive the final empty chunk.

valueprocessAll
  1. :: Monad m
  2. => m (ByteString, IsFinal)

    Get next chunk

  3. -> (a -> m ())

    Process value

  4. -> (a -> m b)

    Process final value

  5. -> Parser e a

    Parser

  6. -> m (ProcessResult e b)
#

Process all incoming data

Returns any unprocessed data. Also returns if we knew that the final result was in fact the final result when we received it (this may or may not be the case, depending on