This commit is contained in:
bluepython508 committed 2026-10-22 12:27:19 +01:00
1 parent 3530afb854
commit 6903fcff27
2146 files changed
+112256 -190703

No files matched your search

+25 -6
View File
@@ -11,17 +11,17 @@ import (
// Variant represents the D-Bus variant type.
type Variant struct {
sig Signature
value interface{}
value any
}
// MakeVariant converts the given value to a Variant. It panics if v cannot be
// represented as a D-Bus type.
func MakeVariant(v interface{}) Variant {
func MakeVariant(v any) Variant {
return MakeVariantWithSignature(v, SignatureOf(v))
}
// MakeVariantWithSignature converts the given value to a Variant.
func MakeVariantWithSignature(v interface{}, s Signature) Variant {
func MakeVariantWithSignature(v any, s Signature) Variant {
return Variant{s, v}
}
@@ -73,7 +73,7 @@ func (v Variant) format() (string, bool) {
}
rv := reflect.ValueOf(v.value)
switch rv.Kind() {
case reflect.Slice:
case reflect.Slice, reflect.Array:
if rv.Len() == 0 {
return "[]", false
}
@@ -119,6 +119,25 @@ func (v Variant) format() (string, bool) {
}
buf.WriteByte('}')
return buf.String(), unamb
case reflect.Struct:
if rv.NumField() == 0 {
return "()", false
}
unamb := true
var buf bytes.Buffer
buf.WriteByte('(')
for i := 0; i < rv.NumField(); i++ {
s, b := MakeVariant(rv.Field(i).Interface()).format()
unamb = unamb && b
buf.WriteString(s)
buf.WriteString(",")
if i != rv.NumField()-1 {
buf.WriteString(" ")
}
}
buf.WriteByte(')')
return buf.String(), unamb
}
return `"INVALID"`, true
}
@@ -139,12 +158,12 @@ func (v Variant) String() string {
}
// Value returns the underlying value of v.
func (v Variant) Value() interface{} {
func (v Variant) Value() any {
return v.value
}
// Store converts the variant into a native go type using the same
// mechanism as the "Store" function.
func (v Variant) Store(value interface{}) error {
func (v Variant) Store(value any) error {
return storeInterfaces(v.value, value)
}