github.com/bluenviron/gomavlib/v2@v2.2.1-0.20240308101627-2c07e3da629c/pkg/dialects/common/enum_video_stream_status_flags.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 // Stream status flags (Bitmap) 12 type VIDEO_STREAM_STATUS_FLAGS uint64 13 14 const ( 15 // Stream is active (running) 16 VIDEO_STREAM_STATUS_FLAGS_RUNNING VIDEO_STREAM_STATUS_FLAGS = 1 17 // Stream is thermal imaging 18 VIDEO_STREAM_STATUS_FLAGS_THERMAL VIDEO_STREAM_STATUS_FLAGS = 2 19 ) 20 21 var labels_VIDEO_STREAM_STATUS_FLAGS = map[VIDEO_STREAM_STATUS_FLAGS]string{ 22 VIDEO_STREAM_STATUS_FLAGS_RUNNING: "VIDEO_STREAM_STATUS_FLAGS_RUNNING", 23 VIDEO_STREAM_STATUS_FLAGS_THERMAL: "VIDEO_STREAM_STATUS_FLAGS_THERMAL", 24 } 25 26 var values_VIDEO_STREAM_STATUS_FLAGS = map[string]VIDEO_STREAM_STATUS_FLAGS{ 27 "VIDEO_STREAM_STATUS_FLAGS_RUNNING": VIDEO_STREAM_STATUS_FLAGS_RUNNING, 28 "VIDEO_STREAM_STATUS_FLAGS_THERMAL": VIDEO_STREAM_STATUS_FLAGS_THERMAL, 29 } 30 31 // MarshalText implements the encoding.TextMarshaler interface. 32 func (e VIDEO_STREAM_STATUS_FLAGS) MarshalText() ([]byte, error) { 33 if e == 0 { 34 return []byte("0"), nil 35 } 36 var names []string 37 for i := 0; i < 2; i++ { 38 mask := VIDEO_STREAM_STATUS_FLAGS(1 << i) 39 if e&mask == mask { 40 names = append(names, labels_VIDEO_STREAM_STATUS_FLAGS[mask]) 41 } 42 } 43 return []byte(strings.Join(names, " | ")), nil 44 } 45 46 // UnmarshalText implements the encoding.TextUnmarshaler interface. 47 func (e *VIDEO_STREAM_STATUS_FLAGS) UnmarshalText(text []byte) error { 48 labels := strings.Split(string(text), " | ") 49 var mask VIDEO_STREAM_STATUS_FLAGS 50 for _, label := range labels { 51 if value, ok := values_VIDEO_STREAM_STATUS_FLAGS[label]; ok { 52 mask |= value 53 } else if value, err := strconv.Atoi(label); err == nil { 54 mask |= VIDEO_STREAM_STATUS_FLAGS(value) 55 } else { 56 return fmt.Errorf("invalid label '%s'", label) 57 } 58 } 59 *e = mask 60 return nil 61 } 62 63 // String implements the fmt.Stringer interface. 64 func (e VIDEO_STREAM_STATUS_FLAGS) String() string { 65 val, _ := e.MarshalText() 66 return string(val) 67 }