-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af5c305
commit 421ffac
Showing
18 changed files
with
139 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Hydra.Network.Ouroboros.Codec where | ||
|
||
import Hydra.Prelude | ||
|
||
import Cardano.Binary qualified as CBOR | ||
import Codec.CBOR.Read qualified as CBOR | ||
import Network.TypedProtocol.Codec | ||
import Network.TypedProtocol.Codec.CBOR (mkCodecCborLazyBS) | ||
import Network.TypedProtocol.Core | ||
import Hydra.Network.Ouroboros.Type (FireForget(..), SFireForget(..), Message(..)) | ||
|
||
codecFireForget :: | ||
forall m msg. | ||
(MonadST m, FromCBOR msg, ToCBOR msg) => | ||
Codec (FireForget msg) CBOR.DeserialiseFailure m LByteString | ||
codecFireForget = | ||
mkCodecCborLazyBS encode decode | ||
where | ||
encode :: | ||
forall msg' (st :: FireForget msg') (st' :: FireForget msg'). | ||
ToCBOR msg' => | ||
Message (FireForget msg') st st' -> | ||
CBOR.Encoding | ||
encode MsgDone = CBOR.encodeWord 0 | ||
encode (MsgSend msg) = CBOR.encodeWord 1 <> toCBOR msg | ||
|
||
decode :: | ||
forall msg' s (st :: FireForget msg'). | ||
(FromCBOR msg', ActiveState st) => | ||
StateToken st -> | ||
CBOR.Decoder s (SomeMessage st) | ||
decode stok = do | ||
key <- CBOR.decodeWord | ||
case (stok, key) of | ||
(SingIdle, 0) -> pure $ SomeMessage MsgDone | ||
(SingIdle, 1) -> SomeMessage . MsgSend <$> fromCBOR | ||
(_, _) -> fail "codedFireForget.StIdle: unexpected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.