[Spice-devel,v2,32/43] Handle switch

Submitted by Frediano Ziglio on July 8, 2015, 1:54 p.m.

Details

Message ID 1436363656-4266-33-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 8, 2015, 1:54 p.m.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 python_modules/dissector.py | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index caf817f..b204c61 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -298,8 +298,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)