-
Notifications
You must be signed in to change notification settings - Fork 83
/
tos_string.go
53 lines (47 loc) · 1.14 KB
/
tos_string.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
package tos
import "fmt"
var (
_tosNameToValue map[string]ToS
_tosValueToName = map[ToS]string{
CS3: "CS3",
CS4: "CS4",
CS5: "CS5",
CS6: "CS6",
CS7: "CS7",
AF11: "AF11",
AF12: "AF12",
AF13: "AF13",
AF21: "AF21",
AF22: "AF22",
AF23: "AF23",
AF31: "AF31",
AF32: "AF32",
AF33: "AF33",
AF41: "AF41",
AF42: "AF42",
AF43: "AF43",
EF: "EF",
Lowdelay: "Lowdelay",
Throughput: "Throughput",
Reliability: "Reliability",
Lowcost: "Lowcost",
}
)
func init() {
_tosNameToValue = make(map[string]ToS, len(_tosValueToName))
for tos, tosString := range _tosValueToName {
_tosNameToValue[tosString] = tos
}
}
// MarshalText implements TextMarshaler from encoding
func (r ToS) MarshalText() ([]byte, error) {
return []byte(_tosValueToName[r]), nil
}
// UnmarshalText implements TextUnMarshaler from encoding
func (r *ToS) UnmarshalText(data []byte) error {
if v, ok := _tosNameToValue[string(data)]; ok {
*r = v
return nil
}
return fmt.Errorf("invalid ToS %q", string(data))
}