當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。