-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_clevel.go
87 lines (73 loc) · 2.2 KB
/
enum_clevel.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
package flate
import (
"encoding/json"
"fmt"
"strconv"
"strings"
)
// CompressLevel indicates the desired effort / CPU time to expend in finding
// an optimal compression stream.
type CompressLevel int8
const (
// DefaultCompression requests that the default value for CompressLevel
// be selected. This is currently equivalent to 6.
DefaultCompression CompressLevel = -1
// NoCompression requests that the data be stored literally, rather
// than compressed.
NoCompression CompressLevel = 0
// FastestCompression requests that the data be compressed with the
// greatest speed and least effort.
FastestCompression CompressLevel = 1
// BestCompression requests that the data be compressed with the
// greatest effort and least speed.
BestCompression CompressLevel = 9
)
// IsValid returns true if clevel is a valid CompressLevel constant.
func (clevel CompressLevel) IsValid() bool {
return clevel >= DefaultCompression && clevel <= BestCompression
}
// GoString returns the Go string representation of this CompressLevel constant.
func (clevel CompressLevel) GoString() string {
if clevel < 0 {
return "DefaultCompression"
}
return fmt.Sprintf("CompressLevel(%d)", int(clevel))
}
// String returns the string representation of this CompressLevel constant.
func (clevel CompressLevel) String() string {
if clevel < 0 {
return strDefault
}
if clevel == 0 {
return "none"
}
return fmt.Sprintf("%d", int(clevel))
}
// MarshalJSON returns the JSON representation of this CompressLevel constant.
func (clevel CompressLevel) MarshalJSON() ([]byte, error) {
return json.Marshal(int(clevel))
}
// Parse parses a string representation of a CompressLevel constant.
func (clevel *CompressLevel) Parse(str string) error {
if strings.EqualFold(str, strDefault) {
*clevel = DefaultCompression
return nil
}
if strings.EqualFold(str, "none") {
*clevel = NoCompression
return nil
}
u64, err := strconv.ParseUint(str, 10, 8)
if err != nil {
*clevel = DefaultCompression
return err
}
if u64 > 9 {
*clevel = DefaultCompression
return fmt.Errorf("value %d is out of range", u64)
}
*clevel = CompressLevel(u64)
return nil
}
var _ fmt.GoStringer = CompressLevel(0)
var _ fmt.Stringer = CompressLevel(0)