Read a 64-bit unsigned integer

@return int
@throws \GameQ\Exception\Protocol
436025
public function readInt64()
    {

        // We have the pack 64-bit codes available. See: http://php.net/manual/en/function.pack.php
        if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE == 8) {
            // Change the integer type we are looking up
            switch ($this->number_type) {
                case self::NUMBER_TYPE_BIGENDIAN:
                    $type = 'Jint';
                    break;

                case self::NUMBER_TYPE_LITTLEENDIAN:
                    $type = 'Pint';
                    break;

                default:
                    $type = 'Qint';
            }

            $int64 = unpack($type, $this->read(8));

            $int = $int64['int'];

            unset($int64);
        } else {
            if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) {
                $high = $this->readInt32();
                $low = $this->readInt32();
            } else {
                $low = $this->readInt32();
                $high = $this->readInt32();
            }

            // We have to determine the number via bitwise
            $int = ($high << 32) | $low;

            unset($low, $high);
        }

        return $int;
    }
1300911
public function readI64(&$value)
    {
        // Read varint from wire
        $hi = 0;
        $lo = 0;

        $idx = 0;
        $shift = 0;

        while (true) {
            $x = $this->trans_->readAll(1);
            $arr = unpack('C', $x);
            $byte = $arr[1];
            $idx += 1;
            // Shift hi and lo together.
            if ($shift < 28) {
                $lo |= (($byte & 0x7f) << $shift);
            } elseif ($shift == 28) {
                $lo |= (($byte & 0x0f) << 28);
                $hi |= (($byte & 0x70) >> 4);
            } else {
                $hi |= (($byte & 0x7f) << ($shift - 32));
            }
            if (($byte >> 7) === 0) {
                break;
            }
            $shift += 7;
        }

        // Now, unzig it.
        $xorer = 0;
        if ($lo & 1) {
            $xorer = 0xffffffff;
        }
        $lo = ($lo >> 1) & 0x7fffffff;
        $lo = $lo | (($hi & 1) << 31);
        $hi = ($hi >> 1) ^ $xorer;
        $lo = $lo ^ $xorer;

        // Now put $hi and $lo back together
        $isNeg = $hi < 0 || $hi & 0x80000000;

        // Check for a negative
        if ($isNeg) {
            $hi = ~$hi & (int)0xffffffff;
            $lo = ~$lo & (int)0xffffffff;

            if ($lo == (int)0xffffffff) {
                $hi++;
                $lo = 0;
            } else {
                $lo++;
            }
        }

        // Force 32bit words in excess of 2G to be positive - we deal with sign
        // explicitly below

        if ($hi & (int)0x80000000) {
            $hi &= (int)0x7fffffff;
            $hi += 0x80000000;
        }

        if ($lo & (int)0x80000000) {
            $lo &= (int)0x7fffffff;
            $lo += 0x80000000;
        }

        // Create as negative value first, since we can store -2^63 but not 2^63
        $value = -$hi * 4294967296 - $lo;

        if (!$isNeg) {
            $value = -$value;
        }

        return $idx;
    }
431741
public function readFloat32()
    {

        // Read the data into a string
        $string = $this->read(4);

        // For big endian we need to reverse the bytes
        if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) {
            $string = strrev($string);
        }

        $float = unpack('ffloat', $string);

        unset($string);

        return $float['float'];
    }
711438
public function readUint64($offset = 0)
    {
        $s = $this->read(8, $offset);
        if (self::$native64BitPack) {
            list(, $ret) = unpack("Q", self::$isLittleEndian ? self::swapEndian64($s) : $s);
        } else {
            $d = unpack("Lh/Ll", self::$isLittleEndian ? self::swapHalvedEndian64($s) : $s);
            $ret = $d["h"] << 32 | $d["l"];
        }
        return $ret;
    }
532898
public function getByteValue() : int
    {
        $bits = (array)$this->getValue();
        return array_reduce($bits, function ($carry, $item) {
            return $carry | (int)$item;
        }, 0);

    }
629247
protected function read()
    {
        // Ignore first byte
        fread($this->socket, 1);

        // There is also masking bit, as MSB, bit it's 0
        $payloadLength = ord(fread($this->socket, 1));

        switch ($payloadLength) {
            case 126:
                $payloadLength = unpack('n', fread($this->socket, 2));
                $payloadLength = $payloadLength[1];
                break;
            case 127:
                //$this->stdout('error', "Next 8 bytes are 64bit uint payload length, not yet implemented, since PHP can't handle 64bit longs!");
                break;
        }

        return fread($this->socket, $payloadLength);
    }
675683
public function readUint32($offset = 0)
    {
        $s = $this->read(4, $offset);
        list(, $ret) = unpack("N", $s);
        return $ret;
    }
1352937
private int readInteger() {
        int b = buf.get();
        if (buf.hasRemaining()) {
            int n = 0;
            int result = 0;
            while ((b & 0x80) != 0 && n < 3) {
                result <<= 7;
                result |= (b & 0x7f);
                b = buf.get();
                n++;
            }
            if (n < 3) {
                result <<= 7;
                result |= b;
            } else {
                // use all 8 bits from the 4th byte
                result <<= 8;
                result |= b & 0x0ff;
                // check if the integer should be negative
                if ((result & 0x10000000) != 0) {
                    // extend the sign bit
                    result |= 0xe0000000;
                }
            }
            return result;
        }
        return b;
    }
816797
public function readInt16()
    {

        // Change the integer type we are looking up
        switch ($this->number_type) {
            case self::NUMBER_TYPE_BIGENDIAN:
                $type = 'nint';
                break;

            case self::NUMBER_TYPE_LITTLEENDIAN:
                $type = 'vint';
                break;

            default:
                $type = 'Sint';
        }

        $int = unpack($type, $this->read(2));

        return $int['int'];
    }
297077
public function readU29() {

            $count = 1;
            $u29 = 0;

            $byte = $this->stream->readByte();
  
            while((($byte & 0x80) != 0) && $count < 4) {
                $u29 <<= 7;
                $u29 |= ($byte & 0x7f);
                $byte = $this->stream->readByte();
                $count++;
            }
            
            if ($count < 4) {
                $u29 <<= 7;
                $u29 |= $byte;
            } else {
                // Use all 8 bits from the 4th byte
                $u29 <<= 8;
                $u29 |= $byte;
            }
            
            return $u29;
         
        }
940227
public int readInt()
    throws IOException
  {
    if (_readOffset + 4 < _readLength) {
      return (((_readBuffer[_readOffset++] & 0xff) << 24)
              + ((_readBuffer[_readOffset++] & 0xff) << 16)
              + ((_readBuffer[_readOffset++] & 0xff) << 8)
              + ((_readBuffer[_readOffset++] & 0xff)));
    }
    else {
      return ((read() << 24)
              + (read() << 16)
              + (read() << 8)
              + (read()));
    }
  }
751977
final public function readInt32BE()
    {
        if ($this->isLittleEndian()) {
            return $this->fromInt32(strrev($this->read(4)));
        } else {
            return $this->fromInt32($this->read(4));
        }
    }
1329486
public long readRawVarint64() throws IOException
    {
        final byte[] buffer = this.buffer;
        int offset = this.offset;

        int shift = 0;
        long result = 0;
        while (shift < 64)
        {
            final byte b = buffer[offset++];
            result |= (long) (b & 0x7F) << shift;
            if ((b & 0x80) == 0)
            {
                this.offset = offset;
                return result;
            }
            shift += 7;
        }
        throw ProtobufException.malformedVarint();
    }
882523
final public function readInt32LE()
    {
        if ($this->isBigEndian()) {
            return $this->fromInt32(strrev($this->read(4)));
        } else {
            return $this->fromInt32($this->read(4));
        }
    }
301185
private function read()
	{
		// Ignore first byte
		fread($this->fd, 1);

		// There is also masking bit, as MSB, bit it's 0
		$payloadLength = ord(fread($this->fd, 1));

		switch ($payloadLength) {
			case 126:
				$payloadLength = unpack("n", fread($this->fd, 2));
				$payloadLength = $payloadLength[1];
				break;
			case 127:
				//$this->stdout('error', "Next 8 bytes are 64bit uint payload length, not yet implemented, since PHP can't handle 64bit longs!");
				break;
		}

		return fread($this->fd, $payloadLength);
	}
1328416
public function readVInt()
    {
        $nextByte = ord($this->_fread(1));
        $val = $nextByte & 0x7F;

        for ($shift=7; ($nextByte & 0x80) != 0; $shift += 7) {
            $nextByte = ord($this->_fread(1));
            $val |= ($nextByte & 0x7F) << $shift;
        }
        return $val;
    }
188361
public function convertData()
    {
        $ver = $this->estimateVersion();
        if($ver > $this->getVersion()) {
            $this->setVersion($ver);
        }

        for(;;) {
            $bits = $this->createBitStream();

            if($bits < 0)
                return -1;

            $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
            if($ver < 0) {
                throw new Exception('WRONG VERSION');
                return -1;
            } else if($ver > $this->getVersion()) {
                $this->setVersion($ver);
            } else {
                break;
            }
        }

        return 0;
    }