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

Public Member Functions

 getTotalLength ()
 
 toBinary ($internal=false)
 
 __toString ()
 

Static Public Member Functions

static fromBinary ($binary, $internal=false, &$offset=null)
 

Data Fields

 $reliability
 
 $hasSplit = false
 
 $length = 0
 
 $messageIndex = null
 
 $orderIndex = null
 
 $orderChannel = null
 
 $splitCount = null
 
 $splitID = null
 
 $splitIndex = null
 
 $buffer
 
 $needACK = false
 
 $identifierACK = null
 

Member Function Documentation

◆ __toString()

__toString ( )
120  {
121  return $this->toBinary();
122  }

◆ fromBinary()

static fromBinary (   $binary,
  $internal = false,
$offset = null 
)
static
Parameters
string$binary
bool$internal
int&$offset
Returns
EncapsulatedPacket
53  {
54 
55  $packet = new EncapsulatedPacket();
56 
57  $flags = ord($binary{0});
58  $packet->reliability = $reliability = ($flags & 0b11100000) >> 5;
59  $packet->hasSplit = $hasSplit = ($flags & 0b00010000) > 0;
60  if($internal){
61  $length = Binary::readInt(substr($binary, 1, 4));
62  $packet->identifierACK = Binary::readInt(substr($binary, 5, 4));
63  $offset = 9;
64  }else{
65  $length = (int) ceil(Binary::readShort(substr($binary, 1, 2)) / 8);
66  $offset = 3;
67  $packet->identifierACK = null;
68  }
69 
72  $packet->messageIndex = Binary::readLTriad(substr($binary, $offset, 3));
73  $offset += 3;
74  }
75 
77  $packet->orderIndex = Binary::readLTriad(substr($binary, $offset, 3));
78  $offset += 3;
79  $packet->orderChannel = ord($binary{$offset++});
80  }
81  }
82 
83  if($hasSplit){
84  $packet->splitCount = Binary::readInt(substr($binary, $offset, 4));
85  $offset += 4;
86  $packet->splitID = Binary::readShort(substr($binary, $offset, 2));
87  $offset += 2;
88  $packet->splitIndex = Binary::readInt(substr($binary, $offset, 4));
89  $offset += 4;
90  }
91 
92  $packet->buffer = substr($binary, $offset, $length);
93  $offset += $length;
94 
95  return $packet;
96  }

◆ getTotalLength()

getTotalLength ( )
98  {
99  return 3 + strlen($this->buffer) + ($this->messageIndex !== null ? 3 : 0) + ($this->orderIndex !== null ? 4 : 0) + ($this->hasSplit ? 10 : 0);
100  }

◆ toBinary()

toBinary (   $internal = false)
Parameters
bool$internal
Returns
string
107  {
108  return
109  chr(($this->reliability << 5) | ($this->hasSplit ? 0b00010000 : 0)) .
110  ($internal ? Binary::writeInt(strlen($this->buffer)) . Binary::writeInt($this->identifierACK) : Binary::writeShort(strlen($this->buffer) << 3)) .
111  ($this->reliability > PacketReliability::UNRELIABLE ?
112  (($this->reliability >= PacketReliability::RELIABLE and $this->reliability !== PacketReliability::UNRELIABLE_WITH_ACK_RECEIPT) ? Binary::writeLTriad($this->messageIndex) : "") .
113  (($this->reliability <= PacketReliability::RELIABLE_SEQUENCED and $this->reliability !== PacketReliability::RELIABLE) ? Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel) : "")
114  : ""
115  ) .
116  ($this->hasSplit ? Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex) : "")
117  . $this->buffer;
118  }

Field Documentation

◆ $buffer

$buffer

◆ $hasSplit

$hasSplit = false

◆ $identifierACK

$identifierACK = null

◆ $length

$length = 0

◆ $messageIndex

$messageIndex = null

◆ $needACK

$needACK = false

◆ $orderChannel

$orderChannel = null

◆ $orderIndex

$orderIndex = null

◆ $reliability

$reliability

◆ $splitCount

$splitCount = null

◆ $splitID

$splitID = null

◆ $splitIndex

$splitIndex = null

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