Ejemplo n.º 1
0
 public function encode()
 {
     parent::encode();
     $payload = "";
     sort($this->packets, SORT_NUMERIC);
     $count = count($this->packets);
     $records = 0;
     if ($count > 0) {
         $pointer = 1;
         $start = $this->packets[0];
         $last = $this->packets[0];
         while ($pointer < $count) {
             $current = $this->packets[$pointer++];
             $diff = $current - $last;
             if ($diff === 1) {
                 $last = $current;
             } elseif ($diff > 1) {
                 //Forget about duplicated packets (bad queues?)
                 if ($start === $last) {
                     $payload .= "";
                     $payload .= Binary::writeLTriad($start);
                     $start = $last = $current;
                 } else {
                     $payload .= "";
                     $payload .= Binary::writeLTriad($start);
                     $payload .= Binary::writeLTriad($last);
                     $start = $last = $current;
                 }
                 ++$records;
             }
         }
         if ($start === $last) {
             $payload .= "";
             $payload .= Binary::writeLTriad($start);
         } else {
             $payload .= "";
             $payload .= Binary::writeLTriad($start);
             $payload .= Binary::writeLTriad($last);
         }
         ++$records;
     }
     $this->putShort($records);
     $this->buffer .= $payload;
 }
Ejemplo n.º 2
0
 /**
  * @param bool $internal
  *
  * @return string
  */
 public function toBinary($internal = false)
 {
     $binary = chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0));
     if ($internal) {
         $binary .= Binary::writeInt(strlen($this->buffer));
         $binary .= Binary::writeInt($this->identifierACK);
     } else {
         $binary .= Binary::writeShort(strlen($this->buffer) << 3);
     }
     if ($this->reliability === 2 or $this->reliability === 3 or $this->reliability === 4 or $this->reliability === 6 or $this->reliability === 7) {
         $binary .= Binary::writeLTriad($this->messageIndex);
     }
     if ($this->reliability === 1 or $this->reliability === 3 or $this->reliability === 4 or $this->reliability === 7) {
         $binary .= Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel);
     }
     if ($this->hasSplit) {
         $binary .= Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex);
     }
     return $binary . $this->buffer;
 }
Ejemplo n.º 3
0
 /**
  * @param bool $internal
  *
  * @return string
  */
 public function toBinary($internal = false)
 {
     return chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0)) . ($internal ? Binary::writeInt(strlen($this->buffer)) . Binary::writeInt($this->identifierACK) : Binary::writeShort(strlen($this->buffer) << 3)) . ($this->reliability > 0 ? (($this->reliability >= 2 and $this->reliability !== 5) ? Binary::writeLTriad($this->messageIndex) : "") . (($this->reliability <= 4 and $this->reliability !== 2) ? Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel) : "") : "") . ($this->hasSplit ? Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex) : "") . $this->buffer;
 }
Ejemplo n.º 4
0
 protected function putLTriad($v)
 {
     $this->buffer .= Binary::writeLTriad($v);
 }
Ejemplo n.º 5
0
 /**
  * @param bool $internal
  *
  * @return string
  */
 public function toBinary($internal = false)
 {
     return chr($this->reliability << 5 | ($this->hasSplit ? 0b10000 : 0)) . ($internal ? Binary::writeInt(strlen($this->buffer)) . Binary::writeInt($this->identifierACK) : Binary::writeShort(strlen($this->buffer) << 3)) . ($this->reliability > PacketReliability::UNRELIABLE ? (($this->reliability >= PacketReliability::RELIABLE and $this->reliability !== PacketReliability::UNRELIABLE_WITH_ACK_RECEIPT) ? Binary::writeLTriad($this->messageIndex) : "") . (($this->reliability <= PacketReliability::RELIABLE_SEQUENCED and $this->reliability !== PacketReliability::RELIABLE) ? Binary::writeLTriad($this->orderIndex) . chr($this->orderChannel) : "") : "") . ($this->hasSplit ? Binary::writeInt($this->splitCount) . Binary::writeShort($this->splitID) . Binary::writeInt($this->splitIndex) : "") . $this->buffer;
 }