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_INT32
42 #undef DBUS_TYPE_UINT32
43 #undef DBUS_TYPE_INT64
44 #undef DBUS_TYPE_UINT64
45 #undef DBUS_TYPE_DOUBLE
46 #undef DBUS_TYPE_STRING
47 #undef DBUS_TYPE_OBJECT_PATH
48 #undef DBUS_TYPE_ARRAY
50 #undef DBUS_TYPE_VARIANT
51 #undef DBUS_TYPE_STRUCT
52 #undef DBUS_NUMBER_OF_TYPES
54 /* Never a legitimate type */
55 #define DBUS_TYPE_INVALID ((int) '\0')
58 #define DBUS_TYPE_BYTE ((int) 'y')
59 #define DBUS_TYPE_BOOLEAN ((int) 'b')
60 #define DBUS_TYPE_INT32 ((int) 'i')
62 #define DBUS_TYPE_UINT32 ((int) 'u')
63 #define DBUS_TYPE_INT64 ((int) 'x')
64 #define DBUS_TYPE_UINT64 ((int) 't')
66 #define DBUS_TYPE_DOUBLE ((int) 'd')
67 #define DBUS_TYPE_STRING ((int) 's')
68 #define DBUS_TYPE_OBJECT_PATH ((int) 'o')
71 #define DBUS_TYPE_ARRAY ((int) 'a')
72 #define DBUS_TYPE_DICT ((int) 'm')
73 #define DBUS_TYPE_VARIANT ((int) 'v')
75 /* STRUCT is sort of special since its code can't appear in a type string,
76 * instead DBUS_STRUCT_BEGIN_CHAR has to appear
78 #define DBUS_TYPE_STRUCT ((int) 'r')
80 /* Does not count INVALID */
81 #define DBUS_NUMBER_OF_TYPES (13)
83 /* characters other than typecodes that appear in type signatures */
84 #define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
85 #define DBUS_STRUCT_END_CHAR ((int) ')')
86 #define DBUS_NAME_DELIMITER_CHAR ((int) '\'')
87 /****************************************************** Remove later */
89 #ifdef WORDS_BIGENDIAN
90 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
92 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
95 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
96 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
97 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
98 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
99 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
101 #ifdef DBUS_HAVE_INT64
103 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
104 (((dbus_uint64_t) (val) & \
105 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
106 (((dbus_uint64_t) (val) & \
107 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
108 (((dbus_uint64_t) (val) & \
109 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
110 (((dbus_uint64_t) (val) & \
111 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
112 (((dbus_uint64_t) (val) & \
113 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
114 (((dbus_uint64_t) (val) & \
115 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
116 (((dbus_uint64_t) (val) & \
117 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
118 (((dbus_uint64_t) (val) & \
119 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
120 #endif /* DBUS_HAVE_INT64 */
122 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
123 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
125 #ifdef DBUS_HAVE_INT64
126 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
127 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
128 #endif /* DBUS_HAVE_INT64 */
130 #ifdef WORDS_BIGENDIAN
131 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
132 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
133 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
134 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
135 # ifdef DBUS_HAVE_INT64
136 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
137 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
138 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
139 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
140 # endif /* DBUS_HAVE_INT64 */
142 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
143 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
144 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
145 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
146 # ifdef DBUS_HAVE_INT64
147 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
148 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
149 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
150 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
151 # endif /* DBUS_HAVE_INT64 */
154 /* The transformation is symmetric, so the FROM just maps to the TO. */
155 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
156 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
157 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
158 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
159 #ifdef DBUS_HAVE_INT64
160 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
161 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
162 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
163 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
164 #endif /* DBUS_HAVE_INT64 */
166 void _dbus_pack_int32 (dbus_int32_t value,
168 unsigned char *data);
169 dbus_int32_t _dbus_unpack_int32 (int byte_order,
170 const unsigned char *data);
171 void _dbus_pack_uint32 (dbus_uint32_t value,
173 unsigned char *data);
174 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
175 const unsigned char *data);
176 #ifdef DBUS_HAVE_INT64
177 void _dbus_pack_int64 (dbus_int64_t value,
179 unsigned char *data);
180 dbus_int64_t _dbus_unpack_int64 (int byte_order,
181 const unsigned char *data);
182 void _dbus_pack_uint64 (dbus_uint64_t value,
184 unsigned char *data);
185 dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
186 const unsigned char *data);
187 #endif /* DBUS_HAVE_INT64 */
189 void _dbus_marshal_set_int32 (DBusString *str,
193 void _dbus_marshal_set_uint32 (DBusString *str,
196 dbus_uint32_t value);
197 #ifdef DBUS_HAVE_INT64
198 void _dbus_marshal_set_int64 (DBusString *str,
202 void _dbus_marshal_set_uint64 (DBusString *str,
205 dbus_uint64_t value);
206 #endif /* DBUS_HAVE_INT64 */
208 dbus_bool_t _dbus_marshal_set_string (DBusString *str,
211 const DBusString *value,
213 void _dbus_marshal_set_object_path (DBusString *str,
219 dbus_bool_t _dbus_marshal_int32 (DBusString *str,
222 dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
224 dbus_uint32_t value);
225 #ifdef DBUS_HAVE_INT64
226 dbus_bool_t _dbus_marshal_int64 (DBusString *str,
229 dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
231 dbus_uint64_t value);
232 #endif /* DBUS_HAVE_INT64 */
233 dbus_bool_t _dbus_marshal_double (DBusString *str,
236 dbus_bool_t _dbus_marshal_string (DBusString *str,
239 dbus_bool_t _dbus_marshal_string_len (DBusString *str,
243 dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
247 dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
249 const unsigned char *value,
251 dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
253 const dbus_int32_t *value,
255 dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
257 const dbus_uint32_t *value,
259 #ifdef DBUS_HAVE_INT64
260 dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
262 const dbus_int64_t *value,
264 dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
266 const dbus_uint64_t *value,
268 #endif /* DBUS_HAVE_INT64 */
269 dbus_bool_t _dbus_marshal_double_array (DBusString *str,
273 dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
279 dbus_bool_t _dbus_marshal_string_array (DBusString *str,
283 dbus_bool_t _dbus_marshal_object_path (DBusString *str,
288 double _dbus_demarshal_double (const DBusString *str,
292 dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
296 dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
300 #ifdef DBUS_HAVE_INT64
301 dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
305 dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
309 #endif /* DBUS_HAVE_INT64 */
310 void _dbus_demarshal_basic_type (const DBusString *str,
315 char * _dbus_demarshal_string (const DBusString *str,
319 dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
323 unsigned char **array,
325 dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
329 dbus_int32_t **array,
331 dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
335 dbus_uint32_t **array,
337 #ifdef DBUS_HAVE_INT64
338 dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
342 dbus_int64_t **array,
344 dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
348 dbus_uint64_t **array,
350 #endif /* DBUS_HAVE_INT64 */
351 dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
357 dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str,
364 dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
370 dbus_bool_t _dbus_decompose_path (const char* data,
374 dbus_bool_t _dbus_demarshal_object_path (const DBusString *str,
381 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
386 dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
390 dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
398 dbus_bool_t _dbus_type_is_valid (int typecode);
400 #endif /* DBUS_MARSHAL_H */