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