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


Java Builder.setField方法代码示例

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


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

示例1: setTargetField

import com.google.protobuf.Message.Builder; //导入方法依赖的package包/类
private static void setTargetField(final Builder target, final Object sourceObject, final String targetField)
                throws IllegalArgumentException {
    Descriptors.FieldDescriptor fieldDescriptor = target.getDescriptorForType().findFieldByName(targetField);
    if (null == fieldDescriptor) {
        throw new RuntimeException("Unknown target field in protobuf: " + targetField);
    }

    if (fieldDescriptor.isRepeated()) {
        target.addRepeatedField(fieldDescriptor, sourceObject);
    } else {
        target.setField(fieldDescriptor, sourceObject);
    }
}
 
开发者ID:yahoo,项目名称:xpath_proto_builder,代码行数:14,代码来源:JXPathCopier.java

示例2: buildKey

import com.google.protobuf.Message.Builder; //导入方法依赖的package包/类
public T buildKey(T data) {
  Builder b = data.newBuilderForType();
  for (FieldDescriptor field : fields) {
    if (!data.hasField(field)) {
      if (requireFields) {
        throw new IllegalStateException("Field not set: " + field.getFullName());
      } else {
        continue;
      }
    }
    Object value = data.getField(field);
    b.setField(field, value);
  }
  return (T) b.build();
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:16,代码来源:InMemoryDataStore.java

示例3: buildMessage

import com.google.protobuf.Message.Builder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Object buildMessage(Builder builder, Map<String, Object> fields) {
  Descriptor descriptor = builder.getDescriptorForType();
  for (Map.Entry<String, Object> entry : fields.entrySet()) {
    if (entry.getValue() == null) {
      continue;
    }
    FieldDescriptor field = getField(descriptor, entry.getKey());
    if (entry.getValue() instanceof List<?>) {
      List<Object> values = (List<Object>) entry.getValue();
      for (Object value : values) {
        builder.addRepeatedField(field, buildValue(builder, field, value));
      }

    } else {
      builder.setField(field, buildValue(builder, field, entry.getValue()));
    }
  }
  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:21,代码来源:QueryResponseToProto.java

示例4: generate

import com.google.protobuf.Message.Builder; //导入方法依赖的package包/类
/**
 * Generates a random protocol buffer, filling in all required fields but
 * with a p chance of not setting an optional field and p chance of having
 * an empty repeated field.
 */
@SuppressWarnings("unchecked")
public E generate(double p) {
  Builder builder = instance.newBuilderForType();
  Descriptor descriptor = instance.getDescriptorForType();
  for (FieldDescriptor field : descriptor.getFields()) {
    if (!field.isRequired() && random.nextDouble() < p) {
      continue;
    }
    builder.setField(field, getRandomValue(field, p));
  }
  return (E) builder.build();
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:18,代码来源:RandomProtobufGenerator.java


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