diff options
author | stuebinm | 2021-02-19 00:23:51 +0100 |
---|---|---|
committer | stuebinm | 2021-02-19 00:23:51 +0100 |
commit | 56ef5217cc03408b8d2b09809880e2cfda7a5855 (patch) | |
tree | 2809161fad1994e98780451b118891a5885d6ad3 /src/Protocol.elm |
Simple Slide-changing client
Everything works, EXCEPT:
- choosing slidesets
- choosing rooms
- choosing the number of slides
at runtime.
Diffstat (limited to 'src/Protocol.elm')
-rw-r--r-- | src/Protocol.elm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Protocol.elm b/src/Protocol.elm new file mode 100644 index 0000000..371a23a --- /dev/null +++ b/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 + |