- add variant reader
authorHavoc Pennington <hp@redhat.com>
Thu, 30 Dec 2004 23:34:23 +0000 (23:34 +0000)
committerHavoc Pennington <hp@redhat.com>
Thu, 30 Dec 2004 23:34:23 +0000 (23:34 +0000)
- further squish the iterator structs

dbus/dbus-marshal-recursive.c
dbus/dbus-marshal-recursive.h

index dd1d652..f9dab44 100644 (file)
@@ -145,8 +145,37 @@ array_reader_recurse (DBusTypeReader *sub,
                  _dbus_type_to_string (sub->u.array.element_type));
 }
 
+static void
+variant_reader_recurse (DBusTypeReader *sub,
+                        DBusTypeReader *parent)
+{
+  int sig_len;
+
+  _dbus_assert (!_dbus_type_reader_array_is_empty (parent));
+  
+  base_reader_recurse (sub, parent);
+
+  /* Variant is 1 byte sig length (without nul), signature with nul,
+   * padding to 8-boundary, then values
+   */
+
+  sig_len = _dbus_string_get_byte (sub->value_str, sub->value_pos);
+
+  sub->type_str = sub->value_str;
+  sub->type_pos = sub->value_pos + 1;
+  
+  sub->value_pos = sub->type_pos + sig_len + 1;
+  
+  sub->value_pos = _DBUS_ALIGN_VALUE (sub->value_pos, 8);
+
+  _dbus_verbose ("    type reader %p variant containing '%s'\n",
+                 sub,
+                 _dbus_string_get_const_data_len (sub->type_str,
+                                                  sub->type_pos, 0));
+}
+
 static int
-body_reader_get_current_type (DBusTypeReader *reader)
+base_reader_get_current_type (DBusTypeReader *reader)
 {
   int t;
 
@@ -369,7 +398,7 @@ array_reader_next (DBusTypeReader *reader,
 static const DBusTypeReaderClass body_reader_class = {
   "body",
   NULL, /* body is always toplevel, so doesn't get recursed into */
-  body_reader_get_current_type,
+  base_reader_get_current_type,
   base_reader_next
 };
 
@@ -387,6 +416,13 @@ static const DBusTypeReaderClass array_reader_class = {
   array_reader_next
 };
 
+static const DBusTypeReaderClass variant_reader_class = {
+  "variant",
+  variant_reader_recurse,
+  base_reader_get_current_type,
+  base_reader_next
+};
+
 void
 _dbus_type_reader_init (DBusTypeReader    *reader,
                         int                byte_order,
@@ -503,6 +539,9 @@ _dbus_type_reader_recurse (DBusTypeReader *reader,
     case DBUS_TYPE_ARRAY:
       sub->klass = &array_reader_class;
       break;
+    case DBUS_TYPE_VARIANT:
+      sub->klass = &variant_reader_class;
+      break;
     default:
       _dbus_verbose ("recursing into type %s\n", _dbus_type_to_string (t));
 #ifndef DBUS_DISABLE_CHECKS
index ef71831..8e50fdc 100644 (file)
@@ -37,7 +37,8 @@ typedef struct DBusTypeReaderClass DBusTypeReaderClass;
 
 struct DBusTypeReader
 {
-  int byte_order;
+  dbus_uint32_t byte_order : 8;
+  
   const DBusString *type_str;
   int type_pos;
   const DBusString *value_str;
@@ -60,15 +61,16 @@ struct DBusTypeReader
 
 struct DBusTypeWriter
 {
-  int byte_order;
+  dbus_uint32_t byte_order : 8;
+
+  dbus_uint32_t container_type : 8;
+
+  dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
   DBusString *type_str;
   int type_pos;
   DBusString *value_str;
   int value_pos;
 
-  dbus_uint32_t type_pos_is_expectation : 1; /* type_pos is an insertion point or an expected next type */
-
-  dbus_uint32_t container_type : 8;
   union
   {
     struct {