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


Java FieldDescriptor类代码示例

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


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

示例1: mergeMapField

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

示例2: mergeMessage

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
private void mergeMessage(JsonElement json, Message.Builder builder, boolean skipTypeUrl)
    throws InvalidProtocolBufferException {
  if (!(json instanceof JsonObject)) {
    throw new InvalidProtocolBufferException("Expect message object but got: " + json);
  }
  JsonObject object = (JsonObject) json;
  Map<String, FieldDescriptor> fieldNameMap = getFieldNameMap(builder.getDescriptorForType());
  for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
    if (skipTypeUrl && entry.getKey().equals("@type")) {
      continue;
    }
    FieldDescriptor field = fieldNameMap.get(entry.getKey());
    if (field == null) {
      if (ignoringUnknownFields) {
        continue;
      }
      throw new InvalidProtocolBufferException(
          "Cannot find field: "
              + entry.getKey()
              + " in message "
              + builder.getDescriptorForType().getFullName());
    }
    mergeField(field, entry.getValue(), builder);
  }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:26,代码来源:JsonFormat.java

示例3: apply

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
@Override
public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) {
  GraphQLFieldDefinition.Builder builder =
      GraphQLFieldDefinition.newFieldDefinition()
          .type(convertType(fieldDescriptor))
          .dataFetcher(
              new ProtoDataFetcher(UNDERSCORE_TO_CAMEL.convert(fieldDescriptor.getName())))
          .name(UNDERSCORE_TO_CAMEL.convert(fieldDescriptor.getName()));
  if (fieldDescriptor.getFile().toProto().getSourceCodeInfo().getLocationCount()
      > fieldDescriptor.getIndex()) {
    builder.description(
        fieldDescriptor
            .getFile()
            .toProto()
            .getSourceCodeInfo()
            .getLocation(fieldDescriptor.getIndex())
            .getLeadingComments());
  }
  if (fieldDescriptor.getOptions().hasDeprecated()
      && fieldDescriptor.getOptions().getDeprecated()) {
    builder.deprecate("deprecated in proto");
  }
  return builder.build();
}
 
开发者ID:google,项目名称:rejoiner,代码行数:25,代码来源:ProtoToGql.java

示例4: getField

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:GeneratedMessage.java

示例5: fromReflectionType

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
/**
 * Convert from the type used by the reflection accessors to the type used
 * by native accessors.  E.g., for enums, the reflection accessors use
 * EnumValueDescriptors but the native accessors use the generated enum
 * type.
 */
@SuppressWarnings("unchecked")
private Object fromReflectionType(final Object value) {
  if (descriptor.isRepeated()) {
    if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE ||
        descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) {
      // Must convert the whole list.
      final List result = new ArrayList();
      for (final Object element : (List) value) {
        result.add(singularFromReflectionType(element));
      }
      return result;
    } else {
      return value;
    }
  } else {
    return singularFromReflectionType(value);
  }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:25,代码来源:GeneratedMessage.java

示例6: writeTo

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
public void writeTo(final CodedOutputStream output) throws IOException {
  final boolean isMessageSet =
      getDescriptorForType().getOptions().getMessageSetWireFormat();

  for (final Map.Entry<FieldDescriptor, Object> entry :
      getAllFields().entrySet()) {
    final FieldDescriptor field = entry.getKey();
    final Object value = entry.getValue();
    if (isMessageSet && field.isExtension() &&
        field.getType() == FieldDescriptor.Type.MESSAGE &&
        !field.isRepeated()) {
      output.writeMessageSetExtension(field.getNumber(), (Message) value);
    } else {
      FieldSet.writeField(field, value, output);
    }
  }

  final UnknownFieldSet unknownFields = getUnknownFields();
  if (isMessageSet) {
    unknownFields.writeAsMessageSetTo(output);
  } else {
    unknownFields.writeTo(output);
  }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:25,代码来源:AbstractMessage.java

示例7: toReflectionType

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
/**
 * Convert from the type used by the native accessors to the type used
 * by reflection accessors.  E.g., for enums, the reflection accessors use
 * EnumValueDescriptors but the native accessors use the generated enum
 * type.
 */
@SuppressWarnings("unchecked")
private Object toReflectionType(final Object value) {
  if (descriptor.isRepeated()) {
    if (descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) {
      // Must convert the whole list.
      final List result = new ArrayList();
      for (final Object element : (List) value) {
        result.add(singularToReflectionType(element));
      }
      return result;
    } else {
      return value;
    }
  } else {
    return singularToReflectionType(value);
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:24,代码来源:GeneratedMessage.java

示例8: add

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
private void add(final ExtensionInfo extension) {
  if (!extension.descriptor.isExtension()) {
    throw new IllegalArgumentException(
      "ExtensionRegistry.add() was given a FieldDescriptor for a regular " +
      "(non-extension) field.");
  }

  extensionsByName.put(extension.descriptor.getFullName(), extension);
  extensionsByNumber.put(
    new DescriptorIntPair(extension.descriptor.getContainingType(),
                          extension.descriptor.getNumber()),
    extension);

  final FieldDescriptor field = extension.descriptor;
  if (field.getContainingType().getOptions().getMessageSetWireFormat() &&
      field.getType() == FieldDescriptor.Type.MESSAGE &&
      field.isOptional() &&
      field.getExtensionScope() == field.getMessageType()) {
    // This is an extension of a MessageSet type defined within the extension
    // type's own scope.  For backwards-compatibility, allow it to be looked
    // up by type name.
    extensionsByName.put(field.getMessageType().getFullName(), extension);
  }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:25,代码来源:ExtensionRegistry.java

示例9: handleObject

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
private Object handleObject(Tokenizer tokenizer,
                                   ExtensionRegistry extensionRegistry,
                                   Message.Builder builder,
                                   FieldDescriptor field,
                                   ExtensionRegistry.ExtensionInfo extension) throws ParseException {

    Object value;
    Message.Builder subBuilder;
    if (extension == null) {
        subBuilder = builder.newBuilderForField(field);
    } else {
        subBuilder = extension.defaultInstance.newBuilderForType();
    }

    //tokenizer.consume("<");
    String endToken = "</";

    while (!tokenizer.tryConsume(endToken)) {
        if (tokenizer.atEnd()) {
            throw tokenizer.parseException("Expected \"" + endToken + "\".");
        }
        mergeField(tokenizer, extensionRegistry, subBuilder);
    }

    value = subBuilder.build();
    return value;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:28,代码来源:XmlFormat.java

示例10: RepeatedMessageFieldAccessor

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
RepeatedMessageFieldAccessor(
    final FieldDescriptor descriptor, final String camelCaseName,
    final Class<? extends GeneratedMessage> messageClass,
    final Class<? extends Builder> builderClass) {
  super(descriptor, camelCaseName, messageClass, builderClass);

  newBuilderMethod = getMethodOrDie(type, "newBuilder");
}
 
开发者ID:s-store,项目名称:s-store,代码行数:9,代码来源:GeneratedMessage.java

示例11: setExtension

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
/** Set the value of one element of a repeated extension. */
public final <Type> BuilderType setExtension(
    final GeneratedExtension<MessageType, List<Type>> extension,
    final int index, final Type value) {
  final ExtendableMessage<MessageType> message = internalGetResult();
  message.verifyExtensionContainingType(extension);
  final FieldDescriptor descriptor = extension.getDescriptor();
  message.extensions.setRepeatedField(
    descriptor, index,
    extension.singularToReflectionType(value));
  return (BuilderType) this;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:13,代码来源:GeneratedMessage.java

示例12: isInitialized

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

示例13: printField

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
private static void printField(final FieldDescriptor field,
                              final Object value,
                              final TextGenerator generator)
                              throws IOException {
  if (field.isRepeated()) {
    // Repeated field.  Print each element.
    for (final Object element : (List) value) {
      printSingleField(field, element, generator);
    }
  } else {
    printSingleField(field, value, generator);
  }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:14,代码来源:TextFormat.java

示例14: add

import com.google.protobuf.Descriptors.FieldDescriptor; //导入依赖的package包/类
/** Add a non-message-type extension to the registry by descriptor. */
public void add(final FieldDescriptor type) {
  if (type.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
    throw new IllegalArgumentException(
      "ExtensionRegistry.add() must be provided a default instance when " +
      "adding an embedded message extension.");
  }
  add(new ExtensionInfo(type, null));
}
 
开发者ID:s-store,项目名称:s-store,代码行数:10,代码来源:ExtensionRegistry.java

示例15: mergeWrapper

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


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