tome_lib/targetstatus_enumer.go

74 lines
2.0 KiB
Go
Raw Normal View History

2021-11-16 16:44:19 -05:00
// Code generated by "enumer -type=TargetStatus -json"; DO NOT EDIT.
//
package tome_lib
import (
"encoding/json"
"fmt"
)
const _TargetStatusName = "TargetSelfTargetOwnTargetOwnEmptyTargetOppTargetOppEmptyTargetAnyTargetNone"
var _TargetStatusIndex = [...]uint8{0, 10, 19, 33, 42, 56, 65, 75}
func (i TargetStatus) String() string {
if i < 0 || i >= TargetStatus(len(_TargetStatusIndex)-1) {
return fmt.Sprintf("TargetStatus(%d)", i)
}
return _TargetStatusName[_TargetStatusIndex[i]:_TargetStatusIndex[i+1]]
}
var _TargetStatusValues = []TargetStatus{0, 1, 2, 3, 4, 5, 6}
var _TargetStatusNameToValueMap = map[string]TargetStatus{
_TargetStatusName[0:10]: 0,
_TargetStatusName[10:19]: 1,
_TargetStatusName[19:33]: 2,
_TargetStatusName[33:42]: 3,
_TargetStatusName[42:56]: 4,
_TargetStatusName[56:65]: 5,
_TargetStatusName[65:75]: 6,
}
// TargetStatusString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func TargetStatusString(s string) (TargetStatus, error) {
if val, ok := _TargetStatusNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to TargetStatus values", s)
}
// TargetStatusValues returns all values of the enum
func TargetStatusValues() []TargetStatus {
return _TargetStatusValues
}
// IsATargetStatus returns "true" if the value is listed in the enum definition. "false" otherwise
func (i TargetStatus) IsATargetStatus() bool {
for _, v := range _TargetStatusValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for TargetStatus
func (i TargetStatus) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for TargetStatus
func (i *TargetStatus) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("TargetStatus should be a string, got %s", data)
}
var err error
*i, err = TargetStatusString(s)
return err
}