Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive types after unpack and before pack #46

Open
ajoaoff opened this issue Jun 28, 2021 · 0 comments
Open

Primitive types after unpack and before pack #46

ajoaoff opened this issue Jun 28, 2021 · 0 comments

Comments

@ajoaoff
Copy link

ajoaoff commented Jun 28, 2021

Original issue opened by @beraldoleal at kytos#198.

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants