github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/enumgen/__examples__/scheme__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: example/scheme__generated.go 3 4 package example 5 6 import ( 7 "bytes" 8 "database/sql/driver" 9 "errors" 10 11 "github.com/machinefi/w3bstream/pkg/depends/kit/enum" 12 ) 13 14 var InvalidScheme = errors.New("invalid Scheme type") 15 16 func ParseSchemeFromString(s string) (Scheme, error) { 17 switch s { 18 default: 19 return SCHEME_UNKNOWN, InvalidScheme 20 case "": 21 return SCHEME_UNKNOWN, nil 22 case "HTTP": 23 return SCHEME__HTTP, nil 24 case "HTTPS": 25 return SCHEME__HTTPS, nil 26 case "TCP": 27 return SCHEME__TCP, nil 28 case "UDP": 29 return SCHEME__UDP, nil 30 case "QUIC": 31 return SCHEME__QUIC, nil 32 } 33 } 34 35 func ParseSchemeFromLabel(s string) (Scheme, error) { 36 switch s { 37 default: 38 return SCHEME_UNKNOWN, InvalidScheme 39 case "": 40 return SCHEME_UNKNOWN, nil 41 case "http": 42 return SCHEME__HTTP, nil 43 case "https": 44 return SCHEME__HTTPS, nil 45 case "TCP": 46 return SCHEME__TCP, nil 47 case "UDP": 48 return SCHEME__UDP, nil 49 case "QUIC": 50 return SCHEME__QUIC, nil 51 } 52 } 53 54 func (v Scheme) Int() int { 55 return int(v) 56 } 57 58 func (v Scheme) String() string { 59 switch v { 60 default: 61 return "UNKNOWN" 62 case SCHEME_UNKNOWN: 63 return "" 64 case SCHEME__HTTP: 65 return "HTTP" 66 case SCHEME__HTTPS: 67 return "HTTPS" 68 case SCHEME__TCP: 69 return "TCP" 70 case SCHEME__UDP: 71 return "UDP" 72 case SCHEME__QUIC: 73 return "QUIC" 74 } 75 } 76 77 func (v Scheme) Label() string { 78 switch v { 79 default: 80 return "UNKNOWN" 81 case SCHEME_UNKNOWN: 82 return "" 83 case SCHEME__HTTP: 84 return "http" 85 case SCHEME__HTTPS: 86 return "https" 87 case SCHEME__TCP: 88 return "TCP" 89 case SCHEME__UDP: 90 return "UDP" 91 case SCHEME__QUIC: 92 return "QUIC" 93 } 94 } 95 96 func (v Scheme) TypeName() string { 97 return "github.com/machinefi/w3bstream/pkg/depends/kit/enumgen/__examples__.Scheme" 98 } 99 100 func (v Scheme) ConstValues() []enum.IntStringerEnum { 101 return []enum.IntStringerEnum{SCHEME__HTTP, SCHEME__HTTPS, SCHEME__TCP, SCHEME__UDP, SCHEME__QUIC} 102 } 103 104 func (v Scheme) MarshalText() ([]byte, error) { 105 s := v.String() 106 if s == "UNKNOWN" { 107 return nil, InvalidScheme 108 } 109 return []byte(s), nil 110 } 111 112 func (v *Scheme) UnmarshalText(data []byte) error { 113 s := string(bytes.ToUpper(data)) 114 val, err := ParseSchemeFromString(s) 115 if err != nil { 116 return err 117 } 118 *(v) = val 119 return nil 120 } 121 122 func (v *Scheme) Scan(src interface{}) error { 123 offset := 0 124 o, ok := interface{}(v).(enum.ValueOffset) 125 if ok { 126 offset = o.Offset() 127 } 128 i, err := enum.ScanIntEnumStringer(src, offset) 129 if err != nil { 130 return err 131 } 132 *(v) = Scheme(i) 133 return nil 134 } 135 136 func (v Scheme) Value() (driver.Value, error) { 137 offset := 0 138 o, ok := interface{}(v).(enum.ValueOffset) 139 if ok { 140 offset = o.Offset() 141 } 142 return int64(v) + int64(offset), nil 143 }