github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/enums/protocol__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: enums/protocol__generated.go 3 4 package enums 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 InvalidProtocol = errors.New("invalid Protocol type") 15 16 func ParseProtocolFromString(s string) (Protocol, error) { 17 switch s { 18 default: 19 return PROTOCOL_UNKNOWN, InvalidProtocol 20 case "": 21 return PROTOCOL_UNKNOWN, nil 22 case "TCP": 23 return PROTOCOL__TCP, nil 24 case "UDP": 25 return PROTOCOL__UDP, nil 26 case "WEBSOCET": 27 return PROTOCOL__WEBSOCET, nil 28 case "HTTP": 29 return PROTOCOL__HTTP, nil 30 case "HTTPS": 31 return PROTOCOL__HTTPS, nil 32 case "MQTT": 33 return PROTOCOL__MQTT, nil 34 } 35 } 36 37 func ParseProtocolFromLabel(s string) (Protocol, error) { 38 switch s { 39 default: 40 return PROTOCOL_UNKNOWN, InvalidProtocol 41 case "": 42 return PROTOCOL_UNKNOWN, nil 43 case "tcp": 44 return PROTOCOL__TCP, nil 45 case "udp": 46 return PROTOCOL__UDP, nil 47 case "websocket": 48 return PROTOCOL__WEBSOCET, nil 49 case "http": 50 return PROTOCOL__HTTP, nil 51 case "https": 52 return PROTOCOL__HTTPS, nil 53 case "mqtt": 54 return PROTOCOL__MQTT, nil 55 } 56 } 57 58 func (v Protocol) Int() int { 59 return int(v) 60 } 61 62 func (v Protocol) String() string { 63 switch v { 64 default: 65 return "UNKNOWN" 66 case PROTOCOL_UNKNOWN: 67 return "" 68 case PROTOCOL__TCP: 69 return "TCP" 70 case PROTOCOL__UDP: 71 return "UDP" 72 case PROTOCOL__WEBSOCET: 73 return "WEBSOCET" 74 case PROTOCOL__HTTP: 75 return "HTTP" 76 case PROTOCOL__HTTPS: 77 return "HTTPS" 78 case PROTOCOL__MQTT: 79 return "MQTT" 80 } 81 } 82 83 func (v Protocol) Label() string { 84 switch v { 85 default: 86 return "UNKNOWN" 87 case PROTOCOL_UNKNOWN: 88 return "" 89 case PROTOCOL__TCP: 90 return "tcp" 91 case PROTOCOL__UDP: 92 return "udp" 93 case PROTOCOL__WEBSOCET: 94 return "websocket" 95 case PROTOCOL__HTTP: 96 return "http" 97 case PROTOCOL__HTTPS: 98 return "https" 99 case PROTOCOL__MQTT: 100 return "mqtt" 101 } 102 } 103 104 func (v Protocol) TypeName() string { 105 return "github.com/machinefi/w3bstream/pkg/enums.Protocol" 106 } 107 108 func (v Protocol) ConstValues() []enum.IntStringerEnum { 109 return []enum.IntStringerEnum{PROTOCOL__TCP, PROTOCOL__UDP, PROTOCOL__WEBSOCET, PROTOCOL__HTTP, PROTOCOL__HTTPS, PROTOCOL__MQTT} 110 } 111 112 func (v Protocol) MarshalText() ([]byte, error) { 113 s := v.String() 114 if s == "UNKNOWN" { 115 return nil, InvalidProtocol 116 } 117 return []byte(s), nil 118 } 119 120 func (v *Protocol) UnmarshalText(data []byte) error { 121 s := string(bytes.ToUpper(data)) 122 val, err := ParseProtocolFromString(s) 123 if err != nil { 124 return err 125 } 126 *(v) = val 127 return nil 128 } 129 130 func (v *Protocol) Scan(src interface{}) error { 131 offset := 0 132 o, ok := interface{}(v).(enum.ValueOffset) 133 if ok { 134 offset = o.Offset() 135 } 136 i, err := enum.ScanIntEnumStringer(src, offset) 137 if err != nil { 138 return err 139 } 140 *(v) = Protocol(i) 141 return nil 142 } 143 144 func (v Protocol) Value() (driver.Value, error) { 145 offset := 0 146 o, ok := interface{}(v).(enum.ValueOffset) 147 if ok { 148 offset = o.Offset() 149 } 150 return int64(v) + int64(offset), nil 151 }