github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/common/enum_fence_type.go (about)

     1  //autogenerated:yes
     2  //nolint:revive,misspell,govet,lll,dupl,gocritic
     3  package common
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  	"strings"
     9  )
    10  
    11  type FENCE_TYPE uint64
    12  
    13  const (
    14  	// All fence types
    15  	FENCE_TYPE_ALL FENCE_TYPE = 0
    16  	// Maximum altitude fence
    17  	FENCE_TYPE_ALT_MAX FENCE_TYPE = 1
    18  	// Circle fence
    19  	FENCE_TYPE_CIRCLE FENCE_TYPE = 2
    20  	// Polygon fence
    21  	FENCE_TYPE_POLYGON FENCE_TYPE = 4
    22  	// Minimum altitude fence
    23  	FENCE_TYPE_ALT_MIN FENCE_TYPE = 8
    24  )
    25  
    26  var labels_FENCE_TYPE = map[FENCE_TYPE]string{
    27  	FENCE_TYPE_ALL:     "FENCE_TYPE_ALL",
    28  	FENCE_TYPE_ALT_MAX: "FENCE_TYPE_ALT_MAX",
    29  	FENCE_TYPE_CIRCLE:  "FENCE_TYPE_CIRCLE",
    30  	FENCE_TYPE_POLYGON: "FENCE_TYPE_POLYGON",
    31  	FENCE_TYPE_ALT_MIN: "FENCE_TYPE_ALT_MIN",
    32  }
    33  
    34  var values_FENCE_TYPE = map[string]FENCE_TYPE{
    35  	"FENCE_TYPE_ALL":     FENCE_TYPE_ALL,
    36  	"FENCE_TYPE_ALT_MAX": FENCE_TYPE_ALT_MAX,
    37  	"FENCE_TYPE_CIRCLE":  FENCE_TYPE_CIRCLE,
    38  	"FENCE_TYPE_POLYGON": FENCE_TYPE_POLYGON,
    39  	"FENCE_TYPE_ALT_MIN": FENCE_TYPE_ALT_MIN,
    40  }
    41  
    42  // MarshalText implements the encoding.TextMarshaler interface.
    43  func (e FENCE_TYPE) MarshalText() ([]byte, error) {
    44  	if e == 0 {
    45  		return []byte("0"), nil
    46  	}
    47  	var names []string
    48  	for i := 0; i < 5; i++ {
    49  		mask := FENCE_TYPE(1 << i)
    50  		if e&mask == mask {
    51  			names = append(names, labels_FENCE_TYPE[mask])
    52  		}
    53  	}
    54  	return []byte(strings.Join(names, " | ")), nil
    55  }
    56  
    57  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    58  func (e *FENCE_TYPE) UnmarshalText(text []byte) error {
    59  	labels := strings.Split(string(text), " | ")
    60  	var mask FENCE_TYPE
    61  	for _, label := range labels {
    62  		if value, ok := values_FENCE_TYPE[label]; ok {
    63  			mask |= value
    64  		} else if value, err := strconv.Atoi(label); err == nil {
    65  			mask |= FENCE_TYPE(value)
    66  		} else {
    67  			return fmt.Errorf("invalid label '%s'", label)
    68  		}
    69  	}
    70  	*e = mask
    71  	return nil
    72  }
    73  
    74  // String implements the fmt.Stringer interface.
    75  func (e FENCE_TYPE) String() string {
    76  	val, _ := e.MarshalText()
    77  	return string(val)
    78  }