summaryrefslogtreecommitdiffstats
path: root/python_modules
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@redhat.com>2013-09-12 12:11:02 -0500
committerJonathon Jongsma <jjongsma@redhat.com>2013-10-23 11:41:43 -0500
commit31ef0c626d75a6af416c32551b8b3a7bb34eac7b (patch)
tree2268c8a1bddbdd4e33a785bc7c4fc55c96f375a8 /python_modules
parentfa640286f436342a7d53ddae5cc28fd0a4659512 (diff)
downloadspice-common-31ef0c626d75a6af416c32551b8b3a7bb34eac7b.tar.gz
spice-common-31ef0c626d75a6af416c32551b8b3a7bb34eac7b.tar.xz
spice-common-31ef0c626d75a6af416c32551b8b3a7bb34eac7b.zip
codegen: Add a --generate-wireshark-dissector option
The wireshark protocol dissector is a bit out-of-date. Several new channel types and enums have been added. It would be nice if these values (and the translation between the value and the name) could be automatically generated so that updating the dissector was a slightly less manual process. This patch adds a commandline switch which generates both the enums and value-name lists in the format that wireshark expects.
Diffstat (limited to 'python_modules')
-rw-r--r--python_modules/ptypes.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index d9fbfe2..2bfbf0d 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -247,6 +247,23 @@ class EnumBaseType(Type):
def get_fixed_nw_size(self):
return self.bits / 8
+ # generates a value-name table suitable for use with the wireshark protocol
+ # dissector
+ def c_describe(self, writer):
+ writer.write("static const value_string %s_vs[] = " % codegen.prefix_underscore_lower(self.name))
+ writer.begin_block()
+ values = self.names.keys()
+ values.sort()
+ for i in values:
+ writer.write("{ ")
+ writer.write(self.c_enumname(i))
+ writer.write(", \"%s\" }," % self.names[i])
+ writer.newline()
+ writer.write("{ 0, NULL }")
+ writer.end_block(semicolon=True)
+ writer.newline()
+
+
class EnumType(EnumBaseType):
def __init__(self, bits, name, enums, attribute_list):
Type.__init__(self)