Unpacks 64-bit unsigned.

@param $v

@return int|string
427224
protected function sphUnpackU64($v)
    {
        list($hi, $lo) = array_values(unpack('N*N*', $v));

        if (PHP_INT_SIZE >= 8) {
            if ($hi < 0) {
                $hi += (1 << 32);
            } // because php 5.2.2 to 5.2.5 is totally fucked up again
            if ($lo < 0) {
                $lo += (1 << 32);
            }

            // x64, int
            if ($hi <= 2147483647) {
                return ($hi << 32) + $lo;
            }

            // x64, bcmath
            if (function_exists('bcmul')) {
                return bcadd($lo, bcmul($hi, '4294967296'));
            }

            // x64, no-bcmath
            $C = 100000;
            $h = ((int) ($hi / $C) << 32) + (int) ($lo / $C);
            $l = (($hi % $C) << 32) + ($lo % $C);
            if ($l > $C) {
                $h += (int) ($l / $C);
                $l = $l % $C;
            }

            if ($h == 0) {
                return $l;
            }

            return sprintf('%d%05d', $h, $l);
        }

        // x32, int
        if ($hi == 0) {
            if ($lo > 0) {
                return $lo;
            }

            return sprintf('%u', $lo);
        }

        $hi = sprintf('%u', $hi);
        $lo = sprintf('%u', $lo);

        // x32, bcmath
        if (function_exists('bcmul')) {
            return bcadd($lo, bcmul($hi, '4294967296'));
        }

        // x32, no-bcmath
        $hi = (float) $hi;
        $lo = (float) $lo;

        $q = floor($hi / 10000000.0);
        $r = $hi - $q * 10000000.0;
        $m = $lo + $r * 4967296.0;
        $mq = floor($m / 10000000.0);
        $l = $m - $mq * 10000000.0;
        $h = $q * 4294967296.0 + $r * 429.0 + $mq;

        $h = sprintf('%.0f', $h);
        $l = sprintf('%07.0f', $l);
        if ($h == '0') {
            return sprintf('%.0f', (float) $l);
        }

        return $h.$l;
    }
1317998
def read_uint64(self, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack('%sQ' % endian, 8)
1127321
public function consumeUint64()
    {
        $s = $this->consume(8);
        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;
    }
229355
function _convertNumber($num)
    {
        // Integer in the range 0..2**16-1
        if ((preg_match("/^\d+$/", $num)) and ($num <= 65535)) {
            return pack("Cv", $this->ptg['ptgInt'], $num);
        } else { // A float
            if ($this->_byte_order) { // if it's Big Endian
                $num = strrev($num);
            }
            return pack("Cd", $this->ptg['ptgNum'], $num);
        }
    }
1142273
public static function bit64(int $data, $endianness = false): string
    {
        // big-endian
        if (true === $endianness) {
            return pack('J', $data);
        }

        // little-endian
        if (false === $endianness) {
            return pack('P', $data);
        }

        // machine byte order
        if (null === $endianness) {
            return pack('Q', $data);
        }
    }
469599
public function pack($v)
    {
        $stream = '';
        if (is_string($v)) {
            $stream .= $this->packText($v);
        } elseif ($v instanceof CollectionInterface && $v instanceof Map) {
            $stream .= $this->packMap($v->getElements());
        } elseif ($v instanceof CollectionInterface && $v instanceof ArrayList) {
            $stream .= $this->packList($v->getElements());
        }
        elseif (is_array($v)) {
            $stream .= ($this->isList($v) && !empty($v)) ? $this->packList($v) : $this->packMap($v);
        } elseif (is_float($v)) {
            $stream .= $this->packFloat($v);
        } elseif (is_int($v)) {
            $stream .= $this->packInteger($v);
        } elseif (is_null($v)) {
            $stream .= chr(Constants::MARKER_NULL);
        } elseif (true === $v) {
            $stream .= chr(Constants::MARKER_TRUE);
        } elseif (false === $v) {
            $stream .= chr(Constants::MARKER_FALSE);
        } elseif (is_float($v)) {
            // if it is 64 bit integers casted to float
            $r = $v + $v;
            if ('double' === gettype($r)) {
                $stream .= $this->packInteger($v);
            }
        } else {
            throw new BoltInvalidArgumentException(sprintf('Could not pack the value %s', $v));
        }

        return $stream;
    }
59186
public function packInteger($value)
    {
        $pow15 = pow(2, 15);
        $pow31 = pow(2, 31);
        $b = '';

        if ($value > -16 && $value < 128) {
            //$b .= chr(Constants::INT_8);
            //$b .= $this->packBigEndian($value, 2);
            return $this->packSignedShortShort($value);
        }

        if ($value > -129 && $value < -16) {
            $b .= chr(Constants::INT_8);
            $b .= $this->packSignedShortShort($value);

            return $b;
        }

        if ($value < -16 && $value > -129) {
            $b .= chr(Constants::INT_8);
            $b .= $this->packSignedShortShort($value);

            return $b;
        }

        if ($value < -128 && $value > -32769) {
            $b .= chr(Constants::INT_16);
            $b .= $this->packBigEndian($value, 2);

            return $b;
        }

        if ($value >= -16 && $value < 128) {
            return $this->packSignedShortShort($value);
        }

        if ($value > 127 && $value < $pow15) {
            $b .= chr(Constants::INT_16);
            $b .= pack('n', $value);

            return $b;
        }

        if ($value > 32767 && $value < $pow31) {
            $b .= chr(Constants::INT_32);
            $b .= pack('N', $value);

            return $b;
        }

        // 32 INTEGERS MINUS
        if ($value >= (-1 * abs(pow(2, 31))) && $value < (-1 * abs(pow(2, 15)))) {
            $b .= chr(Constants::INT_32);
            $b .= pack('N', $value);

            return $b;
        }

        // 64 INTEGERS POS
        if ($value >= pow(2, 31) && $value < pow(2, 63)) {
            $b .= chr(Constants::INT_64);
            //$b .= $this->packBigEndian($value, 8);
            $b .= pack('J', $value);

            return $b;
        }

        // 64 INTEGERS MINUS
        if ($value >= ((-1 * abs(pow(2, 63))) - 1) && $value < (-1 * abs(pow(2, 31)))) {
            $b .= chr(Constants::INT_64);
            $b .= pack('J', $value);

            return $b;
        }

        throw new BoltOutOfBoundsException(sprintf('Out of bound value, max is %d and you give %d', PHP_INT_MAX, $value));
    }
1123072
public static function bit64(string $data, int $offset = 0, bool $endianness = false): int
    {
        // big-endian
        if (true === $endianness) {
            return unpack('J', $data, $offset)[1];
        }

        // little-endian
        if (false === $endianness) {
            return unpack('P', $data, $offset)[1];
        }

        // machine byte order
        if (null === $endianness) {
            return unpack('Q', $data, $offset)[1];
        }
    }
118037
public function readInt16Signed()
    {

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

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

        $int = unpack('sint', $string);

        unset($string);

        return $int['int'];
    }
161691
private static function set_endianness()
  {
    $packed = pack('d', 1);
    switch ($packed)
    {
      case "\77\360\0\0\0\0\0\0":
        self::$endianness = self::BIG_ENDIAN;
        break;
      case "\0\0\0\0\0\0\360\77":
        self::$endianness = self::LITTLE_ENDIAN;
        break;
      default:
        throw new AvroException(
          sprintf('Error determining platform endianness: %s',
                  AvroDebug::hex_string($packed)));
    }
  }
1030416
public function parseFloat()
    {
        try {
            if (Endianness::LITTLE()) {
                return \unpack('f', \strrev(mb_orig_substr($this->buffer, 0, 4)))[1];
            }
            return \unpack('f', $this->buffer)[1]; // @codeCoverageIgnore
        } finally {
            $this->buffer = mb_orig_substr($this->buffer, 4);
        }
    }
1107615
public function computeVarintSize($value)
    {
        if (($value & (0xffffffff <<  7)) === 0) {
            return 1;
        }

        if (($value & (0xffffffff << 14)) === 0) {
            return 2;
        }

        if (($value & (0xffffffff << 21)) === 0) {
            return 3;
        }

        if (($value & (0xffffffff << 28)) === 0) {
            return 4;
        }

        if (($value & (0xffffffff << 35)) === 0) {
            return 5;
        }

        if (($value & (0xffffffff << 42)) === 0) {
            return 6;
        }

        if (($value & (0xffffffff << 49)) === 0) {
            return 7;
        }

        if (($value & (0xffffffff << 56)) === 0) {
            return 8;
        }

        if (($value & (0xffffffff << 63)) === 0) {
            return 9;
        }

        return 10;
    }
1229602
private static function toBytes($val) {
        $val = trim($val);
        $last = strtolower($val[strlen($val) - 1]);
        switch ($last) {
            // The 'G' modifier is available since PHP 5.1.0
            case 'g':
                $val *= 1024;
            case 'm':
                $val *= 1024;
            case 'k':
                $val *= 1024;
        }
        return $val;
    }
22882
protected function decb64($num)
    {
        $bytes = array();
        while($num) {
            array_unshift($bytes, $this->mod($num, 256));
            $num = $this->div($num, 256);
        }
        
        if($bytes && $bytes[0] > 127) {
            array_unshift($bytes,0);
        }
        
        array_unshift($bytes, 'C*');
        
        return base64_encode(call_user_func_array('pack', $bytes));
    }
1054122
public function strlen($var) : int
    {
        $v = '' . $var;
        if ($v === '') {
            return 0;
        }
        if (static::$nativeSupport['mbstring']) {
            return mb_strlen($v);
        }

        $n = 0;
        $le = strlen($v);
        $leading = false;
        for ($i = 0; $i < $le; $i++) {
            // ASCII.
            if (($ord = ord($v{$i})) < 128) {
                ++$n;
                $leading = false;
            }
            // Continuation char.
            elseif ($ord < 192) {
                $leading = false;
            }
            // Leading char.
            else {
                // A sequence of leadings only counts as a single.
                if (!$leading) {
                    ++$n;
                }
                $leading = true;
            }
        }
        return $n;
    }
667775
public static function writeUnsignedVarInt($data) {
        if($data < 0) {
            throw new InvalidDataException('Cannot write negative values');
        }
        $orig = $data;

        //single bytes don't need encoding
        if ($data < 0x80) {
            return new VarInt($data, pack('C', $data), 1);
        }

        $encodedBytes = [];
        while ($data > 0) {
            $encodedBytes[] = 0x80 | ($data & 0x7f);
            $data >>= 7;
        }

        //remove most sig bit from final value
        $encodedBytes[count($encodedBytes)-1] &= 0x7f;

        //build the actual bytes from the encoded array
        $bytes = call_user_func_array('pack', array_merge(array('C*'), $encodedBytes));;

        return new VarInt($orig, $bytes, strlen($bytes));
    }
360997
def _unpack_int_base128(varint, offset):
        """"""
        res = ord(varint[offset])
        if ord(varint[offset]) >= 0x80:
            offset += 1
            res = ((res - 0x80) << 7) + ord(varint[offset])
            if ord(varint[offset]) >= 0x80:
                offset += 1
                res = ((res - 0x80) << 7) + ord(varint[offset])
                if ord(varint[offset]) >= 0x80:
                    offset += 1
                    res = ((res - 0x80) << 7) + ord(varint[offset])
                    if ord(varint[offset]) >= 0x80:
                        offset += 1
                        res = ((res - 0x80) << 7) + ord(varint[offset])
        return res, offset + 1