aboutsummaryrefslogtreecommitdiff
path: root/picarones-elm/src/Protocol.elm
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
+