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

Fix length field conversion #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaelroland
Copy link

Since urllib3 removed their fork of the library again, I'm reposting this here in the hope that it will eventually be picked up.

@michaelroland
Copy link
Author

The chr() method interprets its argument as Unicode code point. Consequently, chr(x).encode() only works for encoding (unsigned) integers with values between 0x00..0x7F (ASCII subset) into bytes, but not for values between 0x80..0xFF. However, single-byte length fields currently encoded using chr(x).encode() are unsigned 1-byte integers with values between 0..255 (0x00..0xFF).

This PR improves conversion between integers and byte-strings by relying on the pack/unpack methods of the struct standard library to get consistent encodeding and decoding of integer values with well-defined format.

@michaelroland michaelroland marked this pull request as ready for review October 19, 2022 13:22
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