Skip to content

Commit

Permalink
add entity ID TLV eq custom method
Browse files Browse the repository at this point in the history
  • Loading branch information
robamu committed Sep 9, 2024
1 parent a514263 commit 9b9f629
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spacepackets/cfdp/tlv/tlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from spacepackets.exceptions import BytesTooShortError
from spacepackets.cfdp.exceptions import TlvTypeMissmatch
from spacepackets.util import UnsignedByteField


def map_enum_status_code_to_int(status_code: FilestoreResponseStatusCode) -> int:
Expand Down Expand Up @@ -502,6 +503,8 @@ def _set_fields(cls, instance: FileStoreResponseTlv, data: bytes):


class EntityIdTlv(AbstractTlvBase):
"""This helper class has a :py:meth:`__eq__` implementation which only compares the numerical value
of the entity IDs"""
TLV_TYPE = TlvType.ENTITY_ID

def __init__(self, entity_id: bytes):
Expand Down Expand Up @@ -540,3 +543,11 @@ def from_tlv(cls, cfdp_tlv: CfdpTlv) -> EntityIdTlv:
entity_id_tlv = cls.__empty()
entity_id_tlv.tlv = cfdp_tlv
return entity_id_tlv

def __eq__(self, other: AbstractTlvBase) -> bool:
"""Custom implementation which only compares the numerical value of the entity IDs"""
if not isinstance(other, EntityIdTlv):
return False
own_id = UnsignedByteField.from_bytes(self.value)
other_id = UnsignedByteField.from_bytes(other.value)
return own_id.value == other_id.value

0 comments on commit 9b9f629

Please sign in to comment.