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


Java OneofDescriptor.getFieldCount方法代码示例

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


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

示例1: getAllFieldsMutable

import com.google.protobuf.Descriptors.OneofDescriptor; //导入方法依赖的package包/类
/**
 * Internal helper to return a modifiable map containing all the fields.
 * The returned Map is modifialbe so that the caller can add additional
 * extension fields to implement {@link #getAllFields()}.
 *
 * @param getBytesForString whether to generate ByteString for string fields
 */
private Map<FieldDescriptor, Object> getAllFieldsMutable(
    boolean getBytesForString) {
  final TreeMap<FieldDescriptor, Object> result =
    new TreeMap<FieldDescriptor, Object>();
  final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
  final List<FieldDescriptor> fields = descriptor.getFields();

  for (int i = 0; i < fields.size(); i++) {
    FieldDescriptor field = fields.get(i);
    final OneofDescriptor oneofDescriptor = field.getContainingOneof();

    /*
     * If the field is part of a Oneof, then at maximum one field in the Oneof is set
     * and it is not repeated. There is no need to iterate through the others.
     */
    if (oneofDescriptor != null) {
      // Skip other fields in the Oneof we know are not set
      i += oneofDescriptor.getFieldCount() - 1;
      if (!hasOneof(oneofDescriptor)) {
        // If no field is set in the Oneof, skip all the fields in the Oneof
        continue;
      }
      // Get the pointer to the only field which is set in the Oneof
      field = getOneofFieldDescriptor(oneofDescriptor);
    } else {
      // If we are not in a Oneof, we need to check if the field is set and if it is repeated
      if (field.isRepeated()) {
        final List<?> value = (List<?>) getField(field);
        if (!value.isEmpty()) {
          result.put(field, value);
        }
        continue;
      }
      if (!hasField(field)) {
        continue;
      }
    }
    // Add the field to the map
    if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) {
      result.put(field, getFieldRaw(field));
    } else {
      result.put(field, getField(field));
    }
  }
  return result;
}
 
开发者ID:reubenbrown13,项目名称:cfapi,代码行数:54,代码来源:GeneratedMessage.java


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