Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Driver ps (pr :: PeerRole) (bytes :: k) (failure :: k1) dstate (f :: ps -> Type) (m :: Type -> Type) = Driver {
- sendMessage :: forall (st :: ps) (st' :: ps). (StateTokenI st, StateTokenI st', ActiveState st) => ReflRelativeAgency (StateAgency st) 'WeHaveAgency (Relative pr (StateAgency st)) -> f st -> Message ps st st' -> m ()
- recvMessage :: forall (st :: ps). (StateTokenI st, ActiveState st) => ReflRelativeAgency (StateAgency st) 'TheyHaveAgency (Relative pr (StateAgency st)) -> f st -> dstate -> m (SomeMessage st, dstate)
- initialDState :: dstate
- 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)
- data SomeMessage (st :: ps) where
- 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
- = DecodePartial (Maybe bytes -> m (DecodeStep bytes failure m a))
- | DecodeDone a (Maybe bytes)
- | DecodeFail failure
DriverIngerface
data Driver ps (pr :: PeerRole) (bytes :: k) (failure :: k1) dstate (f :: ps -> Type) (m :: Type -> Type) Source #
Driver | |
|
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.
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.
DecodePartial (Maybe bytes -> m (DecodeStep bytes failure m a)) | The decoder has consumed the available input and needs more
to continue. Provide |
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
|