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


PHP FieldDescriptorProto::getTypeName方法代码示例

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


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

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: 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


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