summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2004-12-30 23:34:23 +0000
committerHavoc Pennington <hp@redhat.com>2004-12-30 23:34:23 +0000
commit00999397cef16fa989d055f52a3974f5897ca3b1 (patch)
tree22a80e7ee362f001c98160488d9453efaceb5d67
parent6e492b1ba11069375fd8c7eeeb74ad7d2ed88638 (diff)
- add variant reader
- further squish the iterator structs
-rw-r--r--dbus/dbus-marshal-recursive.c43
-rw-r--r--dbus/dbus-marshal-recursive.h12
2 files changed, 48 insertions, 7 deletions
diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c
index dd1d6526..f9dab444 100644
--- a/dbus/dbus-marshal-recursive.c
+++ b/dbus/dbus-marshal-recursive.c
@@ -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
diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h
index ef71831e..8e50fdc9 100644
--- a/dbus/dbus-marshal-recursive.h
+++ b/dbus/dbus-marshal-recursive.h
@@ -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 {