-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add support for reset_file_obj #113
Conversation
…od multiple time on the same stream.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
+ Coverage 95.75% 96.05% +0.29%
==========================================
Files 7 7
Lines 707 710 +3
==========================================
+ Hits 677 682 +5
+ Misses 30 28 -2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good, thanks! There are some surface-level changes to make then this can be merged.
ccsdspy/packet_types.py
Outdated
reset_file_obj : bool | ||
If True, leave the file object, when it is file buffer, where it was before load is called. | ||
Otherwise, (default), leave the file stream pos after the read packets. | ||
Does not apply when file is a file location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor wording adjustment, I'd just say "Does not apply when file is a string" I had to double take for a second to figure out what file location exactly meant
ccsdspy/packet_types.py
Outdated
@@ -621,6 +641,7 @@ def _load(file, fields, converters, decoder_name, include_primary_header=False): | |||
the decoder_name is not one of the allowed values | |||
""" | |||
if hasattr(file, "read"): | |||
pos = file.tell() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call this variable file_pos
so it reads adjacent to file_bytes
@@ -229,3 +235,11 @@ def test_variable_length_rejects_bit_offset(): | |||
), | |||
] | |||
) | |||
|
|||
|
|||
def test_load_without_moving_file_buffer_pos(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Tests that load(..., reset_file_obj=True) works as intended."""
Thanks @ddasilva , I made the changes you requested. |
Merged. Thanks @tloubrieu-jpl ! |
So to be able to recall the .load of the method of the Packet Types multiple time on the same file buffer, as needed when one need to parse once the packet at a coarse level to decide what the finer packet structure is and the parse them again.
Fixes #111