Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CodedInputStream.php

function CodedInputStream::readVarint64

Read Uint64 into $var. Advance buffer with consumed bytes.

Parameters

$var:

2 calls to CodedInputStream::readVarint64()
CodedInputStream::readVarint32 in vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php
Read uint32 into $var. Advance buffer with consumed bytes. If the contained varint is larger than 32 bits, discard the high order bits.
CodedInputStream::readVarintSizeAsInt in vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php
Read int into $var. If the result is larger than the largest integer, $var will be -1. Advance buffer with consumed bytes.

File

vendor/google/protobuf/src/Google/Protobuf/Internal/CodedInputStream.php, line 124

Class

CodedInputStream

Namespace

Google\Protobuf\Internal

Code

public function readVarint64(&$var) {
    $count = 0;
    if (PHP_INT_SIZE == 4) {
        $high = 0;
        $low = 0;
        $b = 0;
        do {
            if ($this->current === $this->buffer_end) {
                return false;
            }
            if ($count === self::MAX_VARINT_BYTES) {
                return false;
            }
            $b = ord($this->buffer[$this->current]);
            $bits = 7 * $count;
            if ($bits >= 32) {
                $high |= ($b & 0x7f) << $bits - 32;
            }
            else {
                if ($bits > 25) {
                    // $bits is 28 in this case.
                    $low |= ($b & 0x7f) << 28;
                    $high = ($b & 0x7f) >> 4;
                }
                else {
                    $low |= ($b & 0x7f) << $bits;
                }
            }
            $this->advance(1);
            $count += 1;
        } while ($b & 0x80);
        $var = GPBUtil::combineInt32ToInt64($high, $low);
        if (bccomp($var, 0) < 0) {
            $var = bcadd($var, "18446744073709551616");
        }
    }
    else {
        $result = 0;
        $shift = 0;
        do {
            if ($this->current === $this->buffer_end) {
                return false;
            }
            if ($count === self::MAX_VARINT_BYTES) {
                return false;
            }
            $byte = ord($this->buffer[$this->current]);
            $result |= ($byte & 0x7f) << $shift;
            $shift += 7;
            $this->advance(1);
            $count += 1;
        } while ($byte > 0x7f);
        $var = $result;
    }
    return true;
}
RSS feed
Powered by Drupal