public static function sint64Size($value) { $value = GPBUtil::Int64($value); $value = self::zigZagEncode64($value); return self::varint64Size($value->toInteger()); }
public function setRepeatedEnum(&$var) { GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); $this->repeated_enum = $var; }
/** * Assign the element at the given index. * * This will also be called for: $arr []= $ele and $arr[0] = ele * * @param long $offset The index of the element to be assigned. * @param object $value The element to be assigned. * @return void * @throws ErrorException Invalid type for index. * @throws ErrorException Non-existing index. * @throws ErrorException Incorrect type of the element. */ public function offsetSet($offset, $value) { switch ($this->type) { case GPBType::INT32: GPBUtil::checkInt32($value); break; case GPBType::UINT32: GPBUtil::checkUint32($value); break; case GPBType::INT64: GPBUtil::checkInt64($value); break; case GPBType::UINT64: GPBUtil::checkUint64($value); break; case GPBType::FLOAT: GPBUtil::checkFloat($value); break; case GPBType::DOUBLE: GPBUtil::checkDouble($value); break; case GPBType::BOOL: GPBUtil::checkBool($value); break; case GPBType::STRING: GPBUtil::checkString($value, true); break; case GPBType::MESSAGE: GPBUtil::checkMessage($value, $this->klass); break; default: break; } if (is_null($offset)) { $this->container[] = $value; } else { $count = count($this->container); if (!is_numeric($offset) || $offset < 0 || $offset >= $count) { trigger_error("Cannot modify element at the given index", E_USER_ERROR); return; } $this->container[$offset] = $value; } }
public function setA($var) { GPBUtil::checkInt32($var); $this->a = $var; }
public function setEnd($var) { GPBUtil::checkInt32($var); $this->end = $var; $this->has_end = true; }
public function testZigZagEncodeDecode() { $this->assertSame(0, GPBWire::zigZagEncode32(0)); $this->assertSame(1, GPBWire::zigZagEncode32(-1)); $this->assertSame(2, GPBWire::zigZagEncode32(1)); $this->assertSame(3, GPBWire::zigZagEncode32(-2)); $this->assertSame(0x7ffffffe, GPBWire::zigZagEncode32(0x3fffffff)); $this->assertSame(0x7fffffff, GPBWire::zigZagEncode32(0xc0000000)); $this->assertSame(-2, GPBWire::zigZagEncode32(0x7fffffff)); $this->assertSame(-1, GPBWire::zigZagEncode32(0x80000000)); $this->assertSame(0, GPBWire::zigZagDecode32(0)); $this->assertSame(-1, GPBWire::zigZagDecode32(1)); $this->assertSame(1, GPBWire::zigZagDecode32(2)); $this->assertSame(-2, GPBWire::zigZagDecode32(3)); $this->assertSame(0x3fffffff, GPBWire::zigZagDecode32(0x7ffffffe)); $this->assertSame(-1073741824, GPBWire::zigZagDecode32(0x7fffffff)); $this->assertSame(0x7fffffff, GPBWire::zigZagDecode32(0xfffffffe)); $this->assertSame(-2147483648, GPBWire::zigZagDecode32(0xffffffff)); $this->assertEquals(GPBUtil::Uint64(0), GPBWire::zigZagEncode64(GPBUtil::Int64(0))); $this->assertEquals(GPBUtil::Uint64(1), GPBWire::zigZagEncode64(GPBUtil::Int64(-1))); $this->assertEquals(GPBUtil::Uint64(2), GPBWire::zigZagEncode64(GPBUtil::Int64(1))); $this->assertEquals(GPBUtil::Uint64(3), GPBWire::zigZagEncode64(GPBUtil::Int64(-2))); $this->assertEquals(GPBUtil::Uint64(0x7ffffffe), GPBWire::zigZagEncode64(GPBUtil::Int64(0x3fffffff))); $this->assertEquals(GPBUtil::Uint64(0x7fffffff), GPBWire::zigZagEncode64(GPBUtil::Int64(1.844674407263581E+19))); $this->assertEquals(GPBUtil::Uint64(0xfffffffe), GPBWire::zigZagEncode64(GPBUtil::Int64(0x7fffffff))); $this->assertEquals(GPBUtil::Uint64(0xffffffff), GPBWire::zigZagEncode64(GPBUtil::Int64(1.8446744071562068E+19))); $this->assertEquals(Uint64::newValue(4294967295, 4294967294), GPBWire::zigZagEncode64(GPBUtil::Int64(0x7fffffffffffffff))); $this->assertEquals(Uint64::newValue(4294967295, 4294967295), GPBWire::zigZagEncode64(GPBUtil::Int64(9.223372036854776E+18))); $this->assertEquals(GPBUtil::Int64(0), GPBWire::zigZagDecode64(GPBUtil::Uint64(0))); $this->assertEquals(GPBUtil::Int64(-1), GPBWire::zigZagDecode64(GPBUtil::Uint64(1))); $this->assertEquals(GPBUtil::Int64(1), GPBWire::zigZagDecode64(GPBUtil::Uint64(2))); $this->assertEquals(GPBUtil::Int64(-2), GPBWire::zigZagDecode64(GPBUtil::Uint64(3))); // Round trip $this->assertSame(0, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(0))); $this->assertSame(1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(1))); $this->assertSame(-1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-1))); $this->assertSame(14927, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(14927))); $this->assertSame(-3612, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-3612))); }