-
Notifications
You must be signed in to change notification settings - Fork 15
/
compat.go
61 lines (56 loc) · 1.32 KB
/
compat.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
package avro
// CompatMode defines a compatiblity mode used for checking Avro
// type compatibility.
type CompatMode int
const (
Backward CompatMode = 1 << iota
Forward
Transitive
BackwardTransitive = Backward | Transitive
ForwardTransitive = Forward | Transitive
Full = Backward | Forward
FullTransitive = Full | Transitive
)
// String returns a string representation of m, one of the values defined
// in https://docs.confluent.io/current/schema-registry/avro.html#schema-evolution-and-compatibility.
// For example FullTransitive.String() returns "FULL_TRANSITIVE".
func (m CompatMode) String() string {
var s string
switch m &^ Transitive {
case 0:
return "NONE"
case Backward:
s = "BACKWARD"
case Forward:
s = "FORWARD"
case Backward | Forward:
s = "FULL"
default:
return "UNKNOWN"
}
if m&Transitive != 0 {
s += "_TRANSITIVE"
}
return s
}
// ParseCompatMode returns the CompatMode from a string.
// It returns -1 if no matches are found.
func ParseCompatMode(s string) CompatMode {
switch s {
case "BACKWARD":
return Backward
case "FORWARD":
return Forward
case "FULL":
return Full
case "BACKWARD_TRANSITIVE":
return BackwardTransitive
case "FORWARD_TRANSITIVE":
return ForwardTransitive
case "FULL_TRANSITIVE":
return FullTransitive
case "NONE":
return 0
}
return -1
}