typed-protocols-stateful
Safe HaskellNone
LanguageHaskell2010

Network.TypedProtocol.Stateful.Driver

Description

Actions for running Peers with a Driver. This module should be imported qualified.

Synopsis

DriverIngerface

data Driver ps (pr :: PeerRole) (bytes :: k) (failure :: k1) dstate (f :: ps -> Type) (m :: Type -> Type) Source #

Constructors

Driver 

Fields

Running a peer

runPeerWithDriver :: forall {k1} {k2} ps (st :: ps) (pr :: PeerRole) (bytes :: k1) (failure :: k2) dstate f m a. MonadSTM m => Driver ps pr bytes failure dstate f m -> f st -> Peer ps pr st f m a -> m (a, dstate) Source #

Run a peer with the given driver.

This runs the peer to completion (if the protocol allows for termination).

NOTE: this function threads local state (i.e. f) through evolution of a protocol (i.e. Peer).

Re-exports

data SomeMessage (st :: ps) where #

When decoding a Message we only know the expected "from" state. We cannot know the "to" state as this depends on the message we decode. To resolve this we use the SomeMessage wrapper which uses an existential type to hide the "to" state.

Constructors

SomeMessage :: forall ps (st :: ps) (st' :: ps). (StateTokenI st, StateTokenI st', ActiveState st) => Message ps st st' -> SomeMessage st 

data DecodeStep bytes failure (m :: Type -> Type) a #

An incremental decoder with return a value of type a.

This interface is not designed to be used directly for implementing decoders, only for running them. In real applications it is expected to use libraries for text or binary decoding and to implement appropriate wrappers to match up with this incremental decoder interface.

This style of interface already closely matches that provided by libraries such as attoparsec for text formats, and binary, cereal and cborg for binary formats.

Constructors

DecodePartial (Maybe bytes -> m (DecodeStep bytes failure m a))

The decoder has consumed the available input and needs more to continue. Provide Just if more input is available and Nothing otherwise, and you will get a new DecodeStep.

DecodeDone a (Maybe bytes)

The decoder has successfully finished. This provides the decoded result value plus any unused input.

DecodeFail failure

The decoder ran into an error. The decoder either used fail or was not provided enough input.