Skip to content

Commit

Permalink
MNT: Remove **parse_value_kwargs from parsing functions
Browse files Browse the repository at this point in the history
These are unused now that the packet itself can be used to get
the previously parsed values.
  • Loading branch information
greglucas committed Dec 15, 2024
1 parent 15750cd commit 4d4af20
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
5 changes: 2 additions & 3 deletions space_packet_parser/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ def _get_container_base_container(
def parse_ccsds_packet(self,
packet: packets.CCSDSPacket,
*,
root_container_name: str = "CCSDSPacket",
**parse_value_kwargs) -> packets.CCSDSPacket:
root_container_name: str = "CCSDSPacket") -> packets.CCSDSPacket:
"""Parse binary packet data according to the self.packet_definition object
Parameters
Expand All @@ -343,7 +342,7 @@ def parse_ccsds_packet(self,
"""
current_container: packets.SequenceContainer = self._sequence_container_cache[root_container_name]
while True:
current_container.parse(packet, **parse_value_kwargs)
current_container.parse(packet)

valid_inheritors = []
for inheritor_name in current_container.inheritors:
Expand Down
8 changes: 4 additions & 4 deletions space_packet_parser/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _calculate_size(self, packet: packets.CCSDSPacket) -> int:
"""
raise NotImplementedError()

def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.ParameterDataTypes:
def parse_value(self, packet: packets.CCSDSPacket) -> packets.ParameterDataTypes:
"""Parse a value from packet data, possibly using previously parsed data items to inform parsing.
Parameters
Expand Down Expand Up @@ -334,7 +334,7 @@ def _get_raw_buffer(self, packet: packets.CCSDSPacket) -> bytes:
).to_bytes(buflen_bytes, "big")
return raw_string_buffer

def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.StrParameter:
def parse_value(self, packet: packets.CCSDSPacket) -> packets.StrParameter:
"""Parse a string value from packet data, possibly using previously parsed data items to inform parsing.
Parameters
Expand Down Expand Up @@ -529,7 +529,7 @@ def _twos_complement(val: int, bit_width: int) -> int:

def parse_value(self,
packet: packets.CCSDSPacket,
**kwargs) -> Union[packets.FloatParameter, packets.IntParameter]:
) -> Union[packets.FloatParameter, packets.IntParameter]:
"""Parse a value from packet data, possibly using previously parsed data items to inform parsing.
Parameters
Expand Down Expand Up @@ -793,7 +793,7 @@ def _calculate_size(self, packet: packets.CCSDSPacket) -> int:
len_bits = self.linear_adjuster(len_bits)
return len_bits

def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.BinaryParameter:
def parse_value(self, packet: packets.CCSDSPacket) -> packets.BinaryParameter:
"""Parse a value from packet data, possibly using previously parsed data items to inform parsing.
Parameters
Expand Down
6 changes: 3 additions & 3 deletions space_packet_parser/packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def user_data(self) -> dict:

class Parseable(Protocol):
"""Defines an object that can be parsed from packet data."""
def parse(self, packet: CCSDSPacket, **parse_value_kwargs) -> None:
def parse(self, packet: CCSDSPacket) -> None:
"""Parse this entry from the packet data and add the necessary items to the packet."""


Expand Down Expand Up @@ -336,13 +336,13 @@ def __post_init__(self):
self.restriction_criteria = self.restriction_criteria or []
self.inheritors = self.inheritors or []

def parse(self, packet: CCSDSPacket, **parse_value_kwargs) -> None:
def parse(self, packet: CCSDSPacket) -> None:
"""Parse the entry list of parameters/containers in the order they are expected in the packet.
This could be recursive if the entry list contains SequenceContainers.
"""
for entry in self.entry_list:
entry.parse(packet=packet, **parse_value_kwargs)
entry.parse(packet=packet)


def ccsds_generator( # pylint: disable=too-many-branches,too-many-statements
Expand Down
17 changes: 8 additions & 9 deletions space_packet_parser/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_data_encoding(parameter_type_element: ElementTree.Element, ns: dict) ->
raise ValueError(f"No Data Encoding element found for Parameter Type "
f"{parameter_type_element.tag}: {parameter_type_element.attrib}")

def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.ParameterDataTypes:
def parse_value(self, packet: packets.CCSDSPacket) -> packets.ParameterDataTypes:
"""Using the parameter type definition and associated data encoding, parse a value from a bit stream starting
at the current cursor position.
Expand All @@ -134,7 +134,7 @@ def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.Paramete
parsed_value : packets.ParameterDataTypes
Resulting parsed parameter value
"""
return self.encoding.parse_value(packet, **kwargs)
return self.encoding.parse_value(packet)


class StringParameterType(ParameterType):
Expand Down Expand Up @@ -259,7 +259,7 @@ def get_enumeration_list_contents(element: ElementTree.Element, encoding: encodi
"Supported encodings for enums are FloatDataEncoding, IntegerDataEncoding, "
"and StringDataEncoding.")

def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.StrParameter:
def parse_value(self, packet: packets.CCSDSPacket) -> packets.StrParameter:
"""Using the parameter type definition and associated data encoding, parse a value from a bit stream starting
at the current cursor position.
Expand All @@ -274,7 +274,7 @@ def parse_value(self, packet: packets.CCSDSPacket, **kwargs) -> packets.StrParam
derived_value : packets.StrParameter
Resulting enum label associated with the (usually integer-)encoded data value.
"""
raw_enum_value = super().parse_value(packet, **kwargs).raw_value
raw_enum_value = super().parse_value(packet).raw_value
# Note: The enum lookup only operates on raw values. This is specified in Fig 4-43 in
# section 4.3.2.4.3.6 of the XTCE spec CCSDS 660.1-G-2
# Note, this doesn't prohibit a user from defining a calibrator on an encoding that is used for an enum lookup.
Expand Down Expand Up @@ -320,7 +320,7 @@ def __init__(self, name: str, encoding: encodings.DataEncoding, unit: Optional[s
f"encoded booleans is not specified in XTCE. e.g. is the string \"0\" truthy?")
super().__init__(name, encoding, unit)

def parse_value(self, packet: packets.CCSDSPacket, **kwargs):
def parse_value(self, packet: packets.CCSDSPacket):
"""Using the parameter type definition and associated data encoding, parse a value from a bit stream starting
at the current cursor position.
Expand All @@ -338,7 +338,7 @@ def parse_value(self, packet: packets.CCSDSPacket, **kwargs):
# NOTE: The XTCE spec states that Booleans are "a restricted form of
# enumeration." Enumerated parameters are only permitted to perform lookups based on raw encoded values
# (not calibrated ones). We force this by taking the bool of the raw form of the parsed parameter.
parsed_value = super().parse_value(packet, **kwargs).raw_value
parsed_value = super().parse_value(packet).raw_value
# NOTE: Boolean parameters may behave unexpectedly when encoded as String and Binary values.
# This is because it's not obvious nor specified in XTCE which values of
# binary encoded or string encoded data should be truthy/falsy.
Expand Down Expand Up @@ -553,10 +553,9 @@ class Parameter(packets.Parseable):
short_description: Optional[str] = None
long_description: Optional[str] = None

def parse(self, packet: packets.CCSDSPacket, **parse_value_kwargs) -> None:
def parse(self, packet: packets.CCSDSPacket) -> None:
"""Parse this parameter from the packet data.
Parse the parameter and add it to the packet dictionary.
"""
packet[self.name] = self.parameter_type.parse_value(
packet, **parse_value_kwargs)
packet[self.name] = self.parameter_type.parse_value(packet)

0 comments on commit 4d4af20

Please sign in to comment.