-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypemaps.go
83 lines (76 loc) · 2.2 KB
/
typemaps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package dbus
import (
"os"
"reflect"
"github.com/creachadair/mds/mapset"
)
var (
// strToType maps the DBus type signature identifier of a type to its
// reflect.Type.
strToType = map[byte]reflect.Type{
'b': reflect.TypeFor[bool](),
'y': reflect.TypeFor[uint8](),
'n': reflect.TypeFor[int16](),
'q': reflect.TypeFor[uint16](),
'i': reflect.TypeFor[int32](),
'u': reflect.TypeFor[uint32](),
'x': reflect.TypeFor[int64](),
't': reflect.TypeFor[uint64](),
'd': reflect.TypeFor[float64](),
's': reflect.TypeFor[string](),
'v': reflect.TypeFor[any](),
'g': reflect.TypeFor[Signature](),
'o': reflect.TypeFor[ObjectPath](),
'h': reflect.TypeFor[*os.File](),
}
// typeToStr maps basic DBus types that aren't basic Go types to
// their DBus type signature identifier.
typeToStr = map[reflect.Type]byte{
reflect.TypeFor[any](): 'v',
reflect.TypeFor[Signature](): 'g',
reflect.TypeFor[ObjectPath](): 'o',
reflect.TypeFor[*os.File](): 'h',
}
// kindToStr maps reflect.Kinds to their corresponding DBus type
// signature identifier, if any.
kindToStr = map[reflect.Kind]byte{
reflect.Bool: 'b',
reflect.Uint8: 'y',
reflect.Int16: 'n',
reflect.Uint16: 'q',
reflect.Int32: 'i',
reflect.Uint32: 'u',
reflect.Int64: 'x',
reflect.Uint64: 't',
reflect.Float64: 'd',
reflect.String: 's',
}
// kindToType reflect.Kinds of DBus basic types to their
// corresponding reflect.Type.
kindToType = map[reflect.Kind]reflect.Type{
reflect.Bool: reflect.TypeFor[bool](),
reflect.Uint8: reflect.TypeFor[uint8](),
reflect.Int16: reflect.TypeFor[int16](),
reflect.Uint16: reflect.TypeFor[uint16](),
reflect.Int32: reflect.TypeFor[int32](),
reflect.Uint32: reflect.TypeFor[uint32](),
reflect.Int64: reflect.TypeFor[int64](),
reflect.Uint64: reflect.TypeFor[uint64](),
reflect.Float64: reflect.TypeFor[float64](),
reflect.String: reflect.TypeFor[string](),
}
// mapKeyKinds is the set of reflect.Kinds that can be DBus map
// keys.
mapKeyKinds = mapset.New(
reflect.Bool,
reflect.Uint8,
reflect.Int16,
reflect.Uint16,
reflect.Int32,
reflect.Uint32,
reflect.Int64,
reflect.Uint64,
reflect.Float64,
reflect.String,
)
)