/
type-definitions.lisp
134 lines (113 loc) · 3.24 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;;;; +----------------------------------------------------------------+
;;;; | DBUS |
;;;; +----------------------------------------------------------------+
(defpackage #:dbus/type-definitions
(:use #:cl #:dbus/utils #:dbus/types)
(:import-from #:ieee-floats #:encode-float64 #:decode-float64)
(:export))
(in-package #:dbus/type-definitions)
;;;; DBUS type definitions
(define-dbus-type :byte
:signature #\y
:alignment 1
:pack (u8 value)
:unpack (u8)
:checker (unsigned-byte 8))
(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)
:checker (signed-byte 16))
(define-dbus-type :uint16
:signature #\q
:alignment 2
:pack (u16 value)
:unpack (u16)
:checker (unsigned-byte 16))
(define-dbus-type :int32
:signature #\i
:alignment 4
:pack (u32 (signed-to-unsigned value 32))
:unpack (unsigned-to-signed (u32) 32)
:checker (signed-byte 32))
(define-dbus-type :uint32
:signature #\u
:alignment 4
:pack (u32 value)
:unpack (u32)
:checker (unsigned-byte 32))
(define-dbus-type :int64
:signature #\x
:alignment 8
:pack (u64 (signed-to-unsigned value 64))
:unpack (unsigned-to-signed (u64) 64)
:checker (signed-byte 64))
(define-dbus-type :uint64
:signature #\t
:alignment 8
:pack (u64 value)
:unpack (u64)
:checker (unsigned-byte 64))
(define-dbus-type :double
:signature #\d
:alignment 8
:pack (u64 (encode-float64 (float value 0.0d0)))
:unpack (decode-float64 (u64))
:checker real)
(define-dbus-type :string
:signature #\s
:alignment 4
:pack (pack-string stream endianness value 32)
:unpack (unpack-string stream endianness (u32))
:checker string)
(define-dbus-type :object-path
:signature #\o
:alignment 4
:pack (pack-string stream endianness value 32)
:unpack (unpack-string stream endianness (u32))
:checker string)
(define-dbus-type :signature
:signature #\g
:alignment 1
:pack (pack-string stream endianness (signature value) 8)
:unpack (unpack-string stream endianness (u8))
:checker #'valid-signature-p)
(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))
:checker #'valid-array-p)
(define-dbus-type :struct
:signature #\(
:composite #\)
:alignment 8
:pack (pack-seq stream endianness element-types value)
:unpack (unpack-seq stream endianness element-types)
:checker #'valid-struct-p)
(define-dbus-type :variant
:signature #\v
:alignment 1
:pack (pack-variant stream endianness (sigexp (first value)) (second value))
:unpack (unpack-variant stream endianness)
:checker #'valid-variant-p)
(define-dbus-type :dict-entry
:signature #\{
:composite #\}
:alignment 8
:pack (pack-seq stream endianness element-types value)
:unpack (unpack-seq stream endianness element-types)
:checker #'valid-dict-entry-p)
(define-dbus-type :unix-fd
:signature #\h
:alignment 4
:pack (u32 value)
:unpack (u32)
:checker (unsigned-byte 32))