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


Java Descriptor类代码示例

本文整理汇总了Java中com.google.protobuf.Descriptors.Descriptor的典型用法代码示例。如果您正苦于以下问题:Java Descriptor类的具体用法?Java Descriptor怎么用?Java Descriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: buildMessage

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的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

示例2: mergeMapField

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private void mergeMapField(FieldDescriptor field, JsonElement json, Message.Builder builder)
    throws InvalidProtocolBufferException {
  if (!(json instanceof JsonObject)) {
    throw new InvalidProtocolBufferException("Expect a map object but found: " + json);
  }
  Descriptor type = field.getMessageType();
  FieldDescriptor keyField = type.findFieldByName("key");
  FieldDescriptor valueField = type.findFieldByName("value");
  if (keyField == null || valueField == null) {
    throw new InvalidProtocolBufferException("Invalid map field: " + field.getFullName());
  }
  JsonObject object = (JsonObject) json;
  for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
    Message.Builder entryBuilder = builder.newBuilderForField(field);
    Object key = parseFieldValue(keyField, new JsonPrimitive(entry.getKey()), entryBuilder);
    Object value = parseFieldValue(valueField, entry.getValue(), entryBuilder);
    if (value == null) {
      throw new InvalidProtocolBufferException("Map value cannot be null.");
    }
    entryBuilder.setField(keyField, key);
    entryBuilder.setField(valueField, value);
    builder.addRepeatedField(field, entryBuilder.build());
  }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:25,代码来源:JsonFormat.java

示例3: createProtoBuf

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
Message createProtoBuf(
    Descriptor descriptor, Message.Builder builder, Map<String, Object> input) {

  if (input == null) {
    return builder.build();
  }
  for (FieldDescriptor field : descriptor.getFields()) {
    String fieldName = field.getName();

    if (!input.containsKey(fieldName)) {
      // TODO: validate required fields
      continue;
    }

    if (field.isRepeated()) {
      List<Object> values = (List<Object>) input.get(fieldName);
      for (Object value : values) {
        builder.addRepeatedField(field, getValueForField(field, value, builder));
      }
    } else {
      builder.setField(field, getValueForField(field, input.get(fieldName), builder));
    }
  }

  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:27,代码来源:GqlInputConverter.java

示例4: build

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
GqlInputConverter build() {
  HashBiMap<String, Descriptor> mapping = HashBiMap.create();
  HashBiMap<String, EnumDescriptor> enumMapping = HashBiMap.create(getEnumMap(enumDescriptors));
  LinkedList<Descriptor> loop = new LinkedList<>(descriptors);

  Set<FileDescriptor> fileDescriptorSet = ProtoRegistry.extractDependencies(fileDescriptors);

  for (FileDescriptor fileDescriptor : fileDescriptorSet) {
    loop.addAll(fileDescriptor.getMessageTypes());
    enumMapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
  }

  while (!loop.isEmpty()) {
    Descriptor descriptor = loop.pop();
    if (!mapping.containsKey(descriptor.getFullName())) {
      mapping.put(getReferenceName(descriptor), descriptor);
      loop.addAll(descriptor.getNestedTypes());
      enumMapping.putAll(getEnumMap(descriptor.getEnumTypes()));
    }
  }

  return new GqlInputConverter(
      ImmutableBiMap.copyOf(mapping), ImmutableBiMap.copyOf(enumMapping));
}
 
开发者ID:google,项目名称:rejoiner,代码行数:25,代码来源:GqlInputConverter.java

示例5: getAllFieldsMutable

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
/** Internal helper which returns a mutable map. */
private Map<FieldDescriptor, Object> getAllFieldsMutable() {
  final TreeMap<FieldDescriptor, Object> result =
    new TreeMap<FieldDescriptor, Object>();
  final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
  for (final FieldDescriptor field : descriptor.getFields()) {
    if (field.isRepeated()) {
      final List value = (List) getField(field);
      if (!value.isEmpty()) {
        result.put(field, value);
      }
    } else {
      if (hasField(field)) {
        result.put(field, getField(field));
      }
    }
  }
  return result;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:20,代码来源:GeneratedMessage.java

示例6: ProtoFieldInfo

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
ProtoFieldInfo(FieldDescriptor field, Message containingPrototype) {
  this.field = checkNotNull(field, "field");
  this.containingPrototype = checkNotNull(containingPrototype, "containingPrototype");
  builderClass = containingPrototype.newBuilderForType().getClass();

  camelCaseName = underscoresToUpperCamelCase(field.getName());

  if (field.isMapField()) {
    Descriptor mapType = field.getMessageType();
    mapKeyField = new ProtoFieldInfo(mapType.findFieldByName("key"), containingPrototype);
    mapValueField = new ProtoFieldInfo(mapType.findFieldByName("value"), containingPrototype);
  } else {
    mapKeyField = null;
    mapValueField = null;
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:17,代码来源:ProtoFieldInfo.java

示例7: DynamicMessage

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
/**
 * Construct a {@code DynamicMessage} using the given {@code FieldSet}.
 */
private DynamicMessage(Descriptor type, FieldSet<FieldDescriptor> fields,
                       UnknownFieldSet unknownFields) {
  this.type = type;
  this.fields = fields;
  this.unknownFields = unknownFields;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:10,代码来源:DynamicMessage.java

示例8: mergeListValue

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private void mergeListValue(JsonElement json, Message.Builder builder)
    throws InvalidProtocolBufferException {
  Descriptor descriptor = builder.getDescriptorForType();
  FieldDescriptor field = descriptor.findFieldByName("values");
  if (field == null) {
    throw new InvalidProtocolBufferException("Invalid ListValue type.");
  }
  mergeRepeatedField(field, json, builder);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:10,代码来源:JsonFormat.java

示例9: parseFrom

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
/** Parse a message of the given type from the given input stream. */
public static DynamicMessage parseFrom(
    Descriptor type,
    CodedInputStream input,
    ExtensionRegistry extensionRegistry)
    throws IOException {
  return newBuilder(type).mergeFrom(input, extensionRegistry).buildParsed();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:9,代码来源:DynamicMessage.java

示例10: mergeWrapper

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private void mergeWrapper(JsonElement json, Message.Builder builder)
    throws InvalidProtocolBufferException {
  Descriptor type = builder.getDescriptorForType();
  FieldDescriptor field = type.findFieldByName("value");
  if (field == null) {
    throw new InvalidProtocolBufferException("Invalid wrapper type: " + type.getFullName());
  }
  builder.setField(field, parseFieldValue(field, json, builder));
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:10,代码来源:JsonFormat.java

示例11: isInitialized

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private static boolean isInitialized(Descriptor type,
                                     FieldSet<FieldDescriptor> fields) {
  // Check that all required fields are present.
  for (final FieldDescriptor field : type.getFields()) {
    if (field.isRequired()) {
      if (!fields.hasField(field)) {
        return false;
      }
    }
  }

  // Check that embedded messages are initialized.
  return fields.isInitialized();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:15,代码来源:DynamicMessage.java

示例12: mergeStruct

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private void mergeStruct(JsonElement json, Message.Builder builder)
    throws InvalidProtocolBufferException {
  Descriptor descriptor = builder.getDescriptorForType();
  FieldDescriptor field = descriptor.findFieldByName("fields");
  if (field == null) {
    throw new InvalidProtocolBufferException("Invalid Struct type.");
  }
  mergeMapField(field, json, builder);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:10,代码来源:JsonFormat.java

示例13: addMessage

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
private void addMessage(Descriptor message) {
  for (Descriptor nestedType : message.getNestedTypes()) {
    addMessage(nestedType);
  }

  if (types.containsKey(message.getFullName())) {
    logger.warning("Type " + message.getFullName() + " is added multiple times.");
    return;
  }

  types.put(message.getFullName(), message);
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:13,代码来源:JsonFormat.java

示例14: testFieldDescriptorDefault

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
public void testFieldDescriptorDefault() throws Exception {
  Descriptor d = TestAllTypes.getDescriptor();
  assertFalse(d.findFieldByName("optional_int32").hasDefaultValue());
  assertEquals(0, d.findFieldByName("optional_int32").getDefaultValue());
  assertTrue(d.findFieldByName("default_int32").hasDefaultValue());
  assertEquals(41, d.findFieldByName("default_int32").getDefaultValue());

  d = TestExtremeDefaultValues.getDescriptor();
  assertEquals(
    ByteString.copyFrom(
      "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes("ISO-8859-1")),
    d.findFieldByName("escaped_bytes").getDefaultValue());
  assertEquals(-1, d.findFieldByName("large_uint32").getDefaultValue());
  assertEquals(-1L, d.findFieldByName("large_uint64").getDefaultValue());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:16,代码来源:DescriptorsTest.java

示例15: add

import com.google.protobuf.Descriptors.Descriptor; //导入依赖的package包/类
/**
 * Adds message types and all types defined in the same .proto file as
 * well as all transitively imported .proto files to this {@link Builder}.
 */
public Builder add(Iterable<Descriptor> messageTypes) {
  if (types == null) {
    throw new IllegalStateException("A TypeRegistry.Builer can only be used once.");
  }
  for (Descriptor type : messageTypes) {
    addFile(type.getFile());
  }
  return this;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:14,代码来源:JsonFormat.java


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