diff options
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_serializer.py')
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_serializer.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_serializer.py b/src/vpp-api/python/vpp_papi/vpp_serializer.py index 81ce53e378d..644aeac65c6 100644 --- a/src/vpp-api/python/vpp_papi/vpp_serializer.py +++ b/src/vpp-api/python/vpp_papi/vpp_serializer.py @@ -356,7 +356,10 @@ class VLAList_legacy(Packer): ) +# Will change to IntEnum after 21.04 release class VPPEnumType(Packer): + output_class = IntFlag + def __init__(self, name, msgdef, options=None): self.size = types['u32'].size self.name = name @@ -371,9 +374,9 @@ class VPPEnumType(Packer): continue ename, evalue = f e_hash[ename] = evalue - self.enum = IntFlag(name, e_hash) + self.enum = self.output_class(name, e_hash) types[name] = self - class_types[name] = VPPEnumType + class_types[name] = self.__class__ self.options = options def __getattr__(self, name): @@ -382,7 +385,6 @@ class VPPEnumType(Packer): def __bool__(self): return True - def pack(self, data, kwargs=None): if data is None: # Default to zero if not specified if self.options and 'default' in self.options: @@ -396,16 +398,23 @@ class VPPEnumType(Packer): x, size = types[self.enumtype].unpack(data, offset) return self.enum(x), size - @staticmethod - def _get_packer_with_options(f_type, options): - return VPPEnumType(f_type, types[f_type].msgdef, options=options) + @classmethod + def _get_packer_with_options(cls, f_type, options): + return cls(f_type, types[f_type].msgdef, options=options) def __repr__(self): - return "VPPEnumType(name=%s, msgdef=%s, options=%s)" % ( - self.name, self.msgdef, self.options + return "%s(name=%s, msgdef=%s, options=%s)" % ( + self.__class__.__name__, self.name, self.msgdef, self.options ) +class VPPEnumFlagType(VPPEnumType): + output_class = IntFlag + + def __init__(self, name, msgdef, options=None): + super(VPPEnumFlagType, self).__init__(name, msgdef, options) + + class VPPUnionType(Packer): def __init__(self, name, msgdef): self.name = name |