1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal.h Marshalling routines
4 * Copyright (C) 2002 CodeFactory AB
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef DBUS_MARSHAL_H
25 #define DBUS_MARSHAL_H
28 #include <dbus/dbus-protocol.h>
29 #include <dbus/dbus-types.h>
30 #include <dbus/dbus-arch-deps.h>
31 #include <dbus/dbus-string.h>
32 #include <dbus/dbus-objectid.h>
35 #error "config.h not included here"
38 #ifdef WORDS_BIGENDIAN
39 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
41 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
44 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
45 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
46 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
47 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
48 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
50 #ifdef DBUS_HAVE_INT64
52 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
53 (((dbus_uint64_t) (val) & \
54 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
55 (((dbus_uint64_t) (val) & \
56 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
57 (((dbus_uint64_t) (val) & \
58 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
59 (((dbus_uint64_t) (val) & \
60 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
61 (((dbus_uint64_t) (val) & \
62 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
63 (((dbus_uint64_t) (val) & \
64 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
65 (((dbus_uint64_t) (val) & \
66 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
67 (((dbus_uint64_t) (val) & \
68 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
69 #endif /* DBUS_HAVE_INT64 */
71 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
72 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
74 #ifdef DBUS_HAVE_INT64
75 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
76 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
77 #endif /* DBUS_HAVE_INT64 */
79 #ifdef WORDS_BIGENDIAN
80 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
81 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
82 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
83 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
84 # ifdef DBUS_HAVE_INT64
85 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
86 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
87 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
88 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
89 # endif /* DBUS_HAVE_INT64 */
91 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
92 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
93 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
94 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
95 # ifdef DBUS_HAVE_INT64
96 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
97 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
98 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
99 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
100 # endif /* DBUS_HAVE_INT64 */
103 /* The transformation is symmetric, so the FROM just maps to the TO. */
104 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
105 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
106 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
107 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
108 #ifdef DBUS_HAVE_INT64
109 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
110 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
111 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
112 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
113 #endif /* DBUS_HAVE_INT64 */
115 void _dbus_pack_int32 (dbus_int32_t value,
117 unsigned char *data);
118 dbus_int32_t _dbus_unpack_int32 (int byte_order,
119 const unsigned char *data);
120 void _dbus_pack_uint32 (dbus_uint32_t value,
122 unsigned char *data);
123 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
124 const unsigned char *data);
125 #ifdef DBUS_HAVE_INT64
126 void _dbus_pack_int64 (dbus_int64_t value,
128 unsigned char *data);
129 dbus_int64_t _dbus_unpack_int64 (int byte_order,
130 const unsigned char *data);
131 void _dbus_pack_uint64 (dbus_uint64_t value,
133 unsigned char *data);
134 dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
135 const unsigned char *data);
136 #endif /* DBUS_HAVE_INT64 */
138 void _dbus_marshal_set_int32 (DBusString *str,
142 void _dbus_marshal_set_uint32 (DBusString *str,
145 dbus_uint32_t value);
146 #ifdef DBUS_HAVE_INT64
147 void _dbus_marshal_set_int64 (DBusString *str,
151 void _dbus_marshal_set_uint64 (DBusString *str,
154 dbus_uint64_t value);
155 #endif /* DBUS_HAVE_INT64 */
157 dbus_bool_t _dbus_marshal_set_string (DBusString *str,
160 const DBusString *value,
162 void _dbus_marshal_set_object_id (DBusString *str,
165 const DBusObjectID *value);
167 dbus_bool_t _dbus_marshal_int32 (DBusString *str,
170 dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
172 dbus_uint32_t value);
173 #ifdef DBUS_HAVE_INT64
174 dbus_bool_t _dbus_marshal_int64 (DBusString *str,
177 dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
179 dbus_uint64_t value);
180 #endif /* DBUS_HAVE_INT64 */
181 dbus_bool_t _dbus_marshal_double (DBusString *str,
184 dbus_bool_t _dbus_marshal_string (DBusString *str,
187 dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
189 const unsigned char *value,
191 dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
193 const dbus_int32_t *value,
195 dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
197 const dbus_uint32_t *value,
199 #ifdef DBUS_HAVE_INT64
200 dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
202 const dbus_int64_t *value,
204 dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
206 const dbus_uint64_t *value,
208 #endif /* DBUS_HAVE_INT64 */
209 dbus_bool_t _dbus_marshal_double_array (DBusString *str,
213 dbus_bool_t _dbus_marshal_string_array (DBusString *str,
217 dbus_bool_t _dbus_marshal_object_id (DBusString *str,
219 const DBusObjectID *value);
221 double _dbus_demarshal_double (const DBusString *str,
225 dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
229 dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
233 #ifdef DBUS_HAVE_INT64
234 dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
238 dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
242 #endif /* DBUS_HAVE_INT64 */
243 char * _dbus_demarshal_string (const DBusString *str,
247 dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
251 unsigned char **array,
253 dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
257 dbus_int32_t **array,
259 dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
263 dbus_uint32_t **array,
265 #ifdef DBUS_HAVE_INT64
266 dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
270 dbus_int64_t **array,
272 dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
276 dbus_uint64_t **array,
278 #endif /* DBUS_HAVE_INT64 */
279 dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
285 dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
291 void _dbus_demarshal_object_id (const DBusString *str,
295 DBusObjectID *value);
297 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
302 dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
306 dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
315 #endif /* DBUS_PROTOCOL_H */