Skip to content

Commit cd80ff7

Browse files
authored
Merge pull request #60 from input-output-hk/coot/stateful-req-resp
coot/stateful req resp
2 parents f1abe95 + 3eb3f62 commit cd80ff7

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

typed-protocols-examples/src/Network/TypedProtocol/Stateful/ReqResp/Client.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ reqRespClientPeer (SendMsgDone a) =
3535
reqRespClientPeer (SendMsgReq req next) =
3636
Yield (StateBusy req)
3737
(MsgReq req) $
38-
Await $ \_ (MsgResp resp) ->
38+
Await $ \_ (MsgResp _ resp) ->
3939
let client = next resp
4040
in ( Effect $ reqRespClientPeer <$> client
4141
, StateIdle

typed-protocols-examples/src/Network/TypedProtocol/Stateful/ReqResp/Codec.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ codecReqResp
2929
-- ^ encode `req resp`
3030
-> (String -> Maybe (Some req))
3131
-- ^ decode `req resp`
32-
-> (forall resp. resp -> String)
32+
-> (forall resp. req resp -> resp -> String)
3333
-- ^ encode resp
3434
-> (forall resp. req resp -> String -> Maybe resp)
3535
-- ^ decode resp
@@ -40,9 +40,9 @@ codecReqResp encodeReq decodeReq encodeResp decodeResp =
4040
encode :: State st'
4141
-> Message (ReqResp req) st st'
4242
-> String
43-
encode _ (MsgReq req) = "MsgReq " ++ encodeReq req ++ "\n"
44-
encode _ MsgDone = "MsgDone\n"
45-
encode _ (MsgResp resp) = "MsgResp " ++ encodeResp resp ++ "\n"
43+
encode _ (MsgReq req) = "MsgReq " ++ encodeReq req ++ "\n"
44+
encode _ MsgDone = "MsgDone\n"
45+
encode _ (MsgResp req resp) = "MsgResp " ++ encodeResp req resp ++ "\n"
4646

4747
decode :: forall (st :: ReqResp req).
4848
ActiveState st
@@ -60,7 +60,7 @@ codecReqResp encodeReq decodeReq encodeResp decodeResp =
6060
(SingBusy, StateBusy req, ("MsgResp", str'))
6161
-- note that we need `req` to decode response of the given type
6262
| Just resp <- decodeResp req str'
63-
-> DecodeDone (SomeMessage (MsgResp resp)) trailing
63+
-> DecodeDone (SomeMessage (MsgResp req resp)) trailing
6464
(_, _, _) -> DecodeFail failure
6565
where failure = CodecFailure ("unexpected server message: " ++ str)
6666

@@ -95,7 +95,7 @@ codecReqRespId eqRespTypes = Codec { encode, decode }
9595
-> DecodeDone (SomeMessage msg) Nothing
9696
(SingIdle, StateIdle, Just (Bytes msg@MsgReq{}))
9797
-> DecodeDone (SomeMessage msg) Nothing
98-
(SingBusy, StateBusy req, Just (Bytes msg@(MsgResp _)))
98+
(SingBusy, StateBusy req, Just (Bytes msg@MsgResp{}))
9999
-- the codec needs to verify that response type of `req` and `msg` agrees
100100
| Just Refl <- eqRespTypes (reqRespType req) (msgRespType msg)
101101
-> DecodeDone (SomeMessage msg) Nothing
@@ -106,7 +106,7 @@ codecReqRespId eqRespTypes = Codec { encode, decode }
106106

107107
msgRespType :: forall resp. Message (ReqResp FileAPI) (StBusy resp) StIdle
108108
-> Proxy resp
109-
msgRespType (MsgResp _) = Proxy
109+
msgRespType (MsgResp _ _) = Proxy
110110

111111
reqRespType :: forall resp. FileAPI resp -> Proxy resp
112112
reqRespType _ = Proxy

typed-protocols-examples/src/Network/TypedProtocol/Stateful/ReqResp/Server.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ reqRespServerPeer ReqRespServer { reqRespServerDone = a,
3030
MsgDone -> (Done a, StateDone)
3131
MsgReq req ->
3232
( Effect $
33-
(\(resp, k') -> Yield StateIdle (MsgResp resp) (reqRespServerPeer k'))
33+
(\(resp, k') -> Yield StateIdle (MsgResp req resp) (reqRespServerPeer k'))
3434
<$> k req
3535
, StateBusy req
3636
)

typed-protocols-examples/src/Network/TypedProtocol/Stateful/ReqResp/Type.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ instance Protocol (ReqResp req) where
5454
-- promoted to the state `StBusy` state.
5555
-> Message (ReqResp req) StIdle (StBusy resp)
5656
MsgResp :: Typeable resp
57-
=> resp -- ^ respond type
57+
=> req resp -- ^ request, not sent over the wire, just useful in the
58+
-- codec.
59+
--
60+
-- TODO: https://github.com/input-output-hk/typed-protocols/issues/59
61+
62+
-> resp -- ^ respond
5863
-> Message (ReqResp req) (StBusy resp) StIdle
5964
MsgDone :: Message (ReqResp req) StIdle StDone
6065

typed-protocols-examples/typed-protocols-examples.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: typed-protocols-examples
3-
version: 0.3.0.0
3+
version: 0.4.0.0
44
synopsis: Examples and tests for the typed-protocols framework
55
-- description:
66
license: Apache-2.0

0 commit comments

Comments
 (0)