We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The read_byte(), read_short(), read_int(), and read_long() methods in StreamInput return unsigned integers.
read_byte()
read_short()
read_int()
read_long()
StreamInput
Attempt to deserialize any value with a negative sign bit, for example
input = StreamInput(b"\xff") self.assertEqual(input.read_byte(), -1)
AssertionError: 255 != -1
input = StreamInput(b"\xff\xff\xff\xff\") self.assertEqual(input.read_int(), -1)
AssertionError: 4294967295 != -1
Python int value matches the signed Java value from OpenSearch
int
The text was updated successfully, but these errors were encountered:
I see (at least) 3 possible approaches here, listed roughly in my preference order
return b - 256 if b >= 128 else b
Sorry, something went wrong.
(1) works for me. Do you have an an XKCD for (2) and (3)?
2:
3:
Bonus, the int.from_bytes() approach is so much better than this mess:
int.from_bytes()
def read_int(self) -> int: return ((self.read_byte() & 0xFF) << 24) | ((self.read_byte() & 0xFF) << 16) | ((self.read_byte() & 0xFF) << 8) | (self.read_byte() & 0xFF) def read_long(self) -> int: return self.read_int() << 32 | self.read_int() & 0xFFFFFFFF
dbwiddis
Successfully merging a pull request may close this issue.
What is the bug?
The
read_byte()
,read_short()
,read_int()
, andread_long()
methods inStreamInput
return unsigned integers.How can one reproduce the bug?
Attempt to deserialize any value with a negative sign bit, for example
What is the expected behavior?
Python
int
value matches the signed Java value from OpenSearchDo you have any additional context?
The text was updated successfully, but these errors were encountered: