[Spice-devel] [PATCH v4 35/41] codegen: Allows to specify wireshark name for enumerators

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


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

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 08adefd..8580ca8 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -736,7 +736,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 d0b26ba..e5d0ebd 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -328,9 +328,11 @@ class EnumBaseType(Type):
         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:
@@ -340,11 +342,13 @@ class EnumBaseType(Type):
             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)
 
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