本文整理汇总了PHP中google\protobuf\FieldDescriptorProto\Type::valueOf方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::valueOf方法的具体用法?PHP Type::valueOf怎么用?PHP Type::valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google\protobuf\FieldDescriptorProto\Type
的用法示例。
在下文中一共展示了Type::valueOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readFrom
/**
* {@inheritdoc}
*/
public function readFrom(\Protobuf\ReadContext $context)
{
$reader = $context->getReader();
$length = $context->getLength();
$stream = $context->getStream();
$limit = $length !== null ? $stream->tell() + $length : null;
while ($limit === null || $stream->tell() < $limit) {
if ($stream->eof()) {
break;
}
$key = $reader->readVarint($stream);
$wire = \Protobuf\WireFormat::getTagWireType($key);
$tag = \Protobuf\WireFormat::getTagFieldNumber($key);
if ($stream->eof()) {
break;
}
if ($tag === 1) {
\Protobuf\WireFormat::assertWireType($wire, 9);
$this->name = $reader->readString($stream);
continue;
}
if ($tag === 3) {
\Protobuf\WireFormat::assertWireType($wire, 5);
$this->number = $reader->readVarint($stream);
continue;
}
if ($tag === 4) {
\Protobuf\WireFormat::assertWireType($wire, 14);
$this->label = \google\protobuf\FieldDescriptorProto\Label::valueOf($reader->readVarint($stream));
continue;
}
if ($tag === 5) {
\Protobuf\WireFormat::assertWireType($wire, 14);
$this->type = \google\protobuf\FieldDescriptorProto\Type::valueOf($reader->readVarint($stream));
continue;
}
if ($tag === 6) {
\Protobuf\WireFormat::assertWireType($wire, 9);
$this->type_name = $reader->readString($stream);
continue;
}
if ($tag === 2) {
\Protobuf\WireFormat::assertWireType($wire, 9);
$this->extendee = $reader->readString($stream);
continue;
}
if ($tag === 7) {
\Protobuf\WireFormat::assertWireType($wire, 9);
$this->default_value = $reader->readString($stream);
continue;
}
if ($tag === 9) {
\Protobuf\WireFormat::assertWireType($wire, 5);
$this->oneof_index = $reader->readVarint($stream);
continue;
}
if ($tag === 10) {
\Protobuf\WireFormat::assertWireType($wire, 9);
$this->json_name = $reader->readString($stream);
continue;
}
if ($tag === 8) {
\Protobuf\WireFormat::assertWireType($wire, 11);
$innerSize = $reader->readVarint($stream);
$innerMessage = new \google\protobuf\FieldOptions();
$this->options = $innerMessage;
$context->setLength($innerSize);
$innerMessage->readFrom($context);
$context->setLength($length);
continue;
}
$extensions = $context->getExtensionRegistry();
$extension = $extensions ? $extensions->findByNumber(__CLASS__, $tag) : null;
if ($extension !== null) {
$this->extensions()->add($extension, $extension->readFrom($context, $wire));
continue;
}
if ($this->unknownFieldSet === null) {
$this->unknownFieldSet = new \Protobuf\UnknownFieldSet();
}
$data = $reader->readUnknown($stream, $wire);
$unknown = new \Protobuf\Unknown($tag, $wire, $data);
$this->unknownFieldSet->add($unknown);
}
}
示例2: createFieldDescriptorProto
/**
* @param integer $number
* @param string $name
* @param integer $type
* @param integer $label
* @param string $typeName
* @param array $values
*
* @return \google\protobuf\FieldDescriptorProto
*/
protected function createFieldDescriptorProto($number, $name, $type, $label, $typeName = null, array $values = [])
{
$field = new FieldDescriptorProto();
$options = isset($values['options']) ? $values['options'] : null;
$field->setName($name);
$field->setNumber($number);
$field->setTypeName($typeName);
$field->setType(FieldDescriptorProto\Type::valueOf($type));
$field->setLabel(FieldDescriptorProto\Label::valueOf($label));
if (isset($values['default'])) {
$field->setDefaultValue($values['default']);
}
if ($options !== null) {
$fieldOptions = new FieldOptions();
if (isset($options['packed'])) {
$fieldOptions->setPacked($options['packed']);
}
$field->setOptions($fieldOptions);
}
return $field;
}