Add explanations
This commit is contained in:
parent
a9aab9163e
commit
13b27b3fac
|
@ -227,6 +227,7 @@ class database
|
||||||
* Pack the record values
|
* Pack the record values
|
||||||
*
|
*
|
||||||
* @param record $record The record
|
* @param record $record The record
|
||||||
|
* @const integer ARCH PHP architecture
|
||||||
*
|
*
|
||||||
* @return string Packed values
|
* @return string Packed values
|
||||||
*/
|
*/
|
||||||
|
@ -246,10 +247,20 @@ class database
|
||||||
|
|
||||||
// Packing the value and writing into the buffer of packed values
|
// Packing the value and writing into the buffer of packed values
|
||||||
$packed .= pack($column->type->value . $column->length, $value);
|
$packed .= pack($column->type->value . $column->length, $value);
|
||||||
} else if (ARCH === 64 &&
|
}
|
||||||
|
/**
|
||||||
|
* PHP builtin pack() ignores 64-bit integer values
|
||||||
|
* found on 64-bit PHP distributions
|
||||||
|
* @see https://www.php.net/manual/en/function.pack.php#109382
|
||||||
|
*
|
||||||
|
* In case of integer type on 64-bit PHP distributions
|
||||||
|
* we got to splice 64-bit integer into two separate longs
|
||||||
|
* next to each other in binary representation
|
||||||
|
*/
|
||||||
|
else if (ARCH === 64 &&
|
||||||
($column->type === type::integer ||
|
($column->type === type::integer ||
|
||||||
$column->type === type::integer_unsigned)
|
$column->type === type::integer_unsigned))
|
||||||
) {
|
{
|
||||||
// Initialize variables for left and right masks of the 64-bit variable
|
// Initialize variables for left and right masks of the 64-bit variable
|
||||||
$left = 0xffffffff00000000;
|
$left = 0xffffffff00000000;
|
||||||
$right = 0x00000000ffffffff;
|
$right = 0x00000000ffffffff;
|
||||||
|
@ -259,7 +270,7 @@ class database
|
||||||
// Bitwise and the value with the right mask to get the second half
|
// Bitwise and the value with the right mask to get the second half
|
||||||
$r = $record->values()[$column->name] & $right;
|
$r = $record->values()[$column->name] & $right;
|
||||||
|
|
||||||
// Pack into 64bit binary value
|
// Pack into 64bit binary value with two longs
|
||||||
$packed .= pack('NN', $l, $r);
|
$packed .= pack('NN', $l, $r);
|
||||||
} else {
|
} else {
|
||||||
// Other types
|
// Other types
|
||||||
|
@ -279,6 +290,7 @@ class database
|
||||||
* Unpack binary values and implement them as a `record` instance
|
* Unpack binary values and implement them as a `record` instance
|
||||||
*
|
*
|
||||||
* @param array $binaries Binary values in the same order as the columns
|
* @param array $binaries Binary values in the same order as the columns
|
||||||
|
* @const integer ARCH PHP architecture
|
||||||
*
|
*
|
||||||
* @return record The unpacked record from binary values
|
* @return record The unpacked record from binary values
|
||||||
*/
|
*/
|
||||||
|
@ -307,12 +319,22 @@ class database
|
||||||
|
|
||||||
// Writing into the buffer of read values
|
// Writing into the buffer of read values
|
||||||
$unpacked[] = $encoded;
|
$unpacked[] = $encoded;
|
||||||
} else if (ARCH === 64 &&
|
}
|
||||||
|
/**
|
||||||
|
* PHP builtin pack() ignores 64-bit integer values
|
||||||
|
* found on 64-bit PHP distributions
|
||||||
|
* @see https://www.php.net/manual/en/function.pack.php#109382
|
||||||
|
*
|
||||||
|
* In case of integer type on 64-bit PHP distributions
|
||||||
|
* we got to reconstruct previosly spliced integer value
|
||||||
|
*/
|
||||||
|
else if (ARCH === 64 &&
|
||||||
($column->type === type::integer ||
|
($column->type === type::integer ||
|
||||||
$column->type === type::integer_unsigned)
|
$column->type === type::integer_unsigned))
|
||||||
) {
|
{
|
||||||
// Unpacking the integer
|
// Unpacking the integer values into array of two longs
|
||||||
$value = unpack('N2', $binary ?? "\0");
|
$value = unpack('N2', $binary ?? "\0");
|
||||||
|
// Reconstructing original integer value
|
||||||
$unpacked[] = $value[1] << 32 | $value[2];
|
$unpacked[] = $value[1] << 32 | $value[2];
|
||||||
} else {
|
} else {
|
||||||
// Other types
|
// Other types
|
||||||
|
|
|
@ -62,6 +62,14 @@ enum type: string
|
||||||
{
|
{
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PHP builtin pack() ignores 64-bit integer values
|
||||||
|
* found on 64-bit PHP distributions
|
||||||
|
* @see https://www.php.net/manual/en/function.pack.php#109382
|
||||||
|
*
|
||||||
|
* Architecture-specific size should always be returned
|
||||||
|
*/
|
||||||
|
|
||||||
// If type is (unsigned) integer, return size of integer
|
// If type is (unsigned) integer, return size of integer
|
||||||
return (strtoupper($this->value) === 'I')
|
return (strtoupper($this->value) === 'I')
|
||||||
? PHP_INT_SIZE
|
? PHP_INT_SIZE
|
||||||
|
|
Loading…
Reference in New Issue