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, 2005 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"
82 #define DBUS_TYPE_SIGNATURE ((int) 'g')
83 #define DBUS_TYPE_SIGNATURE_AS_STRING "g"
86 #define DBUS_TYPE_ARRAY ((int) 'a')
87 #define DBUS_TYPE_ARRAY_AS_STRING "a"
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 ")"
106 #define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
107 #define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
108 #define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
109 #define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
110 #define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
113 _hack_dbus_type_to_string (int type)
117 case DBUS_TYPE_INVALID:
119 case DBUS_TYPE_BOOLEAN:
121 case DBUS_TYPE_INT32:
123 case DBUS_TYPE_UINT32:
125 case DBUS_TYPE_DOUBLE:
127 case DBUS_TYPE_STRING:
129 case DBUS_TYPE_OBJECT_PATH:
130 return "object_path";
131 case DBUS_TYPE_SIGNATURE:
133 case DBUS_TYPE_STRUCT:
135 case DBUS_TYPE_ARRAY:
137 case DBUS_TYPE_VARIANT:
139 case DBUS_STRUCT_BEGIN_CHAR:
140 return "begin_struct";
141 case DBUS_STRUCT_END_CHAR:
148 #define _dbus_type_to_string(t) _hack_dbus_type_to_string(t)
150 /****************************************************** Remove later */
152 #ifdef WORDS_BIGENDIAN
153 #define DBUS_COMPILER_BYTE_ORDER DBUS_BIG_ENDIAN
155 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
158 #define DBUS_UINT32_SWAP_LE_BE_CONSTANT(val) ((dbus_uint32_t) ( \
159 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x000000ffU) << 24) | \
160 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x0000ff00U) << 8) | \
161 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0x00ff0000U) >> 8) | \
162 (((dbus_uint32_t) (val) & (dbus_uint32_t) 0xff000000U) >> 24)))
164 #ifdef DBUS_HAVE_INT64
166 #define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) ((dbus_uint64_t) ( \
167 (((dbus_uint64_t) (val) & \
168 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000000000ff)) << 56) | \
169 (((dbus_uint64_t) (val) & \
170 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000000000ff00)) << 40) | \
171 (((dbus_uint64_t) (val) & \
172 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000000000ff0000)) << 24) | \
173 (((dbus_uint64_t) (val) & \
174 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00000000ff000000)) << 8) | \
175 (((dbus_uint64_t) (val) & \
176 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x000000ff00000000)) >> 8) | \
177 (((dbus_uint64_t) (val) & \
178 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x0000ff0000000000)) >> 24) | \
179 (((dbus_uint64_t) (val) & \
180 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
181 (((dbus_uint64_t) (val) & \
182 (dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
183 #endif /* DBUS_HAVE_INT64 */
185 #define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
186 #define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
188 #ifdef DBUS_HAVE_INT64
189 #define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
190 #define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
191 #endif /* DBUS_HAVE_INT64 */
193 #ifdef WORDS_BIGENDIAN
194 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) (val))
195 #define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
196 #define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
197 #define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
198 # ifdef DBUS_HAVE_INT64
199 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
200 #define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
201 #define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
202 #define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
203 # endif /* DBUS_HAVE_INT64 */
205 #define DBUS_INT32_TO_LE(val) ((dbus_int32_t) (val))
206 #define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
207 #define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
208 #define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
209 # ifdef DBUS_HAVE_INT64
210 #define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
211 #define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
212 #define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
213 #define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
214 # endif /* DBUS_HAVE_INT64 */
217 /* The transformation is symmetric, so the FROM just maps to the TO. */
218 #define DBUS_INT32_FROM_LE(val) (DBUS_INT32_TO_LE (val))
219 #define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
220 #define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
221 #define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
222 #ifdef DBUS_HAVE_INT64
223 #define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
224 #define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
225 #define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
226 #define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
227 #endif /* DBUS_HAVE_INT64 */
229 #ifdef DBUS_HAVE_INT64
232 dbus_uint32_t first32;
233 dbus_uint32_t second32;
235 #endif /* DBUS_HAVE_INT64 */
241 #ifdef DBUS_HAVE_INT64
253 void _dbus_pack_int32 (dbus_int32_t value,
255 unsigned char *data);
256 dbus_int32_t _dbus_unpack_int32 (int byte_order,
257 const unsigned char *data);
258 void _dbus_pack_uint32 (dbus_uint32_t value,
260 unsigned char *data);
261 dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
262 const unsigned char *data);
265 dbus_bool_t _dbus_marshal_set_basic (DBusString *str,
272 dbus_bool_t _dbus_marshal_write_basic (DBusString *str,
278 dbus_bool_t _dbus_marshal_write_basic_array (DBusString *str,
285 void _dbus_marshal_read_basic (const DBusString *str,
291 void _dbus_marshal_skip_basic (const DBusString *str,
295 void _dbus_marshal_skip_array (const DBusString *str,
299 void _dbus_marshal_set_uint32 (DBusString *str,
303 dbus_uint32_t _dbus_marshal_read_uint32 (const DBusString *str,
307 dbus_bool_t _dbus_type_is_valid (int typecode);
308 int _dbus_type_get_alignment (int typecode);
309 dbus_bool_t _dbus_type_is_basic (int typecode);
310 dbus_bool_t _dbus_type_is_container (int typecode);
311 dbus_bool_t _dbus_type_length_varies (int typecode);
316 #endif /* DBUS_MARSHAL_H */