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

Add support for reset_file_obj #113

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Conversation

tloubrieu-jpl
Copy link

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

Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f3957b6) 95.75% compared to head (09cabca) 96.05%.

❗ Current head 09cabca differs from pull request most recent head aa1cef5. Consider uploading reports for the commit aa1cef5 to get more accurate results

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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@ddasilva ddasilva left a 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.

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.
Copy link
Collaborator

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

@@ -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()
Copy link
Collaborator

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():
Copy link
Collaborator

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."""

@tloubrieu-jpl
Copy link
Author

Thanks @ddasilva , I made the changes you requested.

@ddasilva ddasilva merged commit 0b5a630 into CCSDSPy:main Feb 20, 2024
6 checks passed
@ddasilva
Copy link
Collaborator

Merged. Thanks @tloubrieu-jpl !

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