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
56 /* Never a legitimate type */
57 #define DBUS_TYPE_INVALID ((int) '\0')
60 #define DBUS_TYPE_BYTE ((int) 'y')
61 #define DBUS_TYPE_BOOLEAN ((int) 'b')
62 #define DBUS_TYPE_INT32 ((int) 'i')
64 #define DBUS_TYPE_UINT32 ((int) 'u')
65 #define DBUS_TYPE_INT64 ((int) 'x')
66 #define DBUS_TYPE_UINT64 ((int) 't')
68 #define DBUS_TYPE_DOUBLE ((int) 'd')
69 #define DBUS_TYPE_STRING ((int) 's')
70 #define DBUS_TYPE_OBJECT_PATH ((int) 'o')
73 #define DBUS_TYPE_ARRAY ((int) 'a')
74 #define DBUS_TYPE_DICT ((int) 'm')
75 #define DBUS_TYPE_VARIANT ((int) 'v')
77 /* STRUCT is sort of special since its code can't appear in a type string,
78 * instead DBUS_STRUCT_BEGIN_CHAR has to appear
80 #define DBUS_TYPE_STRUCT ((int) 'r')
82 /* Does not count INVALID */
83 #define DBUS_NUMBER_OF_TYPES (13)
85 /* characters other than typecodes that appear in type signatures */
86 #define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
87 #define DBUS_STRUCT_END_CHAR ((int) ')')
90 _hack_dbus_type_to_string (int type)
94 case DBUS_TYPE_INVALID:
96 case DBUS_TYPE_BOOLEAN:
100 case DBUS_TYPE_UINT32:
102 case DBUS_TYPE_DOUBLE:
104 case DBUS_TYPE_STRING:
106 case DBUS_TYPE_STRUCT:
108 case DBUS_TYPE_ARRAY:
112 case DBUS_TYPE_VARIANT:
114 case DBUS_STRUCT_BEGIN_CHAR:
115 return "begin_struct";
116 case DBUS_STRUCT_END_CHAR:
123 #define _dbus_type_to_string(t) _hack_dbus_type_to_string(t)
125 /****************************************************** Remove later */
127 #ifdef WORDS_BIGENDIAN
128 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
130 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
133 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
134 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
135 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
136 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
137 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
139 #ifdef DBUS_HAVE_INT64
141 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
142 (((dbus_uint64_t) (val) & \
143 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
144 (((dbus_uint64_t) (val) & \
145 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
146 (((dbus_uint64_t) (val) & \
147 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
148 (((dbus_uint64_t) (val) & \
149 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
150 (((dbus_uint64_t) (val) & \
151 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
152 (((dbus_uint64_t) (val) & \
153 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
154 (((dbus_uint64_t) (val) & \
155 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
156 (((dbus_uint64_t) (val) & \
157 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
158 #endif /* DBUS_HAVE_INT64 */
160 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
161 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
163 #ifdef DBUS_HAVE_INT64
164 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
165 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
166 #endif /* DBUS_HAVE_INT64 */
168 #ifdef WORDS_BIGENDIAN
169 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
170 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
171 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
172 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
173 # ifdef DBUS_HAVE_INT64
174 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
175 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
176 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
177 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
178 # endif /* DBUS_HAVE_INT64 */
180 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
181 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
182 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
183 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
184 # ifdef DBUS_HAVE_INT64
185 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
186 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
187 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
188 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
189 # endif /* DBUS_HAVE_INT64 */
192 /* The transformation is symmetric, so the FROM just maps to the TO. */
193 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
194 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
195 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
196 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
197 #ifdef DBUS_HAVE_INT64
198 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
199 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
200 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
201 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
202 #endif /* DBUS_HAVE_INT64 */
204 void _dbus_pack_int32 (dbus_int32_t value,
206 unsigned char *data);
207 dbus_int32_t _dbus_unpack_int32 (int byte_order,
208 const unsigned char *data);
209 void _dbus_pack_uint32 (dbus_uint32_t value,
211 unsigned char *data);
212 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
213 const unsigned char *data);
214 #ifdef DBUS_HAVE_INT64
215 void _dbus_pack_int64 (dbus_int64_t value,
217 unsigned char *data);
218 dbus_int64_t _dbus_unpack_int64 (int byte_order,
219 const unsigned char *data);
220 void _dbus_pack_uint64 (dbus_uint64_t value,
222 unsigned char *data);
223 dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
224 const unsigned char *data);
225 #endif /* DBUS_HAVE_INT64 */
227 void _dbus_marshal_set_int32 (DBusString *str,
231 void _dbus_marshal_set_uint32 (DBusString *str,
234 dbus_uint32_t value);
235 #ifdef DBUS_HAVE_INT64
236 void _dbus_marshal_set_int64 (DBusString *str,
240 void _dbus_marshal_set_uint64 (DBusString *str,
243 dbus_uint64_t value);
244 #endif /* DBUS_HAVE_INT64 */
246 dbus_bool_t _dbus_marshal_set_string (DBusString *str,
249 const DBusString *value,
251 void _dbus_marshal_set_object_path (DBusString *str,
257 dbus_bool_t _dbus_marshal_int32 (DBusString *str,
260 dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
262 dbus_uint32_t value);
264 #ifdef DBUS_HAVE_INT64
265 dbus_bool_t _dbus_marshal_int64 (DBusString *str,
268 dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
270 dbus_uint64_t value);
271 #endif /* DBUS_HAVE_INT64 */
272 dbus_bool_t _dbus_marshal_double (DBusString *str,
276 dbus_bool_t _dbus_marshal_string (DBusString *str,
279 dbus_bool_t _dbus_marshal_string_len (DBusString *str,
284 dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
289 dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
295 dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
297 const unsigned char *value,
299 dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
301 const dbus_int32_t *value,
303 dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
305 const dbus_uint32_t *value,
307 #ifdef DBUS_HAVE_INT64
308 dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
310 const dbus_int64_t *value,
312 dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
314 const dbus_uint64_t *value,
316 #endif /* DBUS_HAVE_INT64 */
317 dbus_bool_t _dbus_marshal_double_array (DBusString *str,
321 dbus_bool_t _dbus_marshal_string_array (DBusString *str,
325 double _dbus_demarshal_double (const DBusString *str,
329 dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
333 dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
337 #ifdef DBUS_HAVE_INT64
338 dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
342 dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
346 #endif /* DBUS_HAVE_INT64 */
347 void _dbus_demarshal_basic_type (const DBusString *str,
352 char * _dbus_demarshal_string (const DBusString *str,
356 dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
360 unsigned char **array,
362 dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
366 dbus_int32_t **array,
368 dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
372 dbus_uint32_t **array,
374 #ifdef DBUS_HAVE_INT64
375 dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
379 dbus_int64_t **array,
381 dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
385 dbus_uint64_t **array,
387 #endif /* DBUS_HAVE_INT64 */
388 dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
394 dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str,
401 dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
407 dbus_bool_t _dbus_decompose_path (const char* data,
411 dbus_bool_t _dbus_demarshal_object_path (const DBusString *str,
418 void _dbus_marshal_skip_basic_type (const DBusString *str,
422 void _dbus_marshal_skip_array (const DBusString *str,
426 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
431 dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
435 dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
443 dbus_bool_t _dbus_type_is_valid (int typecode);
445 #endif /* DBUS_MARSHAL_H */