diff options
author | Jonathon Jongsma <jjongsma@redhat.com> | 2013-09-12 12:11:02 -0500 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@redhat.com> | 2013-10-23 11:41:43 -0500 |
commit | f3a47cc903a4a0137264431d0ebb4c01f2959969 (patch) | |
tree | 3f9ed14b8e519ee5a10a4e7337cab62805f6cdf2 /python_modules/ptypes.py | |
parent | 23fe54f11274e4117f4bffd033a7a045cb91de47 (diff) | |
download | spice-protocol-f3a47cc903a4a0137264431d0ebb4c01f2959969.tar.gz spice-protocol-f3a47cc903a4a0137264431d0ebb4c01f2959969.tar.xz spice-protocol-f3a47cc903a4a0137264431d0ebb4c01f2959969.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/ptypes.py')
-rw-r--r-- | python_modules/ptypes.py | 17 |
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) |