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