本文整理汇总了PHP中Google\Protobuf\DescriptorProto::getFieldList方法的典型用法代码示例。如果您正苦于以下问题:PHP DescriptorProto::getFieldList方法的具体用法?PHP DescriptorProto::getFieldList怎么用?PHP DescriptorProto::getFieldList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google\Protobuf\DescriptorProto
的用法示例。
在下文中一共展示了DescriptorProto::getFieldList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUniqueFieldName
/**
* @param \google\protobuf\DescriptorProto $descriptor
* @param string $default
*
* @return string
*/
protected function getUniqueFieldName(DescriptorProto $descriptor, $default)
{
$extensions = $descriptor->getExtensionList() ?: [];
$fields = $descriptor->getFieldList() ?: [];
$name = $default;
$names = [];
$count = 0;
foreach ($fields as $field) {
$names[$field->getName()] = true;
}
foreach ($extensions as $field) {
$names[$field->getName()] = true;
}
while (isset($names[$name])) {
$name = $default . $count++;
}
return $name;
}
示例2: compileMessage
public function compileMessage(proto\DescriptorProto $msg, $namespace)
{
$s[] = "/**";
$s[] = " * @constructor";
$s[] = " * @augments {ProtoJson.Message}";
$s[] = " * @extends ProtoJson.Message";
$s[] = " * @memberOf {$namespace}";
$s[] = " * @param {object} data - Optional, provide initial data to parse";
$s[] = " */";
$s[] = "{$namespace}.{$msg->name} = ProtoJson.create({";
$s[] = " fields: {";
$lines = array();
foreach ($msg->getFieldList() as $field) {
$lines[] = " {$field->number}: " . $this->generateField($field);
}
$s[] = implode(",\n", $lines);
$s[] = " },";
$s[] = " ranges: [";
// @todo dump extension ranges
$s[] = " ]";
$s[] = "});";
$s[] = "";
// Compute a new namespace with the message name as suffix
$namespace .= "." . $msg->getName();
// Generate getters/setters
foreach ($msg->getFieldList() as $field) {
$s[] = $this->generateAccessors($field, $namespace);
}
// Generate Enums
foreach ($msg->getEnumTypeList() as $enum) {
$s[] = $this->compileEnum($enum, $namespace);
}
// Generate nested messages
foreach ($msg->getNestedTypeList() as $msg) {
$s[] = $this->compileMessage($msg, $namespace);
}
// Collect extensions
foreach ($msg->getExtensionList() as $field) {
$this->extensions[$field->getExtendee()][] = array($namespace, $field);
}
return implode("\n", $s);
}