[Spice-devel,v2,24/43] Read values from primitive fields

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

Details

Message ID 1436363656-4266-25-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:53 p.m.
Store into references for future usage.

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

Patch hide | download patch | download mbox

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index cd653b3..da89def 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -166,6 +166,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
 
@@ -181,6 +204,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"):