python-openflow
python-openflow copied to clipboard
Primitive types after unpack and before pack
We know that at the very early stage of development we decided to use boot: primitive types and our types on attributes. Ex: UBInt8() and int on an attribute of a generic struct subclass.
But using the library perhaps makes more sense to hide all the UBInt* stuff. So we should define the attribute as UBInt8():
class Foo(GenericStruct):
a = UBInt8()
But when using makes more sense to use only integers:
>>> foo = Foo()
>>> foo.a = 8
>>> foo.pack()
The same should be done on unpack, and this is the most important part. Because when unpacking we should put there a python primitive value.
>>> foo.unpack(binary_data)
>>> type(foo.a)
(int)
The trick part is that in some cases (when is not primitive) we should accept only this complex type. Ex:
class Foo(GenericStruct):
a = Header()
foo.a
should only accept (before pack) only Header types.
We realized this when creating a new napp. The napp developer should not be aware of the lib internal types, like UBInt8()
Does that makes sense ?