-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ex02Enums.elm
147 lines (92 loc) · 2.73 KB
/
Ex02Enums.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
module Ex02Enums exposing (..)
{-| Protobuf library for decoding and encoding structures found in package `Ex02Enums` along with helpers. This file was generated automatically by `protoc-gen-elmer`. Do not edit.
Records: (none)
Unions:
- Answer
Each type defined has a: decoder, encoder and an empty (zero value) function. In addition to this enums have valuesOf, to and from (string) functions. All functions take the form `decodeDerivedIdent` where `decode` is the purpose and `DerivedIdent` comes from the Protobuf ident.
Elm identifiers are derived directly from the Protobuf ID (a full ident). The package maps to a module and the rest of the ID is the type. Since Protobuf names are hierachical (separated by a dot `.`), each namespace is mapped to an underscore `_` in an Elm ID. A Protobuf namespaced ident (parts between a dot `.`) are then cased to follow Elm naming conventions and do not include any undescores `_`. For example the enum `my.pkg.MyMessage.URLOptions` maps to the Elm module `My.Pkg` with ID `MyMessage_UrlOptions`.
# Types
@docs Answer
# Empty (zero values)
@docs emptyAnswer
# Enum valuesOf
@docs valuesOfAnswer
# Enum and String converters
@docs fromAnswer, toAnswer
# Decoders
@docs decodeAnswer
# Encoders
@docs encodeAnswer
-}
-- // Code generated protoc-gen-elmer DO NOT EDIT \\
import Protobuf.Decode as PD
import Protobuf.Encode as PE
type
Answer
-- Look out! Name collision!
= XMaybe
| Yes
| No
| PleaseRepeat
emptyAnswer : Answer
emptyAnswer =
XMaybe
valuesOfAnswer : List Answer
valuesOfAnswer =
[ XMaybe, Yes, No, PleaseRepeat ]
fromAnswer : Answer -> String
fromAnswer u =
case u of
XMaybe ->
"MAYBE"
Yes ->
"YES"
No ->
"NO"
PleaseRepeat ->
"PLEASE_REPEAT"
toAnswer : String -> Answer
toAnswer str =
case str of
"MAYBE" ->
XMaybe
"YES" ->
Yes
"NO" ->
No
"PLEASE_REPEAT" ->
PleaseRepeat
_ ->
XMaybe
decodeAnswer : PD.Decoder Answer
decodeAnswer =
let
conv v =
case v of
0 ->
XMaybe
1 ->
Yes
2 ->
No
10 ->
PleaseRepeat
_ ->
XMaybe
in
PD.map conv PD.int32
encodeAnswer : Answer -> PE.Encoder
encodeAnswer v =
let
conv =
case v of
XMaybe ->
0
Yes ->
1
No ->
2
PleaseRepeat ->
10
in
PE.int32 conv