[Spice-devel] [PATCH v4 14/41] dissector: Read values from primitive fields

Frediano Ziglio fziglio at redhat.com
Thu Jul 23 08:54:31 PDT 2015


Store into references for future usage.

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

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 128e157..29b098a 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -167,6 +167,29 @@ class SubDestination(Destination):
         return self.parent_dest.get_ref(self.member + "." + member, writer)
 
 
+def primitive_read_func(t):
+    assert(t.is_primitive())
+
+    signed = False
+    if isinstance(t, ptypes.IntegerType) and t.signed:
+        signed = True
+
+    size = t.get_fixed_nw_size()
+    if size == 1:
+        if signed:
+            return '(gint8) tvb_get_guint8'
+        return 'tvb_get_guint8'
+    elif size == 2:
+        if signed:
+            return '(gint32) (gint16) tvb_get_letohs'
+        return 'tvb_get_letohs'
+    elif size == 4:
+        return 'tvb_get_letohl'
+    elif size == 8:
+        return 'tvb_get_letoh64'
+    raise NotImplementedError('primitive size not supported %s %s' % (size, t))
+
+
 def write_switch(writer, container, switch, dest, scope):
     pass
 
@@ -182,6 +205,15 @@ def write_struct(writer, member, t, index, dest, scope):
 def write_member_primitive(writer, container, member, t, dest, scope):
     assert(t.is_primitive())
 
+    if member.has_attr("bytes_count"):
+        raise NotImplementedError("bytes_count not implemented")
+    if member.has_attr("bytes_count"):
+        dest_var = member.attributes["bytes_count"][0]
+    else:
+        dest_var = member.name
+    dest.write_ref(writer, t.get_fixed_nw_size() * 8, dest_var, '%s(glb->tvb, offset)' % primitive_read_func(t))
+    writer.increment("offset", t.get_fixed_nw_size())
+
 def write_member(writer, container, member, dest, scope):
 
     if member.has_attr("virtual"):
-- 
2.1.0



More information about the Spice-devel mailing list