当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldDescriptorProto::getType方法代码示例

本文整理汇总了PHP中Google\Protobuf\FieldDescriptorProto::getType方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldDescriptorProto::getType方法的具体用法?PHP FieldDescriptorProto::getType怎么用?PHP FieldDescriptorProto::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google\Protobuf\FieldDescriptorProto的用法示例。


在下文中一共展示了FieldDescriptorProto::getType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateFieldWriteStatement

 /**
  * @param \Protobuf\Compiler\Entity             $entity
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string[]
  */
 public function generateFieldWriteStatement(Entity $entity, FieldDescriptorProto $field)
 {
     $body = [];
     $name = $field->getName();
     $type = $field->getType();
     $rule = $field->getLabel();
     $tag = $field->getNumber();
     $options = $field->getOptions();
     $variable = $this->targetVar ?: '$this->' . $name;
     $isPack = $options ? $options->getPacked() : false;
     $wire = $isPack ? WireFormat::WIRE_LENGTH : WireFormat::getWireType($type->value(), null);
     $key = WireFormat::getFieldKey($tag, $wire);
     if ($rule === Label::LABEL_REPEATED() && $isPack) {
         $itemValSttm = $type === Type::TYPE_ENUM() ? '$val->value()' : '$val';
         $body[] = '$innerSize   = 0;';
         $body[] = '$calculator  = $sizeContext->getSizeCalculator();';
         $body[] = null;
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $innerSize += ' . $this->generateValueSizeStatement($type->value(), $itemValSttm) . ';';
         $body[] = '}';
         $body[] = null;
         $body[] = '$writer->writeVarint($stream, ' . $key . ');';
         $body[] = '$writer->writeVarint($stream, $innerSize);';
         $body[] = null;
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), $itemValSttm) . ';';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_MESSAGE() && $rule === Label::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    $writer->writeVarint($stream, $val->serializedSize($sizeContext));';
         $body[] = '    $val->writeTo($context);';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_ENUM() && $rule === LABEL::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), '$val->value()') . ';';
         $body[] = '}';
         return $body;
     }
     if ($rule === Label::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), '$val') . ';';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_ENUM()) {
         $body[] = sprintf('$writer->writeVarint($stream, %s);', $key);
         $body[] = $this->generateWriteScalarStatement($type->value(), $variable . '->value()') . ';';
         return $body;
     }
     if ($type !== Type::TYPE_MESSAGE()) {
         $body[] = sprintf('$writer->writeVarint($stream, %s);', $key);
         $body[] = $this->generateWriteScalarStatement($type->value(), $variable) . ';';
         return $body;
     }
     $body[] = '$writer->writeVarint($stream, ' . $key . ');';
     $body[] = '$writer->writeVarint($stream, ' . $variable . '->serializedSize($sizeContext));';
     $body[] = $variable . '->writeTo($context);';
     return $body;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:72,代码来源:WriteFieldStatementGenerator.php

示例2: generateFieldReadStatement

 /**
  * @param \Protobuf\Compiler\Entity             $entity
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string[]
  */
 public function generateFieldReadStatement(Entity $entity, FieldDescriptorProto $field)
 {
     $body = [];
     $reference = null;
     $type = $field->getType();
     $name = $field->getName();
     $rule = $field->getLabel();
     $tag = $field->getNumber();
     $options = $field->getOptions();
     $isPack = $options ? $options->getPacked() : false;
     $variable = $this->targetVar ?: '$this->' . $name;
     $breakSttm = $this->getBreakStatement($variable);
     if ($field->hasTypeName()) {
         $typeName = $field->getTypeName();
         $typeEntity = $this->getEntity($typeName);
         $reference = $typeEntity->getNamespacedName();
     }
     if (!$isPack) {
         $body[] = sprintf('\\Protobuf\\WireFormat::assertWireType($wire, %s);', $type->value());
         $body[] = null;
     }
     if ($rule === Label::LABEL_REPEATED() && $isPack) {
         $readSttm = $type === Type::TYPE_ENUM() ? $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) . ')' : $this->generateReadScalarStatement($type->value());
         $body[] = '$innerSize  = $reader->readVarint($stream);';
         $body[] = '$innerLimit = $stream->tell() + $innerSize;';
         $body[] = null;
         $body[] = 'if (' . $variable . ' === null) {';
         $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
         $body[] = '}';
         $body[] = null;
         $body[] = 'while ($stream->tell() < $innerLimit) {';
         $body[] = '    ' . $variable . '->add(' . $readSttm . ');';
         $body[] = '}';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     if ($type === Type::TYPE_MESSAGE() && $rule === Label::LABEL_REPEATED()) {
         $body[] = '$innerSize    = $reader->readVarint($stream);';
         $body[] = '$innerMessage = new ' . $reference . '();';
         $body[] = null;
         $body[] = 'if (' . $variable . ' === null) {';
         $body[] = '    ' . $variable . ' = new \\Protobuf\\MessageCollection();';
         $body[] = '}';
         $body[] = null;
         $body[] = $variable . '->add($innerMessage);';
         $body[] = null;
         $body[] = '$context->setLength($innerSize);';
         $body[] = '$innerMessage->readFrom($context);';
         $body[] = '$context->setLength($length);';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     if ($type === Type::TYPE_ENUM() && $rule === LABEL::LABEL_REPEATED()) {
         $body[] = 'if (' . $variable . ' === null) {';
         $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
         $body[] = '}';
         $body[] = null;
         $body[] = $variable . '->add(' . $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) . '));';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     if ($type === Type::TYPE_MESSAGE()) {
         $body[] = '$innerSize    = $reader->readVarint($stream);';
         $body[] = '$innerMessage = new ' . $reference . '();';
         $body[] = null;
         $body[] = $variable . ' = $innerMessage;';
         $body[] = null;
         $body[] = '$context->setLength($innerSize);';
         $body[] = '$innerMessage->readFrom($context);';
         $body[] = '$context->setLength($length);';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     if ($type === Type::TYPE_ENUM()) {
         $body[] = $variable . ' = ' . $reference . '::valueOf(' . $this->generateReadScalarStatement($type->value()) . ');';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     if ($rule !== LABEL::LABEL_REPEATED()) {
         $body[] = $variable . ' = ' . $this->generateReadScalarStatement($type->value()) . ';';
         $body[] = null;
         $body[] = $breakSttm;
         return $body;
     }
     $body[] = 'if (' . $variable . ' === null) {';
     $body[] = '    ' . $variable . ' = new ' . $this->getCollectionClassName($field) . '();';
     $body[] = '}';
     $body[] = null;
     $body[] = $variable . '->add(' . $this->generateReadScalarStatement($type->value()) . ');';
//.........这里部分代码省略.........
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:101,代码来源:ReadFieldStatementGenerator.php

示例3: getJavaDocType

 protected function getJavaDocType(proto\FieldDescriptorProto $field)
 {
     switch ($field->getType()) {
         case Protobuf::TYPE_DOUBLE:
         case Protobuf::TYPE_FLOAT:
             return 'float';
         case Protobuf::TYPE_INT64:
         case Protobuf::TYPE_UINT64:
         case Protobuf::TYPE_INT32:
         case Protobuf::TYPE_FIXED64:
         case Protobuf::TYPE_FIXED32:
         case Protobuf::TYPE_UINT32:
         case Protobuf::TYPE_SFIXED32:
         case Protobuf::TYPE_SFIXED64:
         case Protobuf::TYPE_SINT32:
         case Protobuf::TYPE_SINT64:
             return 'int';
         case Protobuf::TYPE_BOOL:
             return 'boolean';
         case Protobuf::TYPE_STRING:
             return 'string';
         case Protobuf::TYPE_MESSAGE:
             return '\\' . $this->normalizeNS($field->getTypeName());
         case Protobuf::TYPE_BYTES:
             return 'string';
         case Protobuf::TYPE_ENUM:
             return 'int - \\' . $this->normalizeNS($field->getTypeName());
         case Protobuf::TYPE_GROUP:
         default:
             return 'unknown';
     }
 }
开发者ID:stanley-cheung,项目名称:protobuf-php,代码行数:32,代码来源:PhpGenerator.php

示例4: doctype

 /**
  * Obtain a JavaDoc style type for the given field (int, float, string)
  *
  * @param proto\FieldDescriptorProto $field
  * return string
  */
 protected function doctype(proto\FieldDescriptorProto $field)
 {
     switch ($field->getType()) {
         case Protobuf\Protobuf::TYPE_DOUBLE:
         case Protobuf\Protobuf::TYPE_FLOAT:
             return 'float';
         case Protobuf\Protobuf::TYPE_INT64:
         case Protobuf\Protobuf::TYPE_UINT64:
         case Protobuf\Protobuf::TYPE_INT32:
         case Protobuf\Protobuf::TYPE_FIXED64:
         case Protobuf\Protobuf::TYPE_FIXED32:
         case Protobuf\Protobuf::TYPE_UINT32:
         case Protobuf\Protobuf::TYPE_SFIXED32:
         case Protobuf\Protobuf::TYPE_SFIXED64:
         case Protobuf\Protobuf::TYPE_SINT32:
         case Protobuf\Protobuf::TYPE_SINT64:
             return 'int';
         case Protobuf\Protobuf::TYPE_BOOL:
             return 'boolean';
         case Protobuf\Protobuf::TYPE_STRING:
             return 'string';
         case Protobuf\Protobuf::TYPE_MESSAGE:
             return $this->ns($field->type_name);
         case Protobuf\Protobuf::TYPE_BYTES:
             return 'string';
         case Protobuf\Protobuf::TYPE_ENUM:
             return 'int - ' . $this->ns($field->type_name);
         default:
             return '*unknown*';
     }
 }
开发者ID:geneanet,项目名称:Protobuf-PHP,代码行数:37,代码来源:AbstractGenerator.php

示例5: isEnum

 public static function isEnum(\google\protobuf\FieldDescriptorProto $field)
 {
     return self::TYPE_ENUM == $field->getType();
 }
开发者ID:melanc,项目名称:devel,代码行数:4,代码来源:Type.php

示例6: getDefaultFieldValue

 /**
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string
  */
 protected function getDefaultFieldValue(FieldDescriptorProto $field)
 {
     $type = $field->getType();
     $value = $field->getDefaultValue();
     if ($value === null) {
         return 'null';
     }
     if ($type === Type::TYPE_ENUM()) {
         $typeName = $field->getTypeName();
         $refEntity = $this->getEntity($typeName);
         $reference = $refEntity->getNamespacedName();
         $const = $reference . '::' . $value . '()';
         return $const;
     }
     if ($type === Type::TYPE_BOOL()) {
         $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
     }
     return var_export($value, true);
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:24,代码来源:BaseGenerator.php

示例7: defaultValueAsString

 public function defaultValueAsString(FieldDescriptorProto $field)
 {
     if (!$field->hasDefaultValue()) {
         return 'null';
     }
     $default_value = null;
     switch ($field->getType()) {
         case \ProtocolBuffers::TYPE_DOUBLE:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_FLOAT:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_INT64:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_UINT64:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_INT32:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_FIXED64:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_FIXED32:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_BOOL:
             return $field->getDefaultValue() == "true" ? "true" : "false";
         case \ProtocolBuffers::TYPE_STRING:
             return "\"" . addcslashes($field->getDefaultValue(), "\"\n\r\$") . "\"";
         case \ProtocolBuffers::TYPE_GROUP:
             return;
         case \ProtocolBuffers::TYPE_MESSAGE:
             return "null";
             break;
         case \ProtocolBuffers::TYPE_BYTES:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_UINT32:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_ENUM:
             $value = $field->getTypeName();
             $descriptor = MessagePool::get($value);
             if (!FieldDescriptorProto\Label::isRepeated($field)) {
                 $def = $field->getDefaultValue();
                 if (!empty($def)) {
                     $value = str_replace(".", "\\", $descriptor->full_name) . "::" . $field->getDefaultValue();
                 } else {
                     $value = "null";
                 }
                 return $value;
             } else {
                 return "array()";
             }
         case \ProtocolBuffers::TYPE_SFIXED32:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_SFIXED64:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_SINT32:
             $default_value = $field->getDefaultValue();
             break;
         case \ProtocolBuffers::TYPE_SINT64:
             $default_value = $field->getDefaultValue();
             break;
     }
     if (!$default_value && $default_value !== 0) {
         return "null";
     } else {
         return $default_value;
     }
 }
开发者ID:asamaru7,项目名称:protoc-gen-php,代码行数:76,代码来源:MessageGenerator.php

示例8: getJsDoc

 public function getJsDoc(proto\FieldDescriptorProto $field)
 {
     switch ($field->getType()) {
         case Protobuf::TYPE_DOUBLE:
         case Protobuf::TYPE_FLOAT:
             return 'Float';
         case Protobuf::TYPE_INT64:
         case Protobuf::TYPE_UINT64:
         case Protobuf::TYPE_INT32:
         case Protobuf::TYPE_FIXED64:
         case Protobuf::TYPE_FIXED32:
         case Protobuf::TYPE_UINT32:
         case Protobuf::TYPE_SFIXED32:
         case Protobuf::TYPE_SFIXED64:
         case Protobuf::TYPE_SINT32:
         case Protobuf::TYPE_SINT64:
             return 'Int';
         case Protobuf::TYPE_BOOL:
             return 'Boolean';
         case Protobuf::TYPE_STRING:
             return 'String';
         case Protobuf::TYPE_MESSAGE:
             return $this->normalizeNS($field->getTypeName());
         case Protobuf::TYPE_BYTES:
             return 'String';
         case Protobuf::TYPE_ENUM:
             return 'Int (' . $this->normalizeNS($field->getTypeName()) . ')';
         case Protobuf::TYPE_GROUP:
         default:
             return 'unknown';
     }
 }
开发者ID:JosephGarrone,项目名称:flerovium,代码行数:32,代码来源:JsonGenerator.php

示例9: generateFieldBody

 /**
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string[]
  */
 protected function generateFieldBody(FieldDescriptorProto $field)
 {
     $lines = [];
     $name = $field->getName();
     $number = $field->getNumber();
     $typeName = $field->getTypeName();
     $extendee = $field->getExtendee();
     $type = $field->getType()->name();
     $label = $field->getLabel()->name();
     $default = $this->getDefaultFieldValue($field);
     $values = ['number' => var_export($number, true), 'name' => var_export($name, true), 'type' => '\\google\\protobuf\\FieldDescriptorProto\\Type::' . $type . '()', 'label' => '\\google\\protobuf\\FieldDescriptorProto\\Label::' . $label . '()'];
     if ($extendee) {
         $values['extendee'] = var_export($extendee, true);
     }
     if ($typeName) {
         $values['type_name'] = var_export($typeName, true);
     }
     if ($field->hasDefaultValue()) {
         $values['default_value'] = $default;
     }
     $lines[] = '\\google\\protobuf\\FieldDescriptorProto::fromArray([';
     $lines = array_merge($lines, $this->generateArrayLines($values));
     $lines[] = ']),';
     return $lines;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:30,代码来源:DescriptorGenerator.php

示例10: generateAddMethod

 /**
  * @param \Protobuf\Compiler\Entity            $entity
  * @param google\protobuf\FieldDescriptorProto $field
  *
  * @return \Zend\Code\Generator\GeneratorInterface
  */
 protected function generateAddMethod(Entity $entity, FieldDescriptorProto $field)
 {
     $fieldName = $field->getName();
     $fieldType = $field->getType();
     $collClass = $this->getCollectionClassName($field);
     $methodName = 'add' . $this->getClassifiedName($field);
     $typeHint = $fieldType !== Type::TYPE_BYTES() ? $this->getDoctype($field) : null;
     $lines[] = 'if ($this->' . $fieldName . ' === null) {';
     $lines[] = '    $this->' . $fieldName . ' = new ' . $collClass . '();';
     $lines[] = '}';
     $lines[] = null;
     $lines[] = $fieldType !== Type::TYPE_BYTES() ? '$this->' . $fieldName . '->add($value);' : '$this->' . $fieldName . '->add(\\Protobuf\\Stream::wrap($value));';
     return MethodGenerator::fromArray(['name' => $methodName, 'body' => implode(PHP_EOL, $lines), 'parameters' => [['name' => 'value', 'type' => $typeHint]], 'docblock' => ['shortDescription' => "Add a new element to '{$fieldName}'", 'tags' => [['name' => 'param', 'description' => $this->getDoctype($field) . ' $value']]]]);
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:20,代码来源:FieldsGenerator.php


注:本文中的Google\Protobuf\FieldDescriptorProto::getType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。