forked from twmb/franz-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enums.go
159 lines (143 loc) · 2.94 KB
/
enums.go
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
148
149
150
151
152
153
154
155
156
157
158
159
package sr
import (
"fmt"
"strings"
)
// SchemaType as an enum representing schema types. The default schema type
// is avro.
type SchemaType int
const (
TypeAvro SchemaType = iota
TypeProtobuf
TypeJSON
)
func (t SchemaType) String() string {
switch t {
case TypeAvro:
return "AVRO"
case TypeProtobuf:
return "PROTOBUF"
case TypeJSON:
return "JSON"
default:
return ""
}
}
func (t SchemaType) MarshalText() ([]byte, error) {
s := t.String()
if s == "" {
return nil, fmt.Errorf("unknown schema type %d", t)
}
return []byte(s), nil
}
func (t *SchemaType) UnmarshalText(text []byte) error {
switch s := strings.ToUpper(string(text)); s {
default:
return fmt.Errorf("unknown schema type %q", s)
case "", "AVRO":
*t = TypeAvro
case "PROTOBUF":
*t = TypeProtobuf
case "JSON":
*t = TypeJSON
}
return nil
}
// CompatibilityLevel as an enum representing config compatibility levels.
type CompatibilityLevel int
const (
CompatNone CompatibilityLevel = 1 + iota
CompatBackward
CompatBackwardTransitive
CompatForward
CompatForwardTransitive
CompatFull
CompatFullTransitive
)
func (l CompatibilityLevel) String() string {
switch l {
case CompatNone:
return "NONE"
case CompatBackward:
return "BACKWARD"
case CompatBackwardTransitive:
return "BACKWARD_TRANSITIVE"
case CompatForward:
return "FORWARD"
case CompatForwardTransitive:
return "FORWARD_TRANSITIVE"
case CompatFull:
return "FULL"
case CompatFullTransitive:
return "FULL_TRANSITIVE"
default:
return ""
}
}
func (l CompatibilityLevel) MarshalText() ([]byte, error) {
s := l.String()
if s == "" {
return nil, fmt.Errorf("unknown compatibility level %d", l)
}
return []byte(s), nil
}
func (l *CompatibilityLevel) UnmarshalText(text []byte) error {
switch s := strings.ToUpper(string(text)); s {
default:
return fmt.Errorf("unknown compatibility level %q", s)
case "NONE":
*l = CompatNone
case "BACKWARD":
*l = CompatBackward
case "BACKWARD_TRANSITIVE":
*l = CompatBackwardTransitive
case "FORWARD":
*l = CompatForward
case "FORWARD_TRANSITIVE":
*l = CompatForwardTransitive
case "FULL":
*l = CompatFull
case "FULL_TRANSITIVE":
*l = CompatFullTransitive
}
return nil
}
// Mode as an enum representing the "mode" of the registry or a subject.
type Mode int
const (
ModeImport Mode = iota
ModeReadOnly
ModeReadWrite
)
func (m Mode) String() string {
switch m {
case ModeImport:
return "IMPORT"
case ModeReadOnly:
return "READONLY"
case ModeReadWrite:
return "READWRITE"
default:
return ""
}
}
func (m Mode) MarshalText() ([]byte, error) {
s := m.String()
if s == "" {
return nil, fmt.Errorf("unknown mode %d", m)
}
return []byte(s), nil
}
func (m *Mode) UnmarshalText(text []byte) error {
switch s := strings.ToUpper(string(text)); s {
default:
return fmt.Errorf("unknown schema type %q", s)
case "IMPORT":
*m = ModeImport
case "READONLY":
*m = ModeReadOnly
case "READWRITE":
*m = ModeReadWrite
}
return nil
}