1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-marshal-basic.c Marshalling routines for basic (primitive) types
4 * Copyright (C) 2002 CodeFactory AB
5 * Copyright (C) 2003, 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 #include "dbus-internals.h"
26 #include "dbus-marshal-basic.h"
31 * @defgroup DBusMarshal marshaling and unmarshaling
32 * @ingroup DBusInternals
33 * @brief functions to marshal/unmarshal data from the wire
35 * Types and functions related to converting primitive data types from
36 * wire format to native machine format, and vice versa.
38 * A signature is just a string with multiple types one after the other.
39 * for example a type is "i" or "(ii)", a signature is "i(ii)"
40 * where i is int and (ii) is struct { int; int; }
46 pack_4_octets (dbus_uint32_t value,
50 _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
52 if ((byte_order) == DBUS_LITTLE_ENDIAN)
53 *((dbus_uint32_t*)(data)) = DBUS_UINT32_TO_LE (value);
55 *((dbus_uint32_t*)(data)) = DBUS_UINT32_TO_BE (value);
59 pack_8_octets (DBusBasicValue value,
63 _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 8) == data);
65 #ifdef DBUS_HAVE_INT64
66 if ((byte_order) == DBUS_LITTLE_ENDIAN)
67 *((dbus_uint64_t*)(data)) = DBUS_UINT64_TO_LE (value.u64);
69 *((dbus_uint64_t*)(data)) = DBUS_UINT64_TO_BE (value.u64);
71 *(DBus8ByteStruct*)data = value.u64;
72 swap_8_octets ((DBusBasicValue*)data, byte_order);
77 * Packs a 32 bit unsigned integer into a data pointer.
79 * @param value the value
80 * @param byte_order the byte order to use
81 * @param data the data pointer
84 _dbus_pack_uint32 (dbus_uint32_t value,
88 pack_4_octets (value, byte_order, data);
92 * Packs a 32 bit signed integer into a data pointer.
94 * @param value the value
95 * @param byte_order the byte order to use
96 * @param data the data pointer
99 _dbus_pack_int32 (dbus_int32_t value,
103 pack_4_octets ((dbus_uint32_t) value, byte_order, data);
107 unpack_4_octets (int byte_order,
108 const unsigned char *data)
110 _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 4) == data);
112 if (byte_order == DBUS_LITTLE_ENDIAN)
113 return DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)data);
115 return DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)data);
118 #ifndef DBUS_HAVE_INT64
121 swap_bytes (unsigned char *data,
124 unsigned char *p1 = data;
125 unsigned char *p2 = data + len - 1;
129 unsigned char tmp = *p1;
137 #endif /* !DBUS_HAVE_INT64 */
140 swap_8_octets (DBusBasicValue *value,
143 if (byte_order != DBUS_COMPILER_BYTE_ORDER)
145 #ifdef DBUS_HAVE_INT64
146 value->u64 = DBUS_UINT64_SWAP_LE_BE (value->u64);
148 swap_bytes ((unsigned char *)value, 8);
153 static DBusBasicValue
154 unpack_8_octets (int byte_order,
155 const unsigned char *data)
159 _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 8) == data);
160 _dbus_assert (sizeof (r) == 8);
162 #ifdef DBUS_HAVE_INT64
163 if (byte_order == DBUS_LITTLE_ENDIAN)
164 r.u64 = DBUS_UINT64_FROM_LE (*(dbus_uint64_t*)data);
166 r.u64 = DBUS_UINT64_FROM_BE (*(dbus_uint64_t*)data);
168 r.u64 = *(DBus8ByteStruct*)data;
169 swap_8_octets (&r, byte_order);
176 * Unpacks a 32 bit unsigned integer from a data pointer
178 * @param byte_order The byte order to use
179 * @param data the data pointer
180 * @returns the integer
183 _dbus_unpack_uint32 (int byte_order,
184 const unsigned char *data)
186 return unpack_4_octets (byte_order, data);
190 * Unpacks a 32 bit signed integer from a data pointer
192 * @param byte_order The byte order to use
193 * @param data the data pointer
194 * @returns the integer
197 _dbus_unpack_int32 (int byte_order,
198 const unsigned char *data)
200 return (dbus_int32_t) unpack_4_octets (byte_order, data);
204 set_4_octets (DBusString *str,
211 _dbus_assert (byte_order == DBUS_LITTLE_ENDIAN ||
212 byte_order == DBUS_BIG_ENDIAN);
214 data = _dbus_string_get_data_len (str, offset, 4);
216 _dbus_pack_uint32 (value, byte_order, data);
220 set_8_octets (DBusString *str,
222 DBusBasicValue value,
227 _dbus_assert (byte_order == DBUS_LITTLE_ENDIAN ||
228 byte_order == DBUS_BIG_ENDIAN);
230 data = _dbus_string_get_data_len (str, offset, 8);
232 pack_8_octets (value, byte_order, data);
236 * Sets the 4 bytes at the given offset to a marshaled unsigned
237 * integer, replacing anything found there previously.
239 * @param str the string to write the marshalled int to
240 * @param pos the byte offset where int should be written
241 * @param value the value
242 * @param byte_order the byte order to use
246 _dbus_marshal_set_uint32 (DBusString *str,
251 set_4_octets (str, pos, value, byte_order);
255 * Sets the existing marshaled string at the given offset with
256 * a new marshaled string. The given offset must point to
257 * an existing string or the wrong length will be deleted
258 * and replaced with the new string.
260 * Note: no attempt is made by this function to re-align
261 * any data which has been already marshalled after this
262 * string. Use with caution.
264 * @param str the string to write the marshalled string to
265 * @param pos the position of the marshaled string length
266 * @param value the value
267 * @param byte_order the byte order to use
268 * @param old_end_pos place to store byte after the nul byte of the old value
269 * @param new_end_pos place to store byte after the nul byte of the new value
270 * @returns #TRUE on success, #FALSE if no memory
274 set_string (DBusString *str,
281 int old_len, new_len;
284 _dbus_string_init_const (&dstr, value);
286 old_len = _dbus_marshal_read_uint32 (str, pos, byte_order, NULL);
288 new_len = _dbus_string_get_length (&dstr);
290 if (!_dbus_string_replace_len (&dstr, 0, new_len,
291 str, pos + 4, old_len))
294 _dbus_marshal_set_uint32 (str, pos, new_len, byte_order);
297 *old_end_pos = pos + 4 + old_len + 1;
299 *new_end_pos = pos + 4 + new_len + 1;
305 * Sets the existing marshaled signature at the given offset to a new
306 * marshaled signature. Same basic ideas as set_string().
308 * @param str the string to write the marshalled signature to
309 * @param pos the position of the marshaled signature length
310 * @param value the value
311 * @param byte_order the byte order to use
312 * @param old_end_pos place to store byte after the nul byte of the old value
313 * @param new_end_pos place to store byte after the nul byte of the new value
314 * @returns #TRUE on success, #FALSE if no memory
318 set_signature (DBusString *str,
325 int old_len, new_len;
328 _dbus_string_init_const (&dstr, value);
330 old_len = _dbus_string_get_byte (str, pos);
331 new_len = _dbus_string_get_length (&dstr);
333 if (!_dbus_string_replace_len (&dstr, 0, new_len,
334 str, pos + 1, old_len))
337 _dbus_string_set_byte (str, pos, new_len);
340 *old_end_pos = pos + 1 + old_len + 1;
342 *new_end_pos = pos + 1 + new_len + 1;
348 * Sets an existing basic type value to a new value.
349 * Arguments work the same way as _dbus_marshal_basic_type().
351 * @param str the string
352 * @param pos location of the current value
353 * @param type the type of the current and new values
354 * @param value the address of the new value
355 * @param byte_order byte order for marshaling
356 * @param old_end_pos location to store end position of the old value, or #NULL
357 * @param new_end_pos location to store end position of the new value, or #NULL
358 * @returns #FALSE if no memory
361 _dbus_marshal_set_basic (DBusString *str,
369 const DBusBasicValue *vp;
376 case DBUS_TYPE_BOOLEAN:
377 _dbus_string_set_byte (str, pos, vp->byt);
379 *old_end_pos = pos + 1;
381 *new_end_pos = pos + 1;
384 case DBUS_TYPE_INT32:
385 case DBUS_TYPE_UINT32:
386 pos = _DBUS_ALIGN_VALUE (pos, 4);
387 set_4_octets (str, pos, vp->u32, byte_order);
389 *old_end_pos = pos + 4;
391 *new_end_pos = pos + 4;
394 case DBUS_TYPE_INT64:
395 case DBUS_TYPE_UINT64:
396 case DBUS_TYPE_DOUBLE:
397 pos = _DBUS_ALIGN_VALUE (pos, 8);
398 set_8_octets (str, pos, *vp, byte_order);
400 *old_end_pos = pos + 8;
402 *new_end_pos = pos + 8;
405 case DBUS_TYPE_STRING:
406 case DBUS_TYPE_OBJECT_PATH:
407 return set_string (str, pos, vp->str, byte_order,
408 old_end_pos, new_end_pos);
410 case DBUS_TYPE_SIGNATURE:
411 return set_signature (str, pos, vp->str, byte_order,
412 old_end_pos, new_end_pos);
415 _dbus_assert_not_reached ("not a basic type");
422 read_4_octets (const DBusString *str,
427 pos = _DBUS_ALIGN_VALUE (pos, 4);
432 return unpack_4_octets (byte_order,
433 _dbus_string_get_const_data (str) + pos);
437 * Convenience function to demarshal a 32 bit unsigned integer.
439 * @param str the string containing the data
440 * @param byte_order the byte order
441 * @param pos the position in the string
442 * @param new_pos the new position of the string
443 * @returns the demarshaled integer.
446 _dbus_marshal_read_uint32 (const DBusString *str,
451 return read_4_octets (str, pos, byte_order, new_pos);
455 * Demarshals a basic-typed value. The "value" pointer is always
456 * the address of a variable of the basic type. So e.g.
457 * if the basic type is "double" then the pointer is
458 * a double*, and if it's "char*" then the pointer is
461 * A value of type #DBusBasicValue is guaranteed to be large enough to
462 * hold any of the types that may be returned, which is handy if you
463 * are trying to do things generically. For example you can pass
464 * a DBusBasicValue* in to this function, and then pass the same
465 * DBusBasicValue* in to _dbus_marshal_basic_type() in order to
466 * move a value from one place to another.
468 * @param str the string containing the data
469 * @param pos position in the string
470 * @param type type of value to demarshal
471 * @param value pointer to return value data
472 * @param byte_order the byte order
473 * @param new_pos pointer to update with new position, or #NULL
476 _dbus_marshal_read_basic (const DBusString *str,
483 const char *str_data;
486 _dbus_assert (_dbus_type_is_basic (type));
488 str_data = _dbus_string_get_const_data (str);
494 case DBUS_TYPE_BOOLEAN:
495 vp->byt = _dbus_string_get_byte (str, pos);
498 case DBUS_TYPE_INT32:
499 case DBUS_TYPE_UINT32:
500 pos = _DBUS_ALIGN_VALUE (pos, 4);
501 vp->u32 = *(dbus_uint32_t *)(str_data + pos);
502 if (byte_order != DBUS_COMPILER_BYTE_ORDER)
503 vp->u32 = DBUS_UINT32_SWAP_LE_BE (vp->u32);
506 case DBUS_TYPE_INT64:
507 case DBUS_TYPE_UINT64:
508 case DBUS_TYPE_DOUBLE:
509 pos = _DBUS_ALIGN_VALUE (pos, 8);
510 #ifdef DBUS_HAVE_INT64
511 if (byte_order != DBUS_COMPILER_BYTE_ORDER)
512 vp->u64 = DBUS_UINT64_SWAP_LE_BE (*(dbus_uint64_t*)(str_data + pos));
514 vp->u64 = *(dbus_uint64_t*)(str_data + pos);
516 vp->u64 = *(DBus8ByteStruct*) (str_data + pos);
517 swap_8_octets (vp, byte_order);
521 case DBUS_TYPE_STRING:
522 case DBUS_TYPE_OBJECT_PATH:
526 len = _dbus_marshal_read_uint32 (str, pos, byte_order, &pos);
528 vp->str = (char*) str_data + pos;
530 pos += len + 1; /* length plus nul */
533 case DBUS_TYPE_SIGNATURE:
537 len = _dbus_string_get_byte (str, pos);
540 vp->str = (char*) str_data + pos;
542 pos += len + 1; /* length plus nul */
546 _dbus_warn ("type %s not a basic type\n",
547 _dbus_type_to_string (type));
548 _dbus_assert_not_reached ("not a basic type");
557 * Reads an array of fixed-length basic values. Does not work for
558 * arrays of string or container types.
560 * This function returns the array in-place; it does not make a copy,
561 * and it does not swap the bytes.
563 * If you ask for #DBUS_TYPE_DOUBLE you will get a "const double*" back
564 * and the "value" argument should be a "const double**" and so on.
566 * @todo last I checked only the test suite uses this function
568 * @param str the string to read from
569 * @param pos position to read from
570 * @param element_type type of array elements
571 * @param value place to return the array
572 * @param n_elements place to return number of array elements
573 * @param byte_order the byte order, used to read the array length
574 * @param new_pos #NULL or location to store a position after the elements
577 _dbus_marshal_read_fixed_array (const DBusString *str,
585 dbus_uint32_t array_len;
588 _dbus_assert (_dbus_type_is_fixed (element_type));
589 _dbus_assert (_dbus_type_is_basic (element_type));
591 pos = _DBUS_ALIGN_VALUE (pos, 4);
593 array_len = _dbus_marshal_read_uint32 (str, pos, byte_order, &pos);
595 alignment = _dbus_type_get_alignment (element_type);
597 pos = _DBUS_ALIGN_VALUE (pos, alignment);
599 *(const DBusBasicValue**) value = (void*) _dbus_string_get_const_data_len (str, pos, array_len);
601 *n_elements = array_len / alignment;
604 *new_pos = pos + array_len;
608 marshal_4_octets (DBusString *str,
617 _dbus_assert (sizeof (value) == 4);
619 if (byte_order != DBUS_COMPILER_BYTE_ORDER)
620 value = DBUS_UINT32_SWAP_LE_BE (value);
622 orig_len = _dbus_string_get_length (str);
624 retval = _dbus_string_insert_4_aligned (str, insert_at,
625 (const unsigned char *)&value);
629 *pos_after = insert_at + (_dbus_string_get_length (str) - orig_len);
630 _dbus_assert (*pos_after <= _dbus_string_get_length (str));
637 marshal_8_octets (DBusString *str,
639 DBusBasicValue value,
646 _dbus_assert (sizeof (value) == 8);
648 swap_8_octets (&value, byte_order);
650 orig_len = _dbus_string_get_length (str);
652 retval = _dbus_string_insert_8_aligned (str, insert_at,
653 (const unsigned char *)&value);
656 *pos_after = insert_at + _dbus_string_get_length (str) - orig_len;
664 MARSHAL_AS_SIGNATURE,
665 MARSHAL_AS_BYTE_ARRAY
669 marshal_len_followed_by_bytes (int marshal_as,
672 const unsigned char *value,
673 int data_len, /* doesn't include nul if any */
678 DBusString value_str;
681 _dbus_assert (byte_order == DBUS_LITTLE_ENDIAN || byte_order == DBUS_BIG_ENDIAN);
682 if (insert_at > _dbus_string_get_length (str))
683 _dbus_warn ("insert_at = %d string len = %d data_len = %d\n",
684 insert_at, _dbus_string_get_length (str), data_len);
686 if (marshal_as == MARSHAL_AS_BYTE_ARRAY)
687 value_len = data_len;
689 value_len = data_len + 1; /* value has a nul */
691 /* FIXME this is probably broken for byte arrays because
692 * DBusString wants strings to be nul-terminated?
693 * Maybe I planned on this when writing init_const_len though
695 _dbus_string_init_const_len (&value_str, value, value_len);
699 if (marshal_as == MARSHAL_AS_SIGNATURE)
701 if (!_dbus_string_insert_byte (str, pos, data_len))
708 if (!marshal_4_octets (str, pos, data_len,
713 if (!_dbus_string_copy_len (&value_str, 0, value_len,
719 _dbus_assert (_dbus_string_equal_substring (&value_str, 0, value_len,
721 _dbus_verbose_bytes_of_string (str, pos, value_len);
732 /* Delete what we've inserted */
733 _dbus_string_delete (str, insert_at, pos - insert_at);
739 marshal_string (DBusString *str,
745 return marshal_len_followed_by_bytes (MARSHAL_AS_STRING,
746 str, insert_at, value,
748 byte_order, pos_after);
752 marshal_signature (DBusString *str,
757 return marshal_len_followed_by_bytes (MARSHAL_AS_SIGNATURE,
758 str, insert_at, value,
760 DBUS_COMPILER_BYTE_ORDER, /* irrelevant */
765 * Marshals a basic-typed value. The "value" pointer is always the
766 * address of a variable containing the basic type value.
767 * So for example for int32 it will be dbus_int32_t*, and
768 * for string it will be const char**. This is for symmetry
769 * with _dbus_marshal_read_basic() and to have a simple
772 * @param str string to marshal to
773 * @param insert_at where to insert the value
774 * @param type type of value
775 * @param value pointer to a variable containing the value
776 * @param byte_order byte order
777 * @param pos_after #NULL or the position after the type
778 * @returns #TRUE on success
781 _dbus_marshal_write_basic (DBusString *str,
788 const DBusBasicValue *vp;
790 _dbus_assert (_dbus_type_is_basic (type));
797 case DBUS_TYPE_BOOLEAN:
798 if (!_dbus_string_insert_byte (str, insert_at, vp->byt))
801 *pos_after = insert_at + 1;
804 case DBUS_TYPE_INT32:
805 case DBUS_TYPE_UINT32:
806 return marshal_4_octets (str, insert_at, vp->u32,
807 byte_order, pos_after);
809 case DBUS_TYPE_INT64:
810 case DBUS_TYPE_UINT64:
811 case DBUS_TYPE_DOUBLE:
812 return marshal_8_octets (str, insert_at, *vp, byte_order, pos_after);
815 case DBUS_TYPE_STRING:
816 case DBUS_TYPE_OBJECT_PATH:
817 return marshal_string (str, insert_at, vp->str, byte_order, pos_after);
819 case DBUS_TYPE_SIGNATURE:
820 return marshal_signature (str, insert_at, vp->str, pos_after);
823 _dbus_assert_not_reached ("not a basic type");
830 marshal_1_octets_array (DBusString *str,
832 const unsigned char *value,
837 return marshal_len_followed_by_bytes (MARSHAL_AS_BYTE_ARRAY,
838 str, insert_at, value, n_elements,
839 byte_order, pos_after);
843 swap_array (DBusString *str,
849 _dbus_assert (_DBUS_ALIGN_VALUE (array_start, alignment) == (unsigned) array_start);
851 if (byte_order != DBUS_COMPILER_BYTE_ORDER)
856 /* we use const_data and cast it off so DBusString can be a const string
857 * for the unit tests. don't ask.
859 d = (unsigned char*) _dbus_string_get_const_data (str) + array_start;
860 end = d + n_elements * alignment;
866 #ifdef DBUS_HAVE_INT64
867 *((dbus_uint64_t*)d) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)d));
869 swap_8_bytes ((DBusBasicValue*) d);
876 _dbus_assert (alignment == 4);
880 *((dbus_uint32_t*)d) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)d));
888 marshal_fixed_array (DBusString *str,
890 const DBusBasicValue *value,
900 old_string_len = _dbus_string_get_length (str);
902 /* The array length is the length in bytes of the array,
903 * *excluding* alignment padding.
905 if (!marshal_4_octets (str, insert_at, n_elements * alignment,
906 byte_order, &array_start))
909 _dbus_verbose ("marshaled len %d at %d array start %d\n", n_elements * alignment, insert_at, array_start);
911 /* Note that we do alignment padding unconditionally
912 * even if the array is empty; this means that
913 * padding + len is always equal to the number of bytes
917 if (!_dbus_string_insert_alignment (str, &array_start, alignment))
920 _dbus_string_init_const_len (&t,
921 (const unsigned char*) value,
922 n_elements * alignment);
924 if (!_dbus_string_copy (&t, 0,
928 swap_array (str, array_start, n_elements, byte_order, alignment);
933 _dbus_string_delete (str, insert_at,
934 _dbus_string_get_length (str) - old_string_len);
940 * Marshals an array of values of fixed-length type.
941 * _dbus_type_is_fixed() returns #TRUE for these types,
942 * which are the basic types minus the string-like types.
944 * The value argument should be the adddress of an
945 * array, so e.g. "const dbus_uint32_t**"
947 * @param str string to marshal to
948 * @param insert_at where to insert the value
949 * @param element_type type of array elements
950 * @param value address of an array to marshal
951 * @param len number of elements in the array
952 * @param byte_order byte order
953 * @param pos_after #NULL or the position after the type
954 * @returns #TRUE on success
957 _dbus_marshal_write_fixed_array (DBusString *str,
965 const void* vp = *(const DBusBasicValue**)value;
967 _dbus_assert (_dbus_type_is_fixed (element_type));
969 switch (element_type)
971 case DBUS_TYPE_BOOLEAN:
972 /* FIXME: we canonicalize to 0 or 1 for the single boolean case
973 * should we here too ? */
975 return marshal_1_octets_array (str, insert_at, vp, n_elements, byte_order, pos_after);
977 case DBUS_TYPE_INT32:
978 case DBUS_TYPE_UINT32:
979 return marshal_fixed_array (str, insert_at, vp, n_elements, byte_order, 4, pos_after);
981 case DBUS_TYPE_INT64:
982 case DBUS_TYPE_UINT64:
983 case DBUS_TYPE_DOUBLE:
984 return marshal_fixed_array (str, insert_at, vp, n_elements, byte_order, 8, pos_after);
988 _dbus_assert_not_reached ("non fixed type in array write");
997 * Skips over a basic-typed value, reporting the following position.
999 * @param str the string containing the data
1000 * @param type type of value to read
1001 * @param byte_order the byte order
1002 * @param pos pointer to position in the string,
1003 * updated on return to new position
1006 _dbus_marshal_skip_basic (const DBusString *str,
1013 case DBUS_TYPE_BYTE:
1014 case DBUS_TYPE_BOOLEAN:
1017 case DBUS_TYPE_INT32:
1018 case DBUS_TYPE_UINT32:
1019 *pos = _DBUS_ALIGN_VALUE (*pos, 4);
1022 case DBUS_TYPE_INT64:
1023 case DBUS_TYPE_UINT64:
1024 case DBUS_TYPE_DOUBLE:
1025 *pos = _DBUS_ALIGN_VALUE (*pos, 8);
1028 case DBUS_TYPE_STRING:
1029 case DBUS_TYPE_OBJECT_PATH:
1033 len = _dbus_marshal_read_uint32 (str, *pos, byte_order, pos);
1035 *pos += len + 1; /* length plus nul */
1038 case DBUS_TYPE_SIGNATURE:
1042 len = _dbus_string_get_byte (str, *pos);
1044 *pos += len + 2; /* length byte plus length plus nul */
1048 _dbus_warn ("type %s not a basic type\n",
1049 _dbus_type_to_string (type));
1050 _dbus_assert_not_reached ("not a basic type");
1056 * Skips an array, returning the next position.
1058 * @param str the string containing the data
1059 * @param element_type the type of array elements
1060 * @param byte_order the byte order
1061 * @param pos pointer to position in the string,
1062 * updated on return to new position
1065 _dbus_marshal_skip_array (const DBusString *str,
1070 dbus_uint32_t array_len;
1074 i = _DBUS_ALIGN_VALUE (*pos, 4);
1076 array_len = _dbus_marshal_read_uint32 (str, i, byte_order, &i);
1078 alignment = _dbus_type_get_alignment (element_type);
1080 i = _DBUS_ALIGN_VALUE (i, alignment);
1082 *pos = i + array_len;
1086 * Gets the alignment requirement for the given type;
1087 * will be 1, 4, or 8.
1089 * @param typecode the type
1090 * @returns alignment of 1, 4, or 8
1093 _dbus_type_get_alignment (int typecode)
1097 case DBUS_TYPE_BYTE:
1098 case DBUS_TYPE_BOOLEAN:
1099 case DBUS_TYPE_VARIANT:
1100 case DBUS_TYPE_SIGNATURE:
1102 case DBUS_TYPE_INT32:
1103 case DBUS_TYPE_UINT32:
1104 /* this stuff is 4 since it starts with a length */
1105 case DBUS_TYPE_STRING:
1106 case DBUS_TYPE_OBJECT_PATH:
1107 case DBUS_TYPE_ARRAY:
1109 case DBUS_TYPE_INT64:
1110 case DBUS_TYPE_UINT64:
1111 case DBUS_TYPE_DOUBLE:
1112 /* struct is 8 since it could contain an 8-aligned item
1113 * and it's simpler to just always align structs to 8;
1114 * we want the amount of padding in a struct of a given
1115 * type to be predictable, not location-dependent.
1117 case DBUS_TYPE_STRUCT:
1121 _dbus_assert_not_reached ("unknown typecode in _dbus_type_get_alignment()");
1128 * Return #TRUE if the typecode is a valid typecode.
1129 * #DBUS_TYPE_INVALID surprisingly enough is not considered valid, and
1130 * random unknown bytes aren't either. This function is safe with
1133 * @returns #TRUE if valid
1136 _dbus_type_is_valid (int typecode)
1140 case DBUS_TYPE_BYTE:
1141 case DBUS_TYPE_BOOLEAN:
1142 case DBUS_TYPE_INT32:
1143 case DBUS_TYPE_UINT32:
1144 case DBUS_TYPE_INT64:
1145 case DBUS_TYPE_UINT64:
1146 case DBUS_TYPE_DOUBLE:
1147 case DBUS_TYPE_STRING:
1148 case DBUS_TYPE_OBJECT_PATH:
1149 case DBUS_TYPE_SIGNATURE:
1150 case DBUS_TYPE_ARRAY:
1151 case DBUS_TYPE_STRUCT:
1152 case DBUS_TYPE_VARIANT:
1160 #define TYPE_IS_CONTAINER(typecode) \
1161 ((typecode) == DBUS_TYPE_STRUCT || \
1162 (typecode) == DBUS_TYPE_VARIANT || \
1163 (typecode) == DBUS_TYPE_ARRAY)
1166 * A "container type" can contain basic types, or nested
1167 * container types. #DBUS_TYPE_INVALID is not a container type.
1168 * This function will crash if passed a typecode that isn't
1169 * in dbus-protocol.h
1171 * @returns #TRUE if type is a container
1174 _dbus_type_is_container (int typecode)
1176 /* only reasonable (non-line-noise) typecodes are allowed */
1177 _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID);
1178 return TYPE_IS_CONTAINER (typecode);
1182 * A "basic type" is a somewhat arbitrary concept, but the intent
1183 * is to include those types that are fully-specified by a single
1184 * typecode, with no additional type information or nested
1185 * values. So all numbers and strings are basic types and
1186 * structs, arrays, and variants are not basic types.
1187 * #DBUS_TYPE_INVALID is not a basic type.
1189 * This function is defined to return #TRUE for exactly those
1190 * types that can be written with _dbus_marshal_basic_type()
1191 * and read with _dbus_marshal_read_basic().
1193 * This function will crash if passed a typecode that isn't
1194 * in dbus-protocol.h
1196 * @returns #TRUE if type is basic
1199 _dbus_type_is_basic (int typecode)
1201 /* only reasonable (non-line-noise) typecodes are allowed */
1202 _dbus_assert (_dbus_type_is_valid (typecode) || typecode == DBUS_TYPE_INVALID);
1204 /* everything that isn't invalid or a container */
1205 return !(typecode == DBUS_TYPE_INVALID || TYPE_IS_CONTAINER (typecode));
1209 * Tells you whether values of this type can change length if you set
1210 * them to some other value. For this purpose, you assume that the
1211 * first byte of the old and new value would be in the same location,
1212 * so alignment padding is not a factor.
1214 * @returns #FALSE if the type can occupy different lengths
1217 _dbus_type_is_fixed (int typecode)
1221 case DBUS_TYPE_BYTE:
1222 case DBUS_TYPE_BOOLEAN:
1223 case DBUS_TYPE_INT32:
1224 case DBUS_TYPE_UINT32:
1225 case DBUS_TYPE_INT64:
1226 case DBUS_TYPE_UINT64:
1227 case DBUS_TYPE_DOUBLE:
1235 * If in verbose mode, print a block of binary data.
1237 * @todo right now it prints even if not in verbose mode
1239 * @param data the data
1240 * @param len the length of the data
1241 * @param offset where to start counting for byte indexes
1244 _dbus_verbose_bytes (const unsigned char *data,
1249 const unsigned char *aligned;
1251 _dbus_assert (len >= 0);
1253 /* Print blanks on first row if appropriate */
1254 aligned = _DBUS_ALIGN_ADDRESS (data, 4);
1257 _dbus_assert (aligned <= data);
1259 if (aligned != data)
1261 _dbus_verbose ("%4d\t%p: ", - (data - aligned), aligned);
1262 while (aligned != data)
1264 _dbus_verbose (" ");
1269 /* now print the bytes */
1273 if (_DBUS_ALIGN_ADDRESS (&data[i], 4) == &data[i])
1275 _dbus_verbose ("%4d\t%p: ",
1276 offset + i, &data[i]);
1279 if (data[i] >= 32 &&
1281 _dbus_verbose (" '%c' ", data[i]);
1283 _dbus_verbose ("0x%s%x ",
1284 data[i] <= 0xf ? "0" : "", data[i]);
1288 if (_DBUS_ALIGN_ADDRESS (&data[i], 4) == &data[i])
1291 _dbus_verbose ("BE: %d LE: %d",
1292 _dbus_unpack_uint32 (DBUS_BIG_ENDIAN, &data[i-4]),
1293 _dbus_unpack_uint32 (DBUS_LITTLE_ENDIAN, &data[i-4]));
1296 _DBUS_ALIGN_ADDRESS (&data[i], 8) == &data[i])
1298 #ifdef DBUS_HAVE_INT64
1299 /* I think I probably mean "GNU libc printf" and not "GNUC"
1300 * but we'll wait until someone complains. If you hit this,
1301 * just turn off verbose mode as a workaround.
1304 _dbus_verbose (" u64: 0x%llx",
1305 *(dbus_uint64_t*)&data[i-8]);
1308 _dbus_verbose (" dbl: %g",
1309 *(double*)&data[i-8]);
1312 _dbus_verbose ("\n");
1316 _dbus_verbose ("\n");
1320 * Dump the given part of the string to verbose log.
1322 * @param str the string
1323 * @param start the start of range to dump
1324 * @param len length of range
1327 _dbus_verbose_bytes_of_string (const DBusString *str,
1334 real_len = _dbus_string_get_length (str);
1336 _dbus_assert (start >= 0);
1338 if (start > real_len)
1340 _dbus_verbose (" [%d,%d) is not inside string of length %d\n",
1341 start, len, real_len);
1345 if ((start + len) > real_len)
1347 _dbus_verbose (" [%d,%d) extends outside string of length %d\n",
1348 start, len, real_len);
1349 len = real_len - start;
1352 d = _dbus_string_get_const_data_len (str, start, len);
1354 _dbus_verbose_bytes (d, len, start);
1359 #ifdef DBUS_BUILD_TESTS
1360 #include "dbus-test.h"
1364 swap_test_array (void *array,
1370 _dbus_string_init_const_len (&t, array, len_bytes);
1371 swap_array (&t, 0, len_bytes / alignment, byte_order, alignment);
1374 #define MARSHAL_BASIC(typename, byte_order, literal) \
1376 v_##typename = literal; \
1377 if (!_dbus_marshal_write_basic (&str, pos, DBUS_TYPE_##typename, \
1379 byte_order, NULL)) \
1380 _dbus_assert_not_reached ("no memory"); \
1383 #define DEMARSHAL_BASIC(typename, byte_order) \
1385 _dbus_marshal_read_basic (&str, pos, DBUS_TYPE_##typename, &v_##typename, \
1386 byte_order, &pos); \
1389 #define DEMARSHAL_BASIC_AND_CHECK(typename, byte_order, literal) \
1391 DEMARSHAL_BASIC (typename, byte_order); \
1392 if (literal != v_##typename) \
1394 _dbus_verbose_bytes_of_string (&str, dump_pos, \
1395 _dbus_string_get_length (&str) - dump_pos); \
1396 _dbus_assert_not_reached ("demarshaled wrong value"); \
1400 #define MARSHAL_TEST(typename, byte_order, literal) \
1402 MARSHAL_BASIC (typename, byte_order, literal); \
1404 DEMARSHAL_BASIC_AND_CHECK (typename, byte_order, literal); \
1407 #define MARSHAL_TEST_STRCMP(typename, byte_order, literal) \
1409 MARSHAL_BASIC (typename, byte_order, literal); \
1411 DEMARSHAL_BASIC (typename, byte_order); \
1412 if (strcmp (literal, v_##typename) != 0) \
1414 _dbus_verbose_bytes_of_string (&str, dump_pos, \
1415 _dbus_string_get_length (&str) - dump_pos); \
1416 _dbus_warn ("literal '%s'\nvalue '%s'\n", literal, v_##typename); \
1417 _dbus_assert_not_reached ("demarshaled wrong value"); \
1421 #define MARSHAL_FIXED_ARRAY(typename, byte_order, literal) \
1423 v_ARRAY_##typename = literal; \
1424 if (!_dbus_marshal_write_fixed_array (&str, pos, DBUS_TYPE_##typename, \
1425 &v_ARRAY_##typename, _DBUS_N_ELEMENTS(literal), \
1426 byte_order, NULL)) \
1427 _dbus_assert_not_reached ("no memory"); \
1430 #define DEMARSHAL_FIXED_ARRAY(typename, byte_order) \
1432 _dbus_marshal_read_fixed_array (&str, pos, DBUS_TYPE_##typename, &v_ARRAY_##typename, \
1433 &n_elements, byte_order, &pos); \
1434 swap_test_array (v_ARRAY_##typename, n_elements * sizeof(v_ARRAY_##typename[0]), \
1435 byte_order, sizeof(v_ARRAY_##typename[0])); \
1438 #define DEMARSHAL_FIXED_ARRAY_AND_CHECK(typename, byte_order, literal) \
1440 DEMARSHAL_FIXED_ARRAY (typename, byte_order); \
1441 if (memcmp (literal, v_ARRAY_##typename, sizeof (literal) != 0)) \
1443 _dbus_verbose ("MARSHALED DATA\n"); \
1444 _dbus_verbose_bytes_of_string (&str, dump_pos, \
1445 _dbus_string_get_length (&str) - dump_pos); \
1446 _dbus_verbose ("LITERAL DATA\n"); \
1447 _dbus_verbose_bytes ((char*)literal, sizeof (literal), 0); \
1448 _dbus_verbose ("READ DATA\n"); \
1449 _dbus_verbose_bytes ((char*)v_ARRAY_##typename, sizeof (literal), 0); \
1450 _dbus_assert_not_reached ("demarshaled wrong fixed array value"); \
1454 #define MARSHAL_TEST_FIXED_ARRAY(typename, byte_order, literal) \
1456 MARSHAL_FIXED_ARRAY (typename, byte_order, literal); \
1458 DEMARSHAL_FIXED_ARRAY_AND_CHECK (typename, byte_order, literal); \
1462 _dbus_marshal_test (void)
1467 dbus_int32_t array4[3] = { 123, 456, 789 };
1468 #ifdef DBUS_HAVE_INT64
1469 dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff),
1470 DBUS_INT64_CONSTANT (0x456ffffffff),
1471 DBUS_INT64_CONSTANT (0x789ffffffff) };
1472 dbus_int64_t *v_ARRAY_INT64;
1474 dbus_int32_t *v_ARRAY_INT32;
1475 double *v_ARRAY_DOUBLE;
1479 dbus_int32_t v_INT32;
1480 dbus_uint32_t v_UINT32;
1481 dbus_int64_t v_INT64;
1482 dbus_uint64_t v_UINT64;
1483 unsigned char v_BYTE;
1484 unsigned char v_BOOLEAN;
1485 const char *v_STRING;
1486 const char *v_SIGNATURE;
1487 const char *v_OBJECT_PATH;
1490 if (!_dbus_string_init (&str))
1491 _dbus_assert_not_reached ("failed to init string");
1495 /* Marshal doubles */
1496 MARSHAL_BASIC (DOUBLE, DBUS_BIG_ENDIAN, 3.14);
1497 DEMARSHAL_BASIC (DOUBLE, DBUS_BIG_ENDIAN);
1499 if (!_DBUS_DOUBLES_BITWISE_EQUAL (t_DOUBLE, v_DOUBLE))
1500 _dbus_assert_not_reached ("got wrong double value");
1502 MARSHAL_BASIC (DOUBLE, DBUS_LITTLE_ENDIAN, 3.14);
1503 DEMARSHAL_BASIC (DOUBLE, DBUS_LITTLE_ENDIAN);
1505 if (!_DBUS_DOUBLES_BITWISE_EQUAL (t_DOUBLE, v_DOUBLE))
1506 _dbus_assert_not_reached ("got wrong double value");
1508 /* Marshal signed integers */
1509 MARSHAL_TEST (INT32, DBUS_BIG_ENDIAN, -12345678);
1510 MARSHAL_TEST (INT32, DBUS_LITTLE_ENDIAN, -12345678);
1512 /* Marshal unsigned integers */
1513 MARSHAL_TEST (UINT32, DBUS_BIG_ENDIAN, 0x12345678);
1514 MARSHAL_TEST (UINT32, DBUS_LITTLE_ENDIAN, 0x12345678);
1516 #ifdef DBUS_HAVE_INT64
1517 /* Marshal signed integers */
1518 MARSHAL_TEST (INT64, DBUS_BIG_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7));
1519 MARSHAL_TEST (INT64, DBUS_LITTLE_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7));
1521 /* Marshal unsigned integers */
1522 MARSHAL_TEST (UINT64, DBUS_BIG_ENDIAN, DBUS_UINT64_CONSTANT (0x123456789abc7));
1523 MARSHAL_TEST (UINT64, DBUS_LITTLE_ENDIAN, DBUS_UINT64_CONSTANT (0x123456789abc7));
1524 #endif /* DBUS_HAVE_INT64 */
1527 MARSHAL_TEST (BYTE, DBUS_BIG_ENDIAN, 5);
1528 MARSHAL_TEST (BYTE, DBUS_LITTLE_ENDIAN, 5);
1530 /* Marshal all possible bools! */
1531 MARSHAL_TEST (BOOLEAN, DBUS_BIG_ENDIAN, FALSE);
1532 MARSHAL_TEST (BOOLEAN, DBUS_LITTLE_ENDIAN, FALSE);
1533 MARSHAL_TEST (BOOLEAN, DBUS_BIG_ENDIAN, TRUE);
1534 MARSHAL_TEST (BOOLEAN, DBUS_LITTLE_ENDIAN, TRUE);
1536 /* Marshal strings */
1537 MARSHAL_TEST_STRCMP (STRING, DBUS_BIG_ENDIAN, "");
1538 MARSHAL_TEST_STRCMP (STRING, DBUS_LITTLE_ENDIAN, "");
1539 MARSHAL_TEST_STRCMP (STRING, DBUS_BIG_ENDIAN, "This is the dbus test string");
1540 MARSHAL_TEST_STRCMP (STRING, DBUS_LITTLE_ENDIAN, "This is the dbus test string");
1543 MARSHAL_TEST_STRCMP (OBJECT_PATH, DBUS_BIG_ENDIAN, "/a/b/c");
1544 MARSHAL_TEST_STRCMP (OBJECT_PATH, DBUS_LITTLE_ENDIAN, "/a/b/c");
1547 MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_BIG_ENDIAN, "");
1548 MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_LITTLE_ENDIAN, "");
1549 MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_BIG_ENDIAN, "a(ii)");
1550 MARSHAL_TEST_STRCMP (SIGNATURE, DBUS_LITTLE_ENDIAN, "a(ii)");
1553 MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_BIG_ENDIAN, array4);
1554 MARSHAL_TEST_FIXED_ARRAY (INT32, DBUS_LITTLE_ENDIAN, array4);
1556 #ifdef DBUS_HAVE_INT64
1557 MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_BIG_ENDIAN, array8);
1558 MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_LITTLE_ENDIAN, array8);
1564 * FIXME restore the set/pack tests
1567 #ifdef DBUS_HAVE_INT64
1568 /* set/pack 64-bit integers */
1569 _dbus_string_set_length (&str, 8);
1572 _dbus_marshal_set_int64 (&str, DBUS_LITTLE_ENDIAN,
1573 0, DBUS_INT64_CONSTANT (-0x123456789abc7));
1575 _dbus_assert (DBUS_INT64_CONSTANT (-0x123456789abc7) ==
1576 _dbus_unpack_int64 (DBUS_LITTLE_ENDIAN,
1577 _dbus_string_get_const_data (&str)));
1580 _dbus_marshal_set_int64 (&str, DBUS_BIG_ENDIAN,
1581 0, DBUS_INT64_CONSTANT (-0x123456789abc7));
1583 _dbus_assert (DBUS_INT64_CONSTANT (-0x123456789abc7) ==
1584 _dbus_unpack_int64 (DBUS_BIG_ENDIAN,
1585 _dbus_string_get_const_data (&str)));
1587 /* signed little pack */
1588 _dbus_pack_int64 (DBUS_INT64_CONSTANT (-0x123456789abc7),
1590 _dbus_string_get_data (&str));
1592 _dbus_assert (DBUS_INT64_CONSTANT (-0x123456789abc7) ==
1593 _dbus_unpack_int64 (DBUS_LITTLE_ENDIAN,
1594 _dbus_string_get_const_data (&str)));
1596 /* signed big pack */
1597 _dbus_pack_int64 (DBUS_INT64_CONSTANT (-0x123456789abc7),
1599 _dbus_string_get_data (&str));
1601 _dbus_assert (DBUS_INT64_CONSTANT (-0x123456789abc7) ==
1602 _dbus_unpack_int64 (DBUS_BIG_ENDIAN,
1603 _dbus_string_get_const_data (&str)));
1605 /* unsigned little */
1606 _dbus_marshal_set_uint64 (&str, DBUS_LITTLE_ENDIAN,
1607 0, DBUS_UINT64_CONSTANT (0x123456789abc7));
1609 _dbus_assert (DBUS_UINT64_CONSTANT (0x123456789abc7) ==
1610 _dbus_unpack_uint64 (DBUS_LITTLE_ENDIAN,
1611 _dbus_string_get_const_data (&str)));
1614 _dbus_marshal_set_uint64 (&str, DBUS_BIG_ENDIAN,
1615 0, DBUS_UINT64_CONSTANT (0x123456789abc7));
1617 _dbus_assert (DBUS_UINT64_CONSTANT (0x123456789abc7) ==
1618 _dbus_unpack_uint64 (DBUS_BIG_ENDIAN,
1619 _dbus_string_get_const_data (&str)));
1621 /* unsigned little pack */
1622 _dbus_pack_uint64 (DBUS_UINT64_CONSTANT (0x123456789abc7),
1624 _dbus_string_get_data (&str));
1626 _dbus_assert (DBUS_UINT64_CONSTANT (0x123456789abc7) ==
1627 _dbus_unpack_uint64 (DBUS_LITTLE_ENDIAN,
1628 _dbus_string_get_const_data (&str)));
1630 /* unsigned big pack */
1631 _dbus_pack_uint64 (DBUS_UINT64_CONSTANT (0x123456789abc7),
1633 _dbus_string_get_data (&str));
1635 _dbus_assert (DBUS_UINT64_CONSTANT (0x123456789abc7) ==
1636 _dbus_unpack_uint64 (DBUS_BIG_ENDIAN,
1637 _dbus_string_get_const_data (&str)));
1638 #endif /* DBUS_HAVE_INT64 */
1640 /* set/pack 32-bit integers */
1641 _dbus_string_set_length (&str, 4);
1644 _dbus_marshal_set_int32 (&str, DBUS_LITTLE_ENDIAN,
1647 _dbus_assert (-0x123456 ==
1648 _dbus_unpack_int32 (DBUS_LITTLE_ENDIAN,
1649 _dbus_string_get_const_data (&str)));
1652 _dbus_marshal_set_int32 (&str, DBUS_BIG_ENDIAN,
1655 _dbus_assert (-0x123456 ==
1656 _dbus_unpack_int32 (DBUS_BIG_ENDIAN,
1657 _dbus_string_get_const_data (&str)));
1659 /* signed little pack */
1660 _dbus_pack_int32 (-0x123456,
1662 _dbus_string_get_data (&str));
1664 _dbus_assert (-0x123456 ==
1665 _dbus_unpack_int32 (DBUS_LITTLE_ENDIAN,
1666 _dbus_string_get_const_data (&str)));
1668 /* signed big pack */
1669 _dbus_pack_int32 (-0x123456,
1671 _dbus_string_get_data (&str));
1673 _dbus_assert (-0x123456 ==
1674 _dbus_unpack_int32 (DBUS_BIG_ENDIAN,
1675 _dbus_string_get_const_data (&str)));
1677 /* unsigned little */
1678 _dbus_marshal_set_uint32 (&str, DBUS_LITTLE_ENDIAN,
1681 _dbus_assert (0x123456 ==
1682 _dbus_unpack_uint32 (DBUS_LITTLE_ENDIAN,
1683 _dbus_string_get_const_data (&str)));
1686 _dbus_marshal_set_uint32 (&str, DBUS_BIG_ENDIAN,
1689 _dbus_assert (0x123456 ==
1690 _dbus_unpack_uint32 (DBUS_BIG_ENDIAN,
1691 _dbus_string_get_const_data (&str)));
1693 /* unsigned little pack */
1694 _dbus_pack_uint32 (0x123456,
1696 _dbus_string_get_data (&str));
1698 _dbus_assert (0x123456 ==
1699 _dbus_unpack_uint32 (DBUS_LITTLE_ENDIAN,
1700 _dbus_string_get_const_data (&str)));
1702 /* unsigned big pack */
1703 _dbus_pack_uint32 (0x123456,
1705 _dbus_string_get_data (&str));
1707 _dbus_assert (0x123456 ==
1708 _dbus_unpack_uint32 (DBUS_BIG_ENDIAN,
1709 _dbus_string_get_const_data (&str)));
1711 #endif /* set/pack tests for integers */
1713 /* Strings in-place set */
1714 byte_order = DBUS_LITTLE_ENDIAN;
1718 _dbus_string_set_length (&str, 0);
1720 /* reset pos for the macros */
1723 MARSHAL_TEST_STRCMP (STRING, byte_order, "Hello world");
1725 /* Set it to something longer */
1726 _dbus_string_init_const (&t, "Hello world foo");
1728 v_STRING = _dbus_string_get_const_data (&t);
1729 _dbus_marshal_set_basic (&str, 0, DBUS_TYPE_STRING,
1730 &v_STRING, byte_order, NULL, NULL);
1732 _dbus_marshal_read_basic (&str, 0, DBUS_TYPE_STRING,
1733 &v_STRING, byte_order,
1735 _dbus_assert (strcmp (v_STRING, "Hello world foo") == 0);
1737 /* Set it to something shorter */
1738 _dbus_string_init_const (&t, "Hello");
1740 v_STRING = _dbus_string_get_const_data (&t);
1741 _dbus_marshal_set_basic (&str, 0, DBUS_TYPE_STRING,
1742 &v_STRING, byte_order, NULL, NULL);
1743 _dbus_marshal_read_basic (&str, 0, DBUS_TYPE_STRING,
1744 &v_STRING, byte_order,
1746 _dbus_assert (strcmp (v_STRING, "Hello") == 0);
1748 /* Do the other byte order */
1749 if (byte_order == DBUS_LITTLE_ENDIAN)
1750 byte_order = DBUS_BIG_ENDIAN;
1756 _dbus_string_free (&str);
1761 #endif /* DBUS_BUILD_TESTS */