mediamtx/internal/staticsources/rpicamera/params_serialize.go
Alessandro Ros 3700d5e5b9
Some checks are pending
code_lint / golangci_lint (push) Waiting to run
code_lint / mod_tidy (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_highlevel (push) Waiting to run
rpi: fix passing unsigned integers to component (#3672)
2024-08-21 00:08:54 +02:00

48 lines
825 B
Go

//go:build (linux && arm) || (linux && arm64)
// +build linux,arm linux,arm64
package rpicamera
import (
"encoding/base64"
"reflect"
"strconv"
"strings"
)
func (p params) serialize() []byte {
rv := reflect.ValueOf(p)
rt := rv.Type()
nf := rv.NumField()
ret := make([]string, nf)
for i := 0; i < nf; i++ {
entry := rt.Field(i).Name + ":"
f := rv.Field(i)
switch f.Kind() {
case reflect.Uint:
entry += strconv.FormatUint(f.Uint(), 10)
case reflect.Float64:
entry += strconv.FormatFloat(f.Float(), 'f', -1, 64)
case reflect.String:
entry += base64.StdEncoding.EncodeToString([]byte(f.String()))
case reflect.Bool:
if f.Bool() {
entry += "1"
} else {
entry += "0"
}
default:
panic("unhandled type")
}
ret[i] = entry
}
return []byte(strings.Join(ret, " "))
}