-
Notifications
You must be signed in to change notification settings - Fork 99
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
Negative Numbers are converted to huge numbers #108
Comments
qrizly2
changed the title
Negative Numbers are converted as huge numbers
Negative Numbers are converted to huge numbers
Feb 20, 2024
I think i found the issue: but is this enough? [MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest] /**
* @test
*/
public function shouldNegativeReadInt32(): void
{
$expected = -4444;
self::assertSame($expected, $this->getBinaryRead(self::pack32bit(-4444))->readInt32());
}
public static function pack32bit(int $value): string
{
return pack(
'C4', ($value >> 0) & 0xFF, ($value >> 8) & 0xFF, ($value >> 16) & 0xFF, ($value >> 24) & 0xFF
);
} [MySQLReplication\BinaryDataReader\BinaryDataReader] public function readInt32(): int
{
$re = unpack('i', $this->read(self::UNSIGNED_INT32_LENGTH))[1];
return $re >= 0x80000000 ? $re - 0x100000000 : $re;
} |
Ok, it seems it is fine for the other int Types [MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest] /**
* @test
*/
public function shouldNegativeReadInt64(): void
{
$expected = '-4444';
self::assertSame($expected, $this->getBinaryRead(BinaryDataReader::pack64bit(-4444))->readInt64());
}
/**
* @test
*/
public function shouldNegativeReadInt8(): void
{
$expected = -44;
self::assertSame($expected, $this->getBinaryRead(self::pack8bit(-44))->readInt8());
}
/**
* @test
*/
public function shouldNegativeReadInt16(): void
{
$expected = -4444;
self::assertSame($expected, $this->getBinaryRead(self::pack16bit(-4444))->readInt16());
}
public static function pack16bit(int $value): string
{
return pack(
'C2', ($value >> 0) & 0xFF, ($value >> 8) & 0xFF
);
}
public static function pack8bit(int $value): string
{
return pack(
'C1', ($value >> 0) & 0xFF
);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SELECT VERSION();
): 5.7.36-logI already have this snippet in place to fix the values, but what should be the preferred way of doing this correctly?
The text was updated successfully, but these errors were encountered: