◆ printFloat()
static printFloat |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- mixed
327 return preg_replace(
"/(\\.\\d+?)0+$/",
"$1", sprintf(
"%F", $value));
◆ readBool()
Reads a byte boolean
- Parameters
-
- Returns
- bool
97 return self::readByte($b,
false) === 0 ? false :
true;
◆ readByte()
static readByte |
( |
|
$c, |
|
|
|
$signed = true |
|
) |
| |
|
static |
Reads an unsigned/signed byte
- Parameters
-
- Returns
- int
120 self::checkLength($c, 1);
124 if(PHP_INT_SIZE === 8){
125 return $b << 56 >> 56;
127 return $b << 24 >> 24;
◆ readDouble()
static readDouble |
( |
|
$str | ) |
|
|
static |
- Parameters
-
- Returns
- mixed
336 self::checkLength($str, 8);
338 return ENDIANNESS === self::BIG_ENDIAN ? unpack(
"d", $str)[1] : unpack(
"d", strrev($str))[1];
◆ readFloat()
static readFloat |
( |
|
$str, |
|
|
int |
$accuracy = -1 |
|
) |
| |
|
static |
- Parameters
-
- Returns
- float
278 self::checkLength($str, 4);
279 $value =
ENDIANNESS === self::BIG_ENDIAN ? unpack(
"f", $str)[1] : unpack(
"f", strrev($str))[1];
281 return round($value, $accuracy);
◆ readInt()
- Parameters
-
- Returns
- int
231 self::checkLength($str, 4);
232 if(PHP_INT_SIZE === 8){
233 return unpack(
"N", $str)[1] << 32 >> 32;
235 return unpack(
"N", $str)[1];
◆ readLDouble()
static readLDouble |
( |
|
$str | ) |
|
|
static |
- Parameters
-
- Returns
- mixed
356 self::checkLength($str, 8);
358 return ENDIANNESS === self::BIG_ENDIAN ? unpack(
"d", strrev($str))[1] : unpack(
"d", $str)[1];
◆ readLFloat()
static readLFloat |
( |
|
$str, |
|
|
int |
$accuracy = -1 |
|
) |
| |
|
static |
- Parameters
-
- Returns
- float
303 self::checkLength($str, 4);
304 $value =
ENDIANNESS === self::BIG_ENDIAN ? unpack(
"f", strrev($str))[1] : unpack(
"f", $str)[1];
306 return round($value, $accuracy);
◆ readLInt()
- Parameters
-
- Returns
- int
254 self::checkLength($str, 4);
255 if(PHP_INT_SIZE === 8){
256 return unpack(
"V", $str)[1] << 32 >> 32;
258 return unpack(
"V", $str)[1];
◆ readLLong()
- Parameters
-
- Returns
- int|string
426 return self::readLong(strrev($str));
◆ readLong()
- Parameters
-
- Returns
- int|string
376 self::checkLength($x, 8);
377 if(PHP_INT_SIZE === 8){
378 $int = unpack(
"N*", $x);
380 return ($int[1] << 32) | $int[2];
383 for($i = 0; $i < 8; $i += 2){
384 $value = bcmul($value,
"65536", 0);
385 $value = bcadd($value, self::readShort(substr($x, $i, 2)), 0);
388 if(bccomp($value,
"9223372036854775807") == 1){
389 $value = bcadd($value,
"-18446744073709551616");
◆ readLShort()
static readLShort |
( |
|
$str | ) |
|
|
static |
Reads a 16-bit unsigned little-endian number
- Parameters
-
- Returns
- int
193 self::checkLength($str, 2);
195 return unpack(
"v", $str)[1];
◆ readLTriad()
static readLTriad |
( |
|
$str | ) |
|
|
static |
Reads a 3-byte little-endian number
- Parameters
-
- Returns
- mixed
73 self::checkLength($str, 3);
75 return unpack(
"V", $str .
"\x00")[1];
◆ readShort()
Reads a 16-bit unsigned big-endian number
- Parameters
-
- Returns
- int
153 self::checkLength($str, 2);
155 return unpack(
"n", $str)[1];
◆ readSignedLShort()
static readSignedLShort |
( |
|
$str | ) |
|
|
static |
Reads a 16-bit signed little-endian number
- Parameters
-
- Returns
- int
206 self::checkLength($str, 2);
207 if(PHP_INT_SIZE === 8){
208 return unpack(
"v", $str)[1] << 48 >> 48;
210 return unpack(
"v", $str)[1] << 16 >> 16;
◆ readSignedShort()
static readSignedShort |
( |
|
$str | ) |
|
|
static |
Reads a 16-bit signed big-endian number
- Parameters
-
- Returns
- int
166 self::checkLength($str, 2);
167 if(PHP_INT_SIZE === 8){
168 return unpack(
"n", $str)[1] << 48 >> 48;
170 return unpack(
"n", $str)[1] << 16 >> 16;
◆ readTriad()
Reads a 3-byte big-endian number
- Parameters
-
- Returns
- mixed
49 self::checkLength($str, 3);
51 return unpack(
"N",
"\x00" . $str)[1];
◆ readUnsignedVarInt()
static readUnsignedVarInt |
( |
|
$stream | ) |
|
|
static |
- Parameters
-
- Returns
- int
463 throw new \InvalidArgumentException(
"Varint did not terminate after 10 bytes!");
465 $value |= ((($b = $stream->getByte()) & 0x7f) << $i);
◆ readVarInt()
static readVarInt |
( |
|
$stream | ) |
|
|
static |
- Parameters
-
- Returns
- int
446 $shift = PHP_INT_SIZE === 8 ? 63 : 31;
447 $raw = self::readUnsignedVarInt($stream);
448 $temp = ((($raw << $shift) >> $shift) ^ $raw) >> 1;
450 return $temp ^ ($raw & (1 << $shift));
◆ writeBool()
Writes a byte boolean
- Parameters
-
- Returns
- bool|string
108 return self::writeByte($b ===
true ? 1 : 0);
◆ writeByte()
Writes an unsigned/signed byte
- Parameters
-
- Returns
- string
◆ writeDouble()
static writeDouble |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
347 return ENDIANNESS === self::BIG_ENDIAN ? pack(
"d", $value) : strrev(pack(
"d", $value));
◆ writeFloat()
static writeFloat |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
293 return ENDIANNESS === self::BIG_ENDIAN ? pack(
"f", $value) : strrev(pack(
"f", $value));
◆ writeInt()
static writeInt |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
245 return pack(
"N", $value);
◆ writeLDouble()
static writeLDouble |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
367 return ENDIANNESS === self::BIG_ENDIAN ? strrev(pack(
"d", $value)) : pack(
"d", $value);
◆ writeLFloat()
static writeLFloat |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
318 return ENDIANNESS === self::BIG_ENDIAN ? strrev(pack(
"f", $value)) : pack(
"f", $value);
◆ writeLInt()
static writeLInt |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
268 return pack(
"V", $value);
◆ writeLLong()
static writeLLong |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
435 return strrev(self::writeLong($value));
◆ writeLong()
static writeLong |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
402 if(PHP_INT_SIZE === 8){
403 return pack(
"NN", $value >> 32, $value & 0xFFFFFFFF);
407 if(bccomp($value,
"0") == -1){
408 $value = bcadd($value,
"18446744073709551616");
411 $x .= self::writeShort(bcmod(bcdiv($value,
"281474976710656"),
"65536"));
412 $x .= self::writeShort(bcmod(bcdiv($value,
"4294967296"),
"65536"));
413 $x .= self::writeShort(bcmod(bcdiv($value,
"65536"),
"65536"));
414 $x .= self::writeShort(bcmod($value,
"65536"));
◆ writeLShort()
static writeLShort |
( |
|
$value | ) |
|
|
static |
Writes a 16-bit signed/unsigned little-endian number
- Parameters
-
- Returns
- string
222 return pack(
"v", $value);
◆ writeLTriad()
static writeLTriad |
( |
|
$value | ) |
|
|
static |
Writes a 3-byte little-endian number
- Parameters
-
- Returns
- string
86 return substr(pack(
"V", $value), 0, -1);
◆ writeShort()
static writeShort |
( |
|
$value | ) |
|
|
static |
Writes a 16-bit signed/unsigned big-endian number
- Parameters
-
- Returns
- string
182 return pack(
"n", $value);
◆ writeTriad()
static writeTriad |
( |
|
$value | ) |
|
|
static |
Writes a 3-byte big-endian number
- Parameters
-
- Returns
- string
62 return substr(pack(
"N", $value), 1);
◆ writeUnsignedVarInt()
static writeUnsignedVarInt |
( |
|
$value | ) |
|
|
static |
- Parameters
-
- Returns
- string
488 for($i = 0; $i < 10; ++$i){
489 if(($value >> 7) !== 0){
490 $buf .= chr($value | 0x80);
492 $buf .= chr($value & 0x7f);
496 $value = (($value >> 7) & (PHP_INT_MAX >> 6));
498 throw new \InvalidArgumentException(
"Value too large to be encoded as a varint");
◆ writeVarInt()
- Parameters
-
- Returns
- string
478 return self::writeUnsignedVarInt(($v << 1) ^ ($v >> (PHP_INT_SIZE === 8 ? 63 : 31)));
◆ BIG_ENDIAN
◆ LITTLE_ENDIAN
const LITTLE_ENDIAN = 0x01 |
The documentation for this class was generated from the following file:
- src/pocketmine/utils/Binary.php