1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-basic.h Marshalling routines for basic (primitive) types
4 * Copyright (C) 2002 CodeFactory AB
5 * Copyright (C) 2004 Red Hat, Inc.
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef DBUS_MARSHAL_H
26 #define DBUS_MARSHAL_H
29 #include <dbus/dbus-protocol.h>
30 #include <dbus/dbus-types.h>
31 #include <dbus/dbus-arch-deps.h>
32 #include <dbus/dbus-string.h>
35 #error "config.h not included here"
38 /****************************************************** Remove later */
39 #undef DBUS_TYPE_INVALID
41 #undef DBUS_TYPE_CUSTOM
43 #undef DBUS_TYPE_INT32
44 #undef DBUS_TYPE_UINT32
45 #undef DBUS_TYPE_INT64
46 #undef DBUS_TYPE_UINT64
47 #undef DBUS_TYPE_DOUBLE
48 #undef DBUS_TYPE_STRING
49 #undef DBUS_TYPE_OBJECT_PATH
50 #undef DBUS_TYPE_ARRAY
52 #undef DBUS_TYPE_VARIANT
53 #undef DBUS_TYPE_STRUCT
54 #undef DBUS_NUMBER_OF_TYPES
57 /* Never a legitimate type */
58 #define DBUS_TYPE_INVALID ((int) '\0')
59 #define DBUS_TYPE_INVALID_AS_STRING "\0"
62 #define DBUS_TYPE_BYTE ((int) 'y')
63 #define DBUS_TYPE_BYTE_AS_STRING "y"
64 #define DBUS_TYPE_BOOLEAN ((int) 'b')
65 #define DBUS_TYPE_BOOLEAN_AS_STRING "b"
66 #define DBUS_TYPE_INT32 ((int) 'i')
67 #define DBUS_TYPE_INT32_AS_STRING "i"
69 #define DBUS_TYPE_UINT32 ((int) 'u')
70 #define DBUS_TYPE_UINT32_AS_STRING "u"
71 #define DBUS_TYPE_INT64 ((int) 'x')
72 #define DBUS_TYPE_INT64_AS_STRING "x"
73 #define DBUS_TYPE_UINT64 ((int) 't')
74 #define DBUS_TYPE_UINT64_AS_STRING "t"
76 #define DBUS_TYPE_DOUBLE ((int) 'd')
77 #define DBUS_TYPE_DOUBLE_AS_STRING "d"
78 #define DBUS_TYPE_STRING ((int) 's')
79 #define DBUS_TYPE_STRING_AS_STRING "s"
80 #define DBUS_TYPE_OBJECT_PATH ((int) 'o')
81 #define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
84 #define DBUS_TYPE_ARRAY ((int) 'a')
85 #define DBUS_TYPE_ARRAY_AS_STRING "a"
86 #define DBUS_TYPE_DICT ((int) 'm') /* not parameterized; always map<string,variant> */
87 #define DBUS_TYPE_DICT_AS_STRING "m"
88 #define DBUS_TYPE_VARIANT ((int) 'v')
89 #define DBUS_TYPE_VARIANT_AS_STRING "v"
91 /* STRUCT is sort of special since its code can't appear in a type string,
92 * instead DBUS_STRUCT_BEGIN_CHAR has to appear
94 #define DBUS_TYPE_STRUCT ((int) 'r')
95 #define DBUS_TYPE_STRUCT_AS_STRING "r"
97 /* Does not count INVALID */
98 #define DBUS_NUMBER_OF_TYPES (13)
100 /* characters other than typecodes that appear in type signatures */
101 #define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
102 #define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
103 #define DBUS_STRUCT_END_CHAR ((int) ')')
104 #define DBUS_STRUCT_END_CHAR_AS_STRING ")"
107 _hack_dbus_type_to_string (int type)
111 case DBUS_TYPE_INVALID:
113 case DBUS_TYPE_BOOLEAN:
115 case DBUS_TYPE_INT32:
117 case DBUS_TYPE_UINT32:
119 case DBUS_TYPE_DOUBLE:
121 case DBUS_TYPE_STRING:
123 case DBUS_TYPE_STRUCT:
125 case DBUS_TYPE_ARRAY:
129 case DBUS_TYPE_VARIANT:
131 case DBUS_STRUCT_BEGIN_CHAR:
132 return "begin_struct";
133 case DBUS_STRUCT_END_CHAR:
140 #define _dbus_type_to_string(t) _hack_dbus_type_to_string(t)
142 /****************************************************** Remove later */
144 #ifdef WORDS_BIGENDIAN
145 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
147 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
150 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
151 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
152 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
153 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
154 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
156 #ifdef DBUS_HAVE_INT64
158 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
159 (((dbus_uint64_t) (val) & \
160 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
161 (((dbus_uint64_t) (val) & \
162 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
163 (((dbus_uint64_t) (val) & \
164 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
165 (((dbus_uint64_t) (val) & \
166 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
167 (((dbus_uint64_t) (val) & \
168 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
169 (((dbus_uint64_t) (val) & \
170 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
171 (((dbus_uint64_t) (val) & \
172 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
173 (((dbus_uint64_t) (val) & \
174 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
175 #endif /* DBUS_HAVE_INT64 */
177 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
178 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
180 #ifdef DBUS_HAVE_INT64
181 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
182 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
183 #endif /* DBUS_HAVE_INT64 */
185 #ifdef WORDS_BIGENDIAN
186 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
187 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
188 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
189 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
190 # ifdef DBUS_HAVE_INT64
191 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
192 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
193 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
194 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
195 # endif /* DBUS_HAVE_INT64 */
197 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
198 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
199 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
200 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
201 # ifdef DBUS_HAVE_INT64
202 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
203 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
204 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
205 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
206 # endif /* DBUS_HAVE_INT64 */
209 /* The transformation is symmetric, so the FROM just maps to the TO. */
210 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
211 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
212 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
213 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
214 #ifdef DBUS_HAVE_INT64
215 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
216 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
217 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
218 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
219 #endif /* DBUS_HAVE_INT64 */
221 void _dbus_pack_int32 (dbus_int32_t value,
223 unsigned char *data);
224 dbus_int32_t _dbus_unpack_int32 (int byte_order,
225 const unsigned char *data);
226 void _dbus_pack_uint32 (dbus_uint32_t value,
228 unsigned char *data);
229 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
230 const unsigned char *data);
231 #ifdef DBUS_HAVE_INT64
232 void _dbus_pack_int64 (dbus_int64_t value,
234 unsigned char *data);
235 dbus_int64_t _dbus_unpack_int64 (int byte_order,
236 const unsigned char *data);
237 void _dbus_pack_uint64 (dbus_uint64_t value,
239 unsigned char *data);
240 dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
241 const unsigned char *data);
242 #endif /* DBUS_HAVE_INT64 */
244 void _dbus_marshal_set_int32 (DBusString *str,
248 void _dbus_marshal_set_uint32 (DBusString *str,
251 dbus_uint32_t value);
252 #ifdef DBUS_HAVE_INT64
253 void _dbus_marshal_set_int64 (DBusString *str,
257 void _dbus_marshal_set_uint64 (DBusString *str,
260 dbus_uint64_t value);
261 #endif /* DBUS_HAVE_INT64 */
263 dbus_bool_t _dbus_marshal_set_string (DBusString *str,
266 const DBusString *value,
268 void _dbus_marshal_set_object_path (DBusString *str,
274 dbus_bool_t _dbus_marshal_int32 (DBusString *str,
277 dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
279 dbus_uint32_t value);
281 #ifdef DBUS_HAVE_INT64
282 dbus_bool_t _dbus_marshal_int64 (DBusString *str,
285 dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
287 dbus_uint64_t value);
288 #endif /* DBUS_HAVE_INT64 */
289 dbus_bool_t _dbus_marshal_double (DBusString *str,
293 dbus_bool_t _dbus_marshal_string (DBusString *str,
296 dbus_bool_t _dbus_marshal_string_len (DBusString *str,
301 dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
306 dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
312 dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
314 const unsigned char *value,
316 dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
318 const dbus_int32_t *value,
320 dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
322 const dbus_uint32_t *value,
324 #ifdef DBUS_HAVE_INT64
325 dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
327 const dbus_int64_t *value,
329 dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
331 const dbus_uint64_t *value,
333 #endif /* DBUS_HAVE_INT64 */
334 dbus_bool_t _dbus_marshal_double_array (DBusString *str,
338 dbus_bool_t _dbus_marshal_string_array (DBusString *str,
342 double _dbus_demarshal_double (const DBusString *str,
346 dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
350 dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
354 #ifdef DBUS_HAVE_INT64
355 dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
359 dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
363 #endif /* DBUS_HAVE_INT64 */
364 void _dbus_demarshal_basic_type (const DBusString *str,
369 char * _dbus_demarshal_string (const DBusString *str,
373 dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
377 unsigned char **array,
379 dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
383 dbus_int32_t **array,
385 dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
389 dbus_uint32_t **array,
391 #ifdef DBUS_HAVE_INT64
392 dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
396 dbus_int64_t **array,
398 dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
402 dbus_uint64_t **array,
404 #endif /* DBUS_HAVE_INT64 */
405 dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
411 dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str,
418 dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
424 dbus_bool_t _dbus_decompose_path (const char* data,
428 dbus_bool_t _dbus_demarshal_object_path (const DBusString *str,
435 void _dbus_marshal_skip_basic_type (const DBusString *str,
439 void _dbus_marshal_skip_array (const DBusString *str,
443 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
448 dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
452 dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
460 dbus_bool_t _dbus_type_is_valid (int typecode);
462 int _dbus_type_get_alignment (int typecode);
464 #endif /* DBUS_MARSHAL_H */