GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Binary Class Reference

Static Public Member Functions

static readTriad ($str)
 
static writeTriad ($value)
 
static readLTriad ($str)
 
static writeLTriad ($value)
 
static readBool ($b)
 
static writeBool ($b)
 
static readByte ($c, $signed=true)
 
static writeByte ($c)
 
static readShort ($str)
 
static readSignedShort ($str)
 
static writeShort ($value)
 
static readLShort ($str, $signed=true)
 
static writeLShort ($value)
 
static readInt ($str)
 
static writeInt ($value)
 
static readLInt ($str)
 
static writeLInt ($value)
 
static readFloat ($str)
 
static writeFloat ($value)
 
static readLFloat ($str)
 
static writeLFloat ($value)
 
static readDouble ($str)
 
static writeDouble ($value)
 
static readLDouble ($str)
 
static writeLDouble ($value)
 
static readLong ($x)
 
static writeLong ($value)
 
static readLLong ($str)
 
static writeLLong ($value)
 

Data Fields

const BIG_ENDIAN = 0x00
 
const LITTLE_ENDIAN = 0x01
 

Member Function Documentation

◆ readBool()

static readBool (   $b)
static

Reads a byte boolean

Parameters
$b
Returns
bool
78  {
79  return self::readByte($b, false) === 0 ? false : true;
80  }

◆ readByte()

static readByte (   $c,
  $signed = true 
)
static

Reads an unsigned/signed byte

Parameters
string$c
bool$signed
Returns
int
101  {
102  $b = ord($c{0});
103 
104  if($signed){
105  if(PHP_INT_SIZE === 8){
106  return $b << 56 >> 56;
107  }else{
108  return $b << 24 >> 24;
109  }
110  }else{
111  return $b;
112  }
113  }

◆ readDouble()

static readDouble (   $str)
static
236  {
237  return ENDIANNESS === self::BIG_ENDIAN ? unpack("d", $str)[1] : unpack("d", strrev($str))[1];
238  }

◆ readFloat()

static readFloat (   $str)
static
220  {
221  return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", $str)[1] : unpack("f", strrev($str))[1];
222  }

◆ readInt()

static readInt (   $str)
static
196  {
197  if(PHP_INT_SIZE === 8){
198  return unpack("N", $str)[1] << 32 >> 32;
199  }else{
200  return unpack("N", $str)[1];
201  }
202  }

◆ readLDouble()

static readLDouble (   $str)
static
244  {
245  return ENDIANNESS === self::BIG_ENDIAN ? unpack("d", strrev($str))[1] : unpack("d", $str)[1];
246  }

◆ readLFloat()

static readLFloat (   $str)
static
228  {
229  return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", strrev($str))[1] : unpack("f", $str)[1];
230  }

◆ readLInt()

static readLInt (   $str)
static
208  {
209  if(PHP_INT_SIZE === 8){
210  return unpack("V", $str)[1] << 32 >> 32;
211  }else{
212  return unpack("V", $str)[1];
213  }
214  }

◆ readLLong()

static readLLong (   $str)
static
291  {
292  return self::readLong(strrev($str));
293  }

◆ readLong()

static readLong (   $x)
static
252  {
253  if(PHP_INT_SIZE === 8){
254  list(, $int1, $int2) = unpack("N*", $x);
255 
256  return ($int1 << 32) | $int2;
257  }else{
258  $value = "0";
259  for($i = 0; $i < 8; $i += 2){
260  $value = bcmul($value, "65536", 0);
261  $value = bcadd($value, self::readShort(substr($x, $i, 2)), 0);
262  }
263 
264  if(bccomp($value, "9223372036854775807") == 1){
265  $value = bcadd($value, "-18446744073709551616");
266  }
267 
268  return $value;
269  }
270  }

◆ readLShort()

static readLShort (   $str,
  $signed = true 
)
static

Reads a 16-bit signed/unsigned little-endian number

Parameters
$str
bool$signed
Returns
int
171  {
172  $unpacked = unpack("v", $str)[1];
173 
174  if($signed){
175  if(PHP_INT_SIZE === 8){
176  return $unpacked << 48 >> 48;
177  }else{
178  return $unpacked << 16 >> 16;
179  }
180  }else{
181  return $unpacked;
182  }
183  }

◆ readLTriad()

static readLTriad (   $str)
static

Reads a 3-byte little-endian number

Parameters
$str
Returns
mixed
56  {
57  return unpack("V", $str . "\x00")[1];
58  }

◆ readShort()

static readShort (   $str)
static

Reads a 16-bit unsigned big-endian number

Parameters
$str
Returns
int
133  {
134  return unpack("n", $str)[1];
135  }

◆ readSignedShort()

static readSignedShort (   $str)
static

Reads a 16-bit signed big-endian number

Parameters
$str
Returns
int
144  {
145  if(PHP_INT_SIZE === 8){
146  return unpack("n", $str)[1] << 48 >> 48;
147  }else{
148  return unpack("n", $str)[1] << 16 >> 16;
149  }
150  }

◆ readTriad()

static readTriad (   $str)
static

Reads a 3-byte big-endian number

Parameters
$str
Returns
mixed
34  {
35  return unpack("N", "\x00" . $str)[1];
36  }

◆ writeBool()

static writeBool (   $b)
static

Writes a byte boolean

Parameters
$b
Returns
bool|string
89  {
90  return self::writeByte($b === true ? 1 : 0);
91  }

◆ writeByte()

static writeByte (   $c)
static

Writes an unsigned/signed byte

Parameters
$c
Returns
string
122  {
123  return chr($c);
124  }

◆ writeDouble()

static writeDouble (   $value)
static
240  {
241  return ENDIANNESS === self::BIG_ENDIAN ? pack("d", $value) : strrev(pack("d", $value));
242  }

◆ writeFloat()

static writeFloat (   $value)
static
224  {
225  return ENDIANNESS === self::BIG_ENDIAN ? pack("f", $value) : strrev(pack("f", $value));
226  }

◆ writeInt()

static writeInt (   $value)
static
204  {
205  return pack("N", $value);
206  }

◆ writeLDouble()

static writeLDouble (   $value)
static
248  {
249  return ENDIANNESS === self::BIG_ENDIAN ? strrev(pack("d", $value)) : pack("d", $value);
250  }

◆ writeLFloat()

static writeLFloat (   $value)
static
232  {
233  return ENDIANNESS === self::BIG_ENDIAN ? strrev(pack("f", $value)) : pack("f", $value);
234  }

◆ writeLInt()

static writeLInt (   $value)
static
216  {
217  return pack("V", $value);
218  }

◆ writeLLong()

static writeLLong (   $value)
static
295  {
296  return strrev(self::writeLong($value));
297  }

◆ writeLong()

static writeLong (   $value)
static
272  {
273  if(PHP_INT_SIZE === 8){
274  return pack("NN", $value >> 32, $value & 0xFFFFFFFF);
275  }else{
276  $x = "";
277 
278  if(bccomp($value, "0") == -1){
279  $value = bcadd($value, "18446744073709551616");
280  }
281 
282  $x .= self::writeShort(bcmod(bcdiv($value, "281474976710656"), "65536"));
283  $x .= self::writeShort(bcmod(bcdiv($value, "4294967296"), "65536"));
284  $x .= self::writeShort(bcmod(bcdiv($value, "65536"), "65536"));
285  $x .= self::writeShort(bcmod($value, "65536"));
286 
287  return $x;
288  }
289  }

◆ writeLShort()

static writeLShort (   $value)
static

Writes a 16-bit signed/unsigned little-endian number

Parameters
$value
Returns
string
192  {
193  return pack("v", $value);
194  }

◆ writeLTriad()

static writeLTriad (   $value)
static

Writes a 3-byte little-endian number

Parameters
$value
Returns
string
67  {
68  return substr(pack("V", $value), 0, -1);
69  }

◆ writeShort()

static writeShort (   $value)
static

Writes a 16-bit signed/unsigned big-endian number

Parameters
$value
Returns
string
159  {
160  return pack("n", $value);
161  }

◆ writeTriad()

static writeTriad (   $value)
static

Writes a 3-byte big-endian number

Parameters
$value
Returns
string
45  {
46  return substr(pack("N", $value), 1);
47  }

Field Documentation

◆ BIG_ENDIAN

const BIG_ENDIAN = 0x00

◆ LITTLE_ENDIAN

const LITTLE_ENDIAN = 0x01

The documentation for this class was generated from the following file: