[Spice-devel] [PATCH v3 45/51] Allows to specify wireshark name for enumerators

Frediano Ziglio fziglio at redhat.com
Tue Jul 21 09:46:15 PDT 2015


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/dissector.py    |  2 +-
 python_modules/ptypes.py       | 91 +++++++++++++++---------------------------
 python_modules/spice_parser.py |  2 +-
 3 files changed, 35 insertions(+), 60 deletions(-)

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 3f63341..5c6b6fc 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -737,7 +737,7 @@ def write_flags_func(writer, t, ws, tree, ti):
 
         desc = t.descs[v] if t.descs[v] else t.names[v]
         hf = HF(name, desc)
-        hf.ws_name = '%s_%s' % (t.name, t.names[v].lower())
+        hf.ws_name = '%s_%s' % (t.name, t.names[v].lower()) if not t.ws_names[v] else t.ws_names[v]
         hf.f_type = 'FT_BOOLEAN'
         hf.base = str(bits)
         hf.vals = 'TFS(&tfs_set_notset)'
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index a899b6c..8c92493 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -321,6 +321,39 @@ class TypeAlias(Type):
         return self.name
 
 class EnumBaseType(Type):
+    def __init__(self, bits, name, enums, attribute_list):
+        Type.__init__(self)
+        self.bits = bits
+        self.name = name
+
+        last = -1
+        names = {}
+        values = {}
+        descs = {}
+        ws_names = {}
+        for v in enums:
+            name = v[0]
+            desc = v[1][1]
+            ws_name = None if len(v[1]) < 3 else v[1][2]
+            if len(v) > 2:
+                value = v[2]
+            else:
+                value = last + 1
+            last = value
+
+            assert value not in names
+            names[value] = name
+            descs[value] = desc
+            ws_names[value] = ws_name
+            values[name] = value
+
+        self.names = names
+        self.values = values
+        self.descs = descs
+        self.ws_names = ws_names
+
+        self.attributes = fix_attributes(attribute_list)
+
     def is_enum(self):
         return isinstance(self, EnumType)
 
@@ -365,35 +398,6 @@ class EnumBaseType(Type):
 
 
 class EnumType(EnumBaseType):
-    def __init__(self, bits, name, enums, attribute_list):
-        Type.__init__(self)
-        self.bits = bits
-        self.name = name
-
-        last = -1
-        names = {}
-        values = {}
-        descs = {}
-        for v in enums:
-            name = v[0]
-            desc = v[1][1]
-            if len(v) > 2:
-                value = v[2]
-            else:
-                value = last + 1
-            last = value
-
-            assert value not in names
-            names[value] = name
-            descs[value] = desc
-            values[name] = value
-
-        self.names = names
-        self.values = values
-        self.descs = descs
-
-        self.attributes = fix_attributes(attribute_list)
-
     def __str__(self):
         return "enum %s" % self.name
 
@@ -422,35 +426,6 @@ class EnumType(EnumBaseType):
         writer.newline()
 
 class FlagsType(EnumBaseType):
-    def __init__(self, bits, name, flags, attribute_list):
-        Type.__init__(self)
-        self.bits = bits
-        self.name = name
-
-        last = -1
-        names = {}
-        values = {}
-        descs = {}
-        for v in flags:
-            name = v[0]
-            desc = v[1][1]
-            if len(v) > 2:
-                value = v[2]
-            else:
-                value = last + 1
-            last = value
-
-            assert value not in names
-            names[value] = name
-            descs[value] = desc
-            values[name] = value
-
-        self.names = names
-        self.values = values
-        self.descs = descs
-
-        self.attributes = fix_attributes(attribute_list)
-
     def __str__(self):
         return "flags %s" % self.name
 
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index 5326e59..3fde843 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -124,7 +124,7 @@ def SPICE_BNF():
                      int32_ ^ uint32_ ^ int64_ ^ uint64_ ^
                      typename).setName("type")
 
-        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(Group(ws_desc), default=[None,None]) + Optional(equals + integer))) + Optional(comma) + rbrace)
+        flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(Group(ws | ws_desc), default=[None,None]) + Optional(equals + integer))) + Optional(comma) + rbrace)
 
         messageSpec = Group(message_ + messageBody + attributes).setParseAction(lambda toks: ptypes.MessageType(None, toks[0][1], toks[0][2])) | typename
 
-- 
2.1.0



More information about the Spice-devel mailing list