blob: 371a23a8381cf4075d9ca513c194b8593a956c0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
|