2003-01-02 Anders Carlsson <andersca@codefactory.se>
authorAnders Carlsson <andersca@codefactory.se>
Thu, 2 Jan 2003 10:09:46 +0000 (10:09 +0000)
committerAnders Carlsson <andersca@codefactory.se>
Thu, 2 Jan 2003 10:09:46 +0000 (10:09 +0000)
* dbus/dbus-marshal.c: (_dbus_marshal_utf8_string),
(_dbus_marshal_byte_array), (_dbus_demarshal_utf8_string),
(_dbus_marshal_test):
* dbus/dbus-marshal.h:
Add _dbus_marshal_byte_array and rename _dbus_marshal_string
to _dbus_marshal_utf8_string. Also fix some tests.

ChangeLog
dbus/dbus-marshal.c
dbus/dbus-marshal.h

index 1e20857..94f8beb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2003-01-02  Anders Carlsson  <andersca@codefactory.se>
+
+       * dbus/dbus-marshal.c: (_dbus_marshal_utf8_string),
+       (_dbus_marshal_byte_array), (_dbus_demarshal_utf8_string),
+       (_dbus_marshal_test):
+       * dbus/dbus-marshal.h:
+       Add _dbus_marshal_byte_array and rename _dbus_marshal_string
+       to _dbus_marshal_utf8_string. Also fix some tests.
+       
 2002-12-28  Harri Porten  <porten@kde.org>
 
        * configure.in: added check for C++ compiler and a very cheesy
index d7548ce..da72635 100644 (file)
@@ -173,17 +173,12 @@ _dbus_marshal_uint32 (DBusString    *str,
 }
 
 dbus_bool_t
-_dbus_marshal_string (DBusString    *str,
-                     int            byte_order,
-                     const char    *value)
+_dbus_marshal_utf8_string (DBusString    *str,
+                          int            byte_order,
+                          const char    *value)
 {
   int len;
 
-  if (!_dbus_string_set_length (str,
-                               DBUS_ALIGN_VALUE (_dbus_string_get_length (str),
-                                                 sizeof (dbus_uint32_t))))
-    return FALSE;
-
   len = strlen (value);
 
   if (!_dbus_marshal_uint32 (str, byte_order, len))
@@ -192,6 +187,17 @@ _dbus_marshal_string (DBusString    *str,
   return _dbus_string_append_len (str, value, len + 1);
 }
 
+dbus_bool_t
+_dbus_marshal_byte_array (DBusString          *str,
+                         int                  byte_order,
+                         const unsigned char *value,
+                         int                  len)
+{
+  if (!_dbus_marshal_uint32 (str, byte_order, len))
+    return FALSE;
+
+  return _dbus_string_append_len (str, value, len);
+}
 
 double
 _dbus_demarshal_double (DBusString  *str,
@@ -254,10 +260,10 @@ _dbus_demarshal_uint32  (DBusString *str,
 }
 
 char *
-_dbus_demarshal_string (DBusString *str,
-                       int         byte_order,
-                       int         pos,
-                       int        *new_pos)
+_dbus_demarshal_utf8_string (DBusString *str,
+                            int         byte_order,
+                            int         pos,
+                            int        *new_pos)
 {
   int len;
   char *retval;
@@ -401,25 +407,29 @@ _dbus_marshal_test (void)
   _dbus_assert (_dbus_demarshal_int32 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == -12345678);
   
   /* Marshal unsigned integers */
+  if (!_dbus_marshal_uint32 (&str, DBUS_BIG_ENDIAN, 0x12345678))
+    _dbus_assert_not_reached ("could not marshal signed integer value");
+  _dbus_assert (_dbus_demarshal_uint32 (&str, DBUS_BIG_ENDIAN, pos, &pos) == 0x12345678);
+  
   if (!_dbus_marshal_uint32 (&str, DBUS_LITTLE_ENDIAN, 0x12345678))
     _dbus_assert_not_reached ("could not marshal signed integer value");
   _dbus_assert (_dbus_demarshal_uint32 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == 0x12345678);
 
   /* Marshal strings */
   tmp1 = "This is the dbus test string";
-  if (!_dbus_marshal_string (&str, DBUS_LITTLE_ENDIAN, tmp1))
+  if (!_dbus_marshal_utf8_string (&str, DBUS_BIG_ENDIAN, tmp1))
     _dbus_assert_not_reached ("could not marshal string");
-  tmp2 = _dbus_demarshal_string (&str, DBUS_LITTLE_ENDIAN, pos, &pos);
+  tmp2 = _dbus_demarshal_utf8_string (&str, DBUS_BIG_ENDIAN, pos, &pos);
   _dbus_assert (strcmp (tmp1, tmp2) == 0);
   dbus_free (tmp2);
 
   tmp1 = "This is the dbus test string";
-  if (!_dbus_marshal_string (&str, DBUS_LITTLE_ENDIAN, tmp1))
+  if (!_dbus_marshal_utf8_string (&str, DBUS_LITTLE_ENDIAN, tmp1))
     _dbus_assert_not_reached ("could not marshal string");
-  tmp2 = _dbus_demarshal_string (&str, DBUS_LITTLE_ENDIAN, pos, &pos);
+  tmp2 = _dbus_demarshal_utf8_string (&str, DBUS_LITTLE_ENDIAN, pos, &pos);
   _dbus_assert (strcmp (tmp1, tmp2) == 0);
   dbus_free (tmp2);
-  
+
   _dbus_string_free (&str);
   
   return TRUE;
index e666304..88a3b1a 100644 (file)
 #define DBUS_COMPILER_BYTE_ORDER DBUS_LITTLE_ENDIAN
 #endif
 
-dbus_bool_t _dbus_marshal_double (DBusString    *str,
-                                 int            byte_order,
-                                 double         value);
-dbus_bool_t _dbus_marshal_int32  (DBusString    *str,
-                                 int            byte_order,
-                                 dbus_int32_t   value);
-dbus_bool_t _dbus_marshal_uint32 (DBusString    *str,
-                                 int            byte_order,
-                                 dbus_uint32_t  value);
-dbus_bool_t _dbus_marshal_string (DBusString    *str,
-                                 int            byte_order,
-                                 const char    *value);
+dbus_bool_t _dbus_marshal_double      (DBusString          *str,
+                                      int                  byte_order,
+                                      double               value);
+dbus_bool_t _dbus_marshal_int32       (DBusString          *str,
+                                      int                  byte_order,
+                                      dbus_int32_t         value);
+dbus_bool_t _dbus_marshal_uint32      (DBusString          *str,
+                                      int                  byte_order,
+                                      dbus_uint32_t        value);
+dbus_bool_t _dbus_marshal_utf8_string (DBusString          *str,
+                                      int                  byte_order,
+                                      const char          *value);
+dbus_bool_t _dbus_marshal_byte_array  (DBusString          *str,
+                                      int                  byte_order,
+                                      const unsigned char *value,
+                                      int                  len);
 
 
-double        _dbus_demarshal_double (DBusString *str,
-                                     int         byte_order,
-                                     int         pos,
-                                     int        *new_pos);
-dbus_int32_t  _dbus_demarshal_int32  (DBusString *str,
-                                     int         byte_order,
-                                     int         pos,
-                                     int        *new_pos);
-dbus_uint32_t _dbus_demarshal_uint32 (DBusString *str,
-                                     int         byte_order,
-                                     int         pos,
-                                     int        *new_pos);
-char *        _dbus_demarshal_string (DBusString *str,
-                                     int         byte_order,
-                                     int         pos,
-                                     int        *new_pos);
+double        _dbus_demarshal_double      (DBusString *str,
+                                          int         byte_order,
+                                          int         pos,
+                                          int        *new_pos);
+dbus_int32_t  _dbus_demarshal_int32       (DBusString *str,
+                                          int         byte_order,
+                                          int         pos,
+                                          int        *new_pos);
+dbus_uint32_t _dbus_demarshal_uint32      (DBusString *str,
+                                          int         byte_order,
+                                          int         pos,
+                                          int        *new_pos);
+char *        _dbus_demarshal_utf8_string (DBusString *str,
+                                          int         byte_order,
+                                          int         pos,
+                                          int        *new_pos);
+