本文整理汇总了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';
}
}
示例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()) . ');';
//.........这里部分代码省略.........
示例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);
}
示例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;
}
}
示例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';
}
}
示例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;
}