diff options
author | Havoc Pennington <hp@redhat.com> | 2005-01-27 23:39:26 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2005-01-27 23:39:26 +0000 |
commit | fddbc09c4a9125fcb168fb31ff300d4132919ea6 (patch) | |
tree | b9f9779991f96ea4207a6795679a2f55087ac8ed /dbus/dbus-marshal-basic.c | |
parent | 382d5ad0b4adf0070948fc2da623bc52894a7788 (diff) | |
download | dbus-fddbc09c4a9125fcb168fb31ff300d4132919ea6.tar.gz |
2005-01-27 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message.c: byteswap the message if you init an
iterator to read/write from it
* dbus/dbus-marshal-byteswap.c: new file implementing
_dbus_marshal_byteswap()
* dbus/dbus-marshal-basic.c: add _dbus_swap_array()
Diffstat (limited to 'dbus/dbus-marshal-basic.c')
-rw-r--r-- | dbus/dbus-marshal-basic.c | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index 5cb43b88..cd5d4e45 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -820,6 +820,53 @@ marshal_1_octets_array (DBusString *str, return TRUE; } +/** + * Swaps the elements of an array to the opposite byte order + * + * @param data start of array + * @param n_elements number of elements + * @param alignment size of each element + */ +void +_dbus_swap_array (unsigned char *data, + int n_elements, + int alignment) +{ + unsigned char *d; + unsigned char *end; + + _dbus_assert (_DBUS_ALIGN_ADDRESS (data, alignment) == data); + + /* we use const_data and cast it off so DBusString can be a const string + * for the unit tests. don't ask. + */ + d = data; + end = d + (n_elements * alignment); + + if (alignment == 8) + { + while (d != end) + { +#ifdef DBUS_HAVE_INT64 + *((dbus_uint64_t*)d) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)d)); +#else + swap_8_bytes ((DBusBasicValue*) d); +#endif + d += 8; + } + } + else + { + _dbus_assert (alignment == 4); + + while (d != end) + { + *((dbus_uint32_t*)d) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)d)); + d += 4; + } + } +} + static void swap_array (DBusString *str, int array_start, @@ -831,37 +878,11 @@ swap_array (DBusString *str, if (byte_order != DBUS_COMPILER_BYTE_ORDER) { - unsigned char *d; - unsigned char *end; - /* we use const_data and cast it off so DBusString can be a const string * for the unit tests. don't ask. */ - d = (unsigned char*) _dbus_string_get_const_data (str) + array_start; - end = d + n_elements * alignment; - - if (alignment == 8) - { - while (d != end) - { -#ifdef DBUS_HAVE_INT64 - *((dbus_uint64_t*)d) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)d)); -#else - swap_8_bytes ((DBusBasicValue*) d); -#endif - d += 8; - } - } - else - { - _dbus_assert (alignment == 4); - - while (d != end) - { - *((dbus_uint32_t*)d) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)d)); - d += 4; - } - } + _dbus_swap_array ((unsigned char*) (_dbus_string_get_const_data (str) + array_start), + n_elements, alignment); } } |