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

Better struct module usage #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

homm
Copy link

@homm homm commented Jan 19, 2022

This improves usage of standard struct module. unpack_from function doesn't require extra copying as well as doesn't require data length match.

Also there was a several places where sequence of unpack calls can be replaced with single call.

-            tag = struct.unpack(self.endian_mark + "H",
-                       self.tiftag[pointer: pointer+2])[0]
-            value_type = struct.unpack(self.endian_mark + "H",
-                         self.tiftag[pointer + 2: pointer + 4])[0]
-            value_num = struct.unpack(self.endian_mark + "L",
-                                      self.tiftag[pointer + 4: pointer + 8]
-                                      )[0]
+            tag, value_type, value_num = unpack_from(
+                self.endian_mark + "HHL", self.tiftag, pointer)

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

Successfully merging this pull request may close these issues.

1 participant