PHPDaemon\Utils\Binary::getByte PHP Method

getByte() public static method

Parse byte, and remove it
public static getByte ( &$p ) : integer
return integer
    public static function getByte(&$p)
    {
        $r = static::bytes2int($p[0]);
        $p = mb_orig_substr($p, 1);
        return (int) $r;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Called when new data received
  * @return void
  */
 public function onRead()
 {
     $packet = $this->read(1024);
     $orig = $packet;
     $type = Binary::getByte($packet);
     $code = Binary::getByte($packet);
     $checksum = Binary::getStrWord($packet);
     $id = Binary::getWord($packet);
     $seq = Binary::getWord($packet);
     if ($checksum !== self::checksum(substr_replace($orig, "", 2, 2))) {
         $status = 'badChecksum';
     } elseif ($type === 0x3) {
         $status = isset(static::$unreachableCodes[$code]) ? static::$unreachableCodes[$code] : 'unk' . $code . 'unreachable';
     } else {
         $status = 'unknownType0x' . dechex($type);
     }
     while (!$this->onResponse->isEmpty()) {
         $el = $this->onResponse->shift();
         if ($el instanceof CallbackWrapper) {
             $el = $el->unwrap();
         }
         list($cb, $st) = $el;
         call_user_func($cb, microtime(true) - $st, $status);
     }
     $this->finish();
 }
All Usage Examples Of PHPDaemon\Utils\Binary::getByte