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>
34 #error "config.h not included here"
37 #ifdef WORDS_BIGENDIAN
38 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
40 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
43 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
44 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
45 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
46 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
47 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
49 #ifdef DBUS_HAVE_INT64
51 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
52 (((dbus_uint64_t) (val) & \
53 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
54 (((dbus_uint64_t) (val) & \
55 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
56 (((dbus_uint64_t) (val) & \
57 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
58 (((dbus_uint64_t) (val) & \
59 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
60 (((dbus_uint64_t) (val) & \
61 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
62 (((dbus_uint64_t) (val) & \
63 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
64 (((dbus_uint64_t) (val) & \
65 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
66 (((dbus_uint64_t) (val) & \
67 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
68 #endif /* DBUS_HAVE_INT64 */
70 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
71 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
73 #ifdef DBUS_HAVE_INT64
74 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
75 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
76 #endif /* DBUS_HAVE_INT64 */
78 #ifdef WORDS_BIGENDIAN
79 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
80 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
81 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
82 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
83 # ifdef DBUS_HAVE_INT64
84 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
85 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
86 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
87 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
88 # endif /* DBUS_HAVE_INT64 */
90 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
91 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
92 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
93 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
94 # ifdef DBUS_HAVE_INT64
95 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
96 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
97 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
98 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
99 # endif /* DBUS_HAVE_INT64 */
102 /* The transformation is symmetric, so the FROM just maps to the TO. */
103 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
104 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
105 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
106 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
107 #ifdef DBUS_HAVE_INT64
108 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
109 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
110 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
111 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
112 #endif /* DBUS_HAVE_INT64 */
114 void _dbus_pack_int32 (dbus_int32_t value,
116 unsigned char *data);
117 dbus_int32_t _dbus_unpack_int32 (int byte_order,
118 const unsigned char *data);
119 void _dbus_pack_uint32 (dbus_uint32_t value,
121 unsigned char *data);
122 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
123 const unsigned char *data);
124 #ifdef DBUS_HAVE_INT64
125 void _dbus_pack_int64 (dbus_int64_t value,
127 unsigned char *data);
128 dbus_int64_t _dbus_unpack_int64 (int byte_order,
129 const unsigned char *data);
130 void _dbus_pack_uint64 (dbus_uint64_t value,
132 unsigned char *data);
133 dbus_uint64_t _dbus_unpack_uint64 (int byte_order,
134 const unsigned char *data);
135 #endif /* DBUS_HAVE_INT64 */
137 void _dbus_marshal_set_int32 (DBusString *str,
141 void _dbus_marshal_set_uint32 (DBusString *str,
144 dbus_uint32_t value);
145 #ifdef DBUS_HAVE_INT64
146 void _dbus_marshal_set_int64 (DBusString *str,
150 void _dbus_marshal_set_uint64 (DBusString *str,
153 dbus_uint64_t value);
154 #endif /* DBUS_HAVE_INT64 */
155 dbus_bool_t _dbus_marshal_set_string (DBusString *str,
158 const DBusString *value,
161 dbus_bool_t _dbus_marshal_int32 (DBusString *str,
164 dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
166 dbus_uint32_t value);
167 #ifdef DBUS_HAVE_INT64
168 dbus_bool_t _dbus_marshal_int64 (DBusString *str,
171 dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
173 dbus_uint64_t value);
174 #endif /* DBUS_HAVE_INT64 */
175 dbus_bool_t _dbus_marshal_double (DBusString *str,
178 dbus_bool_t _dbus_marshal_string (DBusString *str,
181 dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
183 const unsigned char *value,
185 dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
187 const dbus_int32_t *value,
189 dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
191 const dbus_uint32_t *value,
193 #ifdef DBUS_HAVE_INT64
194 dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
196 const dbus_int64_t *value,
198 dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
200 const dbus_uint64_t *value,
202 #endif /* DBUS_HAVE_INT64 */
203 dbus_bool_t _dbus_marshal_double_array (DBusString *str,
207 dbus_bool_t _dbus_marshal_string_array (DBusString *str,
211 double _dbus_demarshal_double (const DBusString *str,
215 dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
219 dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
223 #ifdef DBUS_HAVE_INT64
224 dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
228 dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
232 #endif /* DBUS_HAVE_INT64 */
233 char * _dbus_demarshal_string (const DBusString *str,
237 dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
241 unsigned char **array,
243 dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
247 dbus_int32_t **array,
249 dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
253 dbus_uint32_t **array,
255 #ifdef DBUS_HAVE_INT64
256 dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
260 dbus_int64_t **array,
262 dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
266 dbus_uint64_t **array,
268 #endif /* DBUS_HAVE_INT64 */
269 dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
275 dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
285 dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
290 dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
294 dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
303 #endif /* DBUS_PROTOCOL_H */