[Spice-devel] [PATCH 26/33] Handle switch

Frediano Ziglio fziglio at redhat.com
Wed Jul 1 10:10:18 PDT 2015


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/dissector.py | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 6e9f0d6..f18b5b4 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -221,8 +221,47 @@ def read_array_len(writer, prefix, array, dest, scope, is_ptr):
     dest.write_ref(writer, 32, prefix+'.nelements', nelements)
     return nelements
 
+
 def write_switch(writer, container, switch, dest, scope):
-    pass
+    var = container.lookup_member(switch.variable)
+    var_type = var.member_type
+
+    if switch.has_attr("fixedsize"):
+        scope.variable_def("guint32", "save_output")
+        writer.assign("save_output", "output")
+
+    first = True
+    for c in switch.cases:
+        check = c.get_check(dest.read_ref(switch.variable), var_type)
+        m = c.member
+        with writer.if_block(check, not first, False) as block:
+            t = m.member_type
+            if switch.has_attr("anon"):
+                dest2 = dest
+            else:
+                if t.is_struct():
+                    dest2 = dest.child_sub(switch.name + "." + m.name, block)
+                else:
+                    dest2 = dest.child_sub(switch.name, block)
+
+            if t.is_pointer():
+                write_pointer(writer, container, m, t, dest2, block)
+            elif t.is_struct():
+                write_struct(writer, m, t, '-1', dest2, scope)
+            elif t.is_primitive():
+                write_member_primitive(writer, container, m, t, dest2, scope)
+            elif t.is_array():
+                nelements = read_array_len(writer, m.name, t, dest, block, False)
+                write_array(writer, container, m, nelements, t, dest2, block)
+            else:
+                writer.todo("Can't handle type %s" % m.member_type)
+
+        first = False
+
+    writer.newline()
+
+    if switch.has_attr("fixedsize"):
+        writer.assign("output", "save_output + %s" % switch.get_fixed_nw_size())
 
 def write_array(writer, container, member, nelements, array, dest, scope):
     assert(container and member)
-- 
2.1.0



More information about the Spice-devel mailing list