aboutsummaryrefslogtreecommitdiff
path: root/picarones-elm/src/Protocol.elm
diff options
context:
space:
mode:
authorstuebinm2021-03-07 16:59:38 +0100
committerstuebinm2021-03-07 18:36:43 +0100
commit090041fadec2e2896c3b82ef518096313d452c13 (patch)
treeb24b2753f8316bbf25420e8c121c685d346505a7 /picarones-elm/src/Protocol.elm
parent2ad5d413aa958a1c2fe75ce7aa155576e9a80345 (diff)
parentf4a1ee55987b7c58745dc5865c4ecf30874a3564 (diff)
Join subtrees and integrate meta info / gitignore
git-subtree-dir: picarones-elm git-subtree-mainline: 2ad5d413aa958a1c2fe75ce7aa155576e9a80345 git-subtree-split: f4a1ee55987b7c58745dc5865c4ecf30874a3564
Diffstat (limited to 'picarones-elm/src/Protocol.elm')
-rw-r--r--picarones-elm/src/Protocol.elm24
1 files changed, 24 insertions, 0 deletions
diff --git a/picarones-elm/src/Protocol.elm b/picarones-elm/src/Protocol.elm
new file mode 100644
index 0000000..371a23a
--- /dev/null
+++ b/picarones-elm/src/Protocol.elm
@@ -0,0 +1,24 @@
+module Protocol exposing (State, encodeState, decodeState)
+
+import Json.Decode as D
+import Json.Encode as E
+
+{- PROTOCOL -}
+
+ -- for now, this is still very boring and just has one field:
+type alias State = { state : Int }
+
+encodeState : State -> String
+encodeState state =
+ E.object [ ("state", E.int state.state) ]
+ |> E.encode 0
+
+
+stateDecoder : D.Decoder State
+stateDecoder = D.map State (D.field "state" D.int)
+
+decodeState : String -> Maybe State
+decodeState text = case D.decodeString (D.nullable stateDecoder) text of
+ Err e -> Nothing
+ Ok value -> value
+