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

Public Member Functions

 __construct ($buffer="", $offset=0)
 
 reset ()
 
 setBuffer ($buffer=null, $offset=0)
 
 getOffset ()
 
 getBuffer ()
 
 get ($len)
 
 put ($str)
 
 getBool ()
 
 putBool ($v)
 
 getLong ()
 
 putLong ($v)
 
 getInt ()
 
 putInt ($v)
 
 getLLong ()
 
 putLLong ($v)
 
 getLInt ()
 
 putLInt ($v)
 
 getSignedShort ()
 
 putShort ($v)
 
 getShort ()
 
 putSignedShort ($v)
 
 getFloat (int $accuracy=-1)
 
 putFloat ($v)
 
 getLShort ($signed=true)
 
 putLShort ($v)
 
 getLFloat (int $accuracy=-1)
 
 putLFloat ($v)
 
 getTriad ()
 
 putTriad ($v)
 
 getLTriad ()
 
 putLTriad ($v)
 
 getByte ()
 
 putByte ($v)
 
 getUUID ()
 
 putUUID (UUID $uuid)
 
 getSlot ()
 
 putSlot (Item $item)
 
 getString ()
 
 putString ($v)
 
 getUnsignedVarInt ()
 
 putUnsignedVarInt ($v)
 
 getVarInt ()
 
 putVarInt ($v)
 
 getEntityId ()
 
 putEntityId ($v)
 
 getBlockCoords (&$x, &$y, &$z)
 
 putBlockCoords ($x, $y, $z)
 
 getVector3f (&$x, &$y, &$z)
 
 putVector3f ($x, $y, $z)
 
 feof ()
 

Data Fields

 $offset
 
 $buffer
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $buffer = "",
  $offset = 0 
)

BinaryStream constructor.

Parameters
string$buffer
int$offset
41  {
42  $this->buffer = $buffer;
43  $this->offset = $offset;
44  }

Member Function Documentation

◆ feof()

feof ( )
Returns
bool
475  {
476  return !isset($this->buffer{$this->offset});
477  }

◆ get()

get (   $len)
Parameters
$len
Returns
bool|string
79  {
80  if($len < 0){
81  $this->offset = strlen($this->buffer) - 1;
82 
83  return "";
84  }elseif($len === true){
85  $str = substr($this->buffer, $this->offset);
86  $this->offset = strlen($this->buffer);
87 
88  return $str;
89  }
90 
91  return $len === 1 ? $this->buffer{$this->offset++} : substr($this->buffer, ($this->offset += $len) - $len, $len);
92  }

◆ getBlockCoords()

getBlockCoords ( $x,
$y,
$z 
)
Parameters
$x
$y
$z
433  {
434  $x = $this->getVarInt();
435  $y = $this->getUnsignedVarInt();
436  $z = $this->getVarInt();
437  }

◆ getBool()

getBool ( )
Returns
bool
104  : bool{
105  return (bool) $this->getByte();
106  }

◆ getBuffer()

getBuffer ( )
Returns
string
70  {
71  return $this->buffer;
72  }

◆ getByte()

getByte ( )
Returns
int
278  {
279  return ord($this->buffer{$this->offset++});
280  }

◆ getEntityId()

getEntityId ( )
Returns
int
417  {
418  return $this->getVarInt();
419  }

◆ getFloat()

getFloat ( int  $accuracy = -1)
Parameters
int$accuracy
Returns
float
204  {
205  return Binary::readFloat($this->get(4), $accuracy);
206  }

◆ getInt()

getInt ( )
Returns
int
132  {
133  return Binary::readInt($this->get(4));
134  }

◆ getLFloat()

getLFloat ( int  $accuracy = -1)
Parameters
int$accuracy
Returns
float
236  {
237  return Binary::readLFloat($this->get(4), $accuracy);
238  }

◆ getLInt()

getLInt ( )
Returns
int
160  {
161  return Binary::readLInt($this->get(4));
162  }

◆ getLLong()

getLLong ( )
Returns
int|string
146  {
147  return Binary::readLLong($this->get(8));
148  }

◆ getLong()

getLong ( )
Returns
int|string
118  {
119  return Binary::readLong($this->get(8));
120  }

◆ getLShort()

getLShort (   $signed = true)
Parameters
bool$signed
Returns
int
220  {
221  return $signed ? Binary::readSignedLShort($this->get(2)) : Binary::readLShort($this->get(2));
222  }

◆ getLTriad()

getLTriad ( )
Returns
mixed
264  {
265  return Binary::readLTriad($this->get(3));
266  }

◆ getOffset()

getOffset ( )
Returns
int
63  {
64  return $this->offset;
65  }

◆ getShort()

getShort ( )
Returns
int
188  {
189  return Binary::readShort($this->get(2));
190  }

◆ getSignedShort()

getSignedShort ( )
Returns
int
174  {
175  return Binary::readSignedShort($this->get(2));
176  }

◆ getSlot()

getSlot ( )
Returns
Item
306  {
307  $id = $this->getVarInt();
308 
309  if($id <= 0){
310  return Item::get(0, 0, 0);
311  }
312  $auxValue = $this->getVarInt();
313  $data = $auxValue >> 8;
314  if($data === 0x7fff){
315  $data = -1;
316  }
317  $cnt = $auxValue & 0xff;
318 
319  $nbtLen = $this->getLShort();
320  $nbt = "";
321 
322  if($nbtLen > 0){
323  $nbt = $this->get($nbtLen);
324  }
325 
326  $canPlaceOn = $this->getVarInt();
327  if($canPlaceOn > 0){
328  for($i = 0; $i < $canPlaceOn; ++$i){
329  $this->getString();
330  }
331  }
332 
333  $canDestroy = $this->getVarInt();
334  if($canDestroy > 0){
335  for($i = 0; $i < $canDestroy; ++$i){
336  $this->getString();
337  }
338  }
339 
340  return Item::get($id, $data, $cnt, $nbt);
341  }

◆ getString()

getString ( )
Returns
bool|string
368  {
369  return $this->get($this->getUnsignedVarInt());
370  }

◆ getTriad()

getTriad ( )
Returns
mixed
250  {
251  return Binary::readTriad($this->get(3));
252  }

◆ getUnsignedVarInt()

getUnsignedVarInt ( )

Reads an unsigned varint32 from the stream.

385  {
386  return Binary::readUnsignedVarInt($this);
387  }

◆ getUUID()

getUUID ( )
Returns
UUID
292  {
293  return UUID::fromBinary($this->get(16));
294  }

◆ getVarInt()

getVarInt ( )

Reads a signed varint32 from the stream.

401  {
402  return Binary::readVarInt($this);
403  }

◆ getVector3f()

getVector3f ( $x,
$y,
$z 
)
Parameters
$x
$y
$z
455  {
456  $x = $this->getLFloat(4);
457  $y = $this->getLFloat(4);
458  $z = $this->getLFloat(4);
459  }

◆ put()

put (   $str)
Parameters
$str
97  {
98  $this->buffer .= $str;
99  }

◆ putBlockCoords()

putBlockCoords (   $x,
  $y,
  $z 
)
Parameters
$x
$y
$z
444  {
445  $this->putVarInt($x);
446  $this->putUnsignedVarInt($y);
447  $this->putVarInt($z);
448  }

◆ putBool()

putBool (   $v)
Parameters
$v
111  {
112  $this->putByte((bool) $v);
113  }

◆ putByte()

putByte (   $v)
Parameters
$v
285  {
286  $this->buffer .= chr($v);
287  }

◆ putEntityId()

putEntityId (   $v)
Parameters
$v
424  {
425  $this->putVarInt($v);
426  }

◆ putFloat()

putFloat (   $v)
Parameters
$v
211  {
212  $this->buffer .= Binary::writeFloat($v);
213  }

◆ putInt()

putInt (   $v)
Parameters
$v
139  {
140  $this->buffer .= Binary::writeInt($v);
141  }

◆ putLFloat()

putLFloat (   $v)
Parameters
$v
243  {
244  $this->buffer .= Binary::writeLFloat($v);
245  }

◆ putLInt()

putLInt (   $v)
Parameters
$v
167  {
168  $this->buffer .= Binary::writeLInt($v);
169  }

◆ putLLong()

putLLong (   $v)
Parameters
$v
153  {
154  $this->buffer .= Binary::writeLLong($v);
155  }

◆ putLong()

putLong (   $v)
Parameters
$v
125  {
126  $this->buffer .= Binary::writeLong($v);
127  }

◆ putLShort()

putLShort (   $v)
Parameters
$v
227  {
228  $this->buffer .= Binary::writeLShort($v);
229  }

◆ putLTriad()

putLTriad (   $v)
Parameters
$v
271  {
272  $this->buffer .= Binary::writeLTriad($v);
273  }

◆ putShort()

putShort (   $v)
Parameters
$v
181  {
182  $this->buffer .= Binary::writeShort($v);
183  }

◆ putSignedShort()

putSignedShort (   $v)
Parameters
$v
195  {
196  $this->buffer .= Binary::writeShort($v);
197  }

◆ putSlot()

putSlot ( Item  $item)
Parameters
Item$item
347  {
348  if($item->getId() === 0){
349  $this->putVarInt(0);
350 
351  return;
352  }
353 
354  $this->putVarInt($item->getId());
355  $auxValue = (($item->getDamage() & 0x7fff) << 8) | $item->getCount();
356  $this->putVarInt($auxValue);
357  $nbt = $item->getCompoundTag();
358  $this->putLShort(strlen($nbt));
359  $this->put($nbt);
360 
361  $this->putVarInt(0); //CanPlaceOn entry count (TODO)
362  $this->putVarInt(0); //CanDestroy entry count (TODO)
363  }

◆ putString()

putString (   $v)
Parameters
$v
375  {
376  $this->putUnsignedVarInt(strlen($v));
377  $this->put($v);
378  }

◆ putTriad()

putTriad (   $v)
Parameters
$v
257  {
258  $this->buffer .= Binary::writeTriad($v);
259  }

◆ putUnsignedVarInt()

putUnsignedVarInt (   $v)

Writes an unsigned varint32 to the stream.

Parameters
$v
394  {
395  $this->put(Binary::writeUnsignedVarInt($v));
396  }

◆ putUUID()

putUUID ( UUID  $uuid)
Parameters
UUID$uuid
299  {
300  $this->put($uuid->toBinary());
301  }

◆ putVarInt()

putVarInt (   $v)

Writes a signed varint32 to the stream.

Parameters
$v
410  {
411  $this->put(Binary::writeVarInt($v));
412  }

◆ putVector3f()

putVector3f (   $x,
  $y,
  $z 
)
Parameters
$x
$y
$z
466  {
467  $this->putLFloat($x);
468  $this->putLFloat($y);
469  $this->putLFloat($z);
470  }

◆ reset()

reset ( )
46  {
47  $this->buffer = "";
48  $this->offset = 0;
49  }

◆ setBuffer()

setBuffer (   $buffer = null,
  $offset = 0 
)
Parameters
null$buffer
int$offset
55  {
56  $this->buffer = $buffer;
57  $this->offset = (int) $offset;
58  }

Field Documentation

◆ $buffer

$buffer

◆ $offset

$offset

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