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

     1  //autogenerated:yes
     2  //nolint:revive,misspell,govet,lll,dupl,gocritic
     3  package ardupilotmega
     4  
     5  import (
     6  	"fmt"
     7  	"strconv"
     8  	"strings"
     9  )
    10  
    11  type GOPRO_HEARTBEAT_FLAGS uint64
    12  
    13  const (
    14  	// GoPro is currently recording.
    15  	GOPRO_FLAG_RECORDING GOPRO_HEARTBEAT_FLAGS = 1
    16  )
    17  
    18  var labels_GOPRO_HEARTBEAT_FLAGS = map[GOPRO_HEARTBEAT_FLAGS]string{
    19  	GOPRO_FLAG_RECORDING: "GOPRO_FLAG_RECORDING",
    20  }
    21  
    22  var values_GOPRO_HEARTBEAT_FLAGS = map[string]GOPRO_HEARTBEAT_FLAGS{
    23  	"GOPRO_FLAG_RECORDING": GOPRO_FLAG_RECORDING,
    24  }
    25  
    26  // MarshalText implements the encoding.TextMarshaler interface.
    27  func (e GOPRO_HEARTBEAT_FLAGS) MarshalText() ([]byte, error) {
    28  	if e == 0 {
    29  		return []byte("0"), nil
    30  	}
    31  	var names []string
    32  	for i := 0; i < 1; i++ {
    33  		mask := GOPRO_HEARTBEAT_FLAGS(1 << i)
    34  		if e&mask == mask {
    35  			names = append(names, labels_GOPRO_HEARTBEAT_FLAGS[mask])
    36  		}
    37  	}
    38  	return []byte(strings.Join(names, " | ")), nil
    39  }
    40  
    41  // UnmarshalText implements the encoding.TextUnmarshaler interface.
    42  func (e *GOPRO_HEARTBEAT_FLAGS) UnmarshalText(text []byte) error {
    43  	labels := strings.Split(string(text), " | ")
    44  	var mask GOPRO_HEARTBEAT_FLAGS
    45  	for _, label := range labels {
    46  		if value, ok := values_GOPRO_HEARTBEAT_FLAGS[label]; ok {
    47  			mask |= value
    48  		} else if value, err := strconv.Atoi(label); err == nil {
    49  			mask |= GOPRO_HEARTBEAT_FLAGS(value)
    50  		} else {
    51  			return fmt.Errorf("invalid label '%s'", label)
    52  		}
    53  	}
    54  	*e = mask
    55  	return nil
    56  }
    57  
    58  // String implements the fmt.Stringer interface.
    59  func (e GOPRO_HEARTBEAT_FLAGS) String() string {
    60  	val, _ := e.MarshalText()
    61  	return string(val)
    62  }