forked from lucashpandolfo/dbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type-definitions.lisp
113 lines (93 loc) · 2.66 KB
/
type-definitions.lisp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;;; +----------------------------------------------------------------+
;;;; | DBUS DEATH, 2010-2011 |
;;;; +----------------------------------------------------------------+
(in-package #:dbus)
;;;; DBUS type definitions
(define-dbus-type :byte
:signature #\y
:alignment 1
:pack (u8 value)
:unpack (u8))
(define-dbus-type :boolean
:signature #\b
:alignment 4
:pack (u32 (if value 1 0))
:unpack (if (zerop (u32)) nil t))
(define-dbus-type :int16
:signature #\n
:alignment 2
:pack (u16 (signed-to-unsigned value 16))
:unpack (unsigned-to-signed (u16) 16))
(define-dbus-type :uint16
:signature #\q
:alignment 2
:pack (u16 value)
:unpack (u16))
(define-dbus-type :int32
:signature #\i
:alignment 4
:pack (u32 (signed-to-unsigned value 32))
:unpack (unsigned-to-signed (u32) 32))
(define-dbus-type :uint32
:signature #\u
:alignment 4
:pack (u32 value)
:unpack (u32))
(define-dbus-type :int64
:signature #\x
:alignment 8
:pack (u64 (signed-to-unsigned value 64))
:unpack (unsigned-to-signed (u64) 64))
(define-dbus-type :uint64
:signature #\t
:alignment 8
:pack (u64 value)
:unpack (u64))
(define-dbus-type :double
:signature #\d
:alignment 8
:pack (u64 (double-to-unsigned (float value 0.0d0)))
:unpack (unsigned-to-double (u64)))
(define-dbus-type :string
:signature #\s
:alignment 4
:pack (pack-string stream endianness value 32)
:unpack (unpack-string stream endianness (u32)))
(define-dbus-type :object-path
:signature #\o
:alignment 4
:pack (pack-string stream endianness value 32)
:unpack (unpack-string stream endianness (u32)))
(define-dbus-type :signature
:signature #\g
:alignment 1
:pack (pack-string stream endianness (signature value) 8)
:unpack (unpack-string stream endianness (u8)))
(define-dbus-type :array
:signature #\a
:composite t
:alignment 4
:pack (pack-array stream endianness (first element-types) value)
:unpack (unpack-array stream endianness (first element-types) (u32)))
(define-dbus-type :struct
:signature #\(
:composite #\)
:alignment 8
:pack (pack-seq stream endianness element-types value)
:unpack (unpack-seq stream endianness element-types))
(define-dbus-type :variant
:signature #\v
:alignment 1
:pack (pack-variant stream endianness (sigexp (first value)) (second value))
:unpack (unpack-variant stream endianness))
(define-dbus-type :dict-entry
:signature #\{
:composite #\}
:alignment 8
:pack (pack-seq stream endianness element-types value)
:unpack (unpack-seq stream endianness element-types))
(define-dbus-type :unix-fd
:signature #\h
:alignment 4
:pack (u32 value)
:unpack (u32))