* @param int|string $n * @returns string long $n encoded as bytes * @internal This relies on 64-bit PHP. */
($n)
| 98 | * @internal This relies on 64-bit PHP. |
| 99 | */ |
| 100 | public static function encodeLong($n) |
| 101 | { |
| 102 | $n = (int) $n; |
| 103 | $n = ($n << 1) ^ ($n >> 63); |
| 104 | |
| 105 | if ($n >= 0 && $n < 0x80) { |
| 106 | return chr($n); |
| 107 | } |
| 108 | |
| 109 | $buf = []; |
| 110 | if (($n & ~0x7F) != 0) { |
| 111 | $buf[] = ($n | 0x80) & 0xFF; |
| 112 | $n = ($n >> 7) ^ (($n >> 63) << 57); // unsigned shift right ($n >>> 7) |
| 113 | |
| 114 | while ($n > 0x7F) { |
| 115 | $buf[] = ($n | 0x80) & 0xFF; |
| 116 | $n >>= 7; // $n is always positive here |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | $buf[] = $n; |
| 121 | return pack("C*", ...$buf); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @param float $datum |