github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/enums/mqtt_qos__generated.go (about)

     1  // This is a generated source file. DO NOT EDIT
     2  // Source: enums/mqtt_qos__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 InvalidMqttQOS = errors.New("invalid MqttQOS type")
    15  
    16  func ParseMqttQOSFromString(s string) (MqttQOS, error) {
    17  	switch s {
    18  	default:
    19  		return MQTT_QOS_UNKNOWN, InvalidMqttQOS
    20  	case "":
    21  		return MQTT_QOS_UNKNOWN, nil
    22  	case "ONCE":
    23  		return MQTT_QOS__ONCE, nil
    24  	case "AT_LEAST_ONCE":
    25  		return MQTT_QOS__AT_LEAST_ONCE, nil
    26  	case "ONLY_ONCE":
    27  		return MQTT_QOS__ONLY_ONCE, nil
    28  	}
    29  }
    30  
    31  func ParseMqttQOSFromLabel(s string) (MqttQOS, error) {
    32  	switch s {
    33  	default:
    34  		return MQTT_QOS_UNKNOWN, InvalidMqttQOS
    35  	case "":
    36  		return MQTT_QOS_UNKNOWN, nil
    37  	case "0":
    38  		return MQTT_QOS__ONCE, nil
    39  	case "1":
    40  		return MQTT_QOS__AT_LEAST_ONCE, nil
    41  	case "2":
    42  		return MQTT_QOS__ONLY_ONCE, nil
    43  	}
    44  }
    45  
    46  func (v MqttQOS) Int() int {
    47  	return int(v)
    48  }
    49  
    50  func (v MqttQOS) String() string {
    51  	switch v {
    52  	default:
    53  		return "UNKNOWN"
    54  	case MQTT_QOS_UNKNOWN:
    55  		return ""
    56  	case MQTT_QOS__ONCE:
    57  		return "ONCE"
    58  	case MQTT_QOS__AT_LEAST_ONCE:
    59  		return "AT_LEAST_ONCE"
    60  	case MQTT_QOS__ONLY_ONCE:
    61  		return "ONLY_ONCE"
    62  	}
    63  }
    64  
    65  func (v MqttQOS) Label() string {
    66  	switch v {
    67  	default:
    68  		return "UNKNOWN"
    69  	case MQTT_QOS_UNKNOWN:
    70  		return ""
    71  	case MQTT_QOS__ONCE:
    72  		return "0"
    73  	case MQTT_QOS__AT_LEAST_ONCE:
    74  		return "1"
    75  	case MQTT_QOS__ONLY_ONCE:
    76  		return "2"
    77  	}
    78  }
    79  
    80  func (v MqttQOS) TypeName() string {
    81  	return "github.com/machinefi/w3bstream/pkg/enums.MqttQOS"
    82  }
    83  
    84  func (v MqttQOS) ConstValues() []enum.IntStringerEnum {
    85  	return []enum.IntStringerEnum{MQTT_QOS__ONCE, MQTT_QOS__AT_LEAST_ONCE, MQTT_QOS__ONLY_ONCE}
    86  }
    87  
    88  func (v MqttQOS) MarshalText() ([]byte, error) {
    89  	s := v.String()
    90  	if s == "UNKNOWN" {
    91  		return nil, InvalidMqttQOS
    92  	}
    93  	return []byte(s), nil
    94  }
    95  
    96  func (v *MqttQOS) UnmarshalText(data []byte) error {
    97  	s := string(bytes.ToUpper(data))
    98  	val, err := ParseMqttQOSFromString(s)
    99  	if err != nil {
   100  		return err
   101  	}
   102  	*(v) = val
   103  	return nil
   104  }
   105  
   106  func (v *MqttQOS) Scan(src interface{}) error {
   107  	offset := 0
   108  	o, ok := interface{}(v).(enum.ValueOffset)
   109  	if ok {
   110  		offset = o.Offset()
   111  	}
   112  	i, err := enum.ScanIntEnumStringer(src, offset)
   113  	if err != nil {
   114  		return err
   115  	}
   116  	*(v) = MqttQOS(i)
   117  	return nil
   118  }
   119  
   120  func (v MqttQOS) Value() (driver.Value, error) {
   121  	offset := 0
   122  	o, ok := interface{}(v).(enum.ValueOffset)
   123  	if ok {
   124  		offset = o.Offset()
   125  	}
   126  	return int64(v) + int64(offset), nil
   127  }