This repository was archived by the owner on Apr 22, 2024. It is now read-only.
This repository was archived by the owner on Apr 22, 2024. It is now read-only.
fix BinaryData inconsistencies and also make it accept any packable #420
Closed
Description
currently BinaryData has many inconsistencies, like not initializing with a False
object, but accepting it on its pack method:
In [1]: from pyof.foundation.basic_types import BinaryData
In [2]: BinaryData([])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-170088959e05> in <module>()
----> 1 BinaryData([])
python-openflow/pyof/foundation/basic_types.py in __init__(self, value)
423 """
424 if not isinstance(value, bytes):
--> 425 raise ValueError('BinaryData must contain bytes.')
426 super().__init__(value)
427
ValueError: BinaryData must contain bytes.
In [3]: BinaryData().pack([])
Out[3]: b''
Or not accepting None
in initialization:
In [4]: BinaryData(None)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-6b71433feedd> in <module>()
----> 1 BinaryData(None)
python-openflow/pyof/foundation/basic_types.py in __init__(self, value)
423 """
424 if not isinstance(value, bytes):
--> 425 raise ValueError('BinaryData must contain bytes.')
426 super().__init__(value)
427
ValueError: BinaryData must contain bytes.
Furthermore, any packable object can become a BinaryData, so I see no reason not to accept it as value. This can be very useful, like for accepting unknown structures like in the optional HelloMessage body.
Many of these fixes were implemented in #392, but since the PR was rejected I am separating them in other PRs.
Metadata
Metadata
Assignees
Labels
No labels