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


Java MessageOrBuilder.getDescriptorForType方法代码示例

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


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

示例1: getPropertyFieldDescriptor

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
protected FieldDescriptor getPropertyFieldDescriptor(final MessageOrBuilder mob,
    final Object property) {
  final Descriptor descriptor = mob.getDescriptorForType();
  FieldDescriptor field = null;

  if (property instanceof String) {
    field = descriptor.findFieldByName(property.toString());
  } else if (property instanceof FieldDescriptor) {
    field = FieldDescriptor.class.cast(property);

    if (field.getContainingType() != descriptor) {
      field = null;
    }
  }

  if (field == null) {
    throw new PropertyNotFoundException();
  }

  return field;
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:22,代码来源:BuilderELResolver.java

示例2: printWrapper

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
/** Prints wrapper types (e.g., google.protobuf.Int32Value) */
private void printWrapper(MessageOrBuilder message) throws IOException {
  Descriptor descriptor = message.getDescriptorForType();
  FieldDescriptor valueField = descriptor.findFieldByName("value");
  if (valueField == null) {
    throw new InvalidProtocolBufferException("Invalid Wrapper type.");
  }
  // When formatting wrapper types, we just print its value field instead of
  // the whole message.
  printSingleFieldValue(valueField, message.getField(valueField));
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:12,代码来源:JsonFormat.java

示例3: printStruct

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
/** Prints google.protobuf.Struct */
private void printStruct(MessageOrBuilder message) throws IOException {
  Descriptor descriptor = message.getDescriptorForType();
  FieldDescriptor field = descriptor.findFieldByName("fields");
  if (field == null) {
    throw new InvalidProtocolBufferException("Invalid Struct type.");
  }
  // Struct is formatted as a map object.
  printMapFieldValue(field, message.getField(field));
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:11,代码来源:JsonFormat.java

示例4: printListValue

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
/** Prints google.protobuf.ListValue */
private void printListValue(MessageOrBuilder message) throws IOException {
  Descriptor descriptor = message.getDescriptorForType();
  FieldDescriptor field = descriptor.findFieldByName("values");
  if (field == null) {
    throw new InvalidProtocolBufferException("Invalid ListValue type.");
  }
  printRepeatedFieldValue(field, message.getField(field));
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:10,代码来源:JsonFormat.java

示例5: printAny

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
/** Prints google.protobuf.Any */
private void printAny(MessageOrBuilder message) throws IOException {
  if (Any.getDefaultInstance().equals(message)) {
    generator.print("{}");
    return;
  }
  Descriptor descriptor = message.getDescriptorForType();
  FieldDescriptor typeUrlField = descriptor.findFieldByName("type_url");
  FieldDescriptor valueField = descriptor.findFieldByName("value");
  // Validates type of the message. Note that we can't just cast the message
  // to com.google.protobuf.Any because it might be a DynamicMessage.
  if (typeUrlField == null
      || valueField == null
      || typeUrlField.getType() != FieldDescriptor.Type.STRING
      || valueField.getType() != FieldDescriptor.Type.BYTES) {
    throw new InvalidProtocolBufferException("Invalid Any type.");
  }
  String typeUrl = (String) message.getField(typeUrlField);
  String typeName = getTypeName(typeUrl);
  Descriptor type = registry.find(typeName);
  if (type == null) {
    throw new InvalidProtocolBufferException("Cannot find type for url: " + typeUrl);
  }
  ByteString content = (ByteString) message.getField(valueField);
  Message contentMessage =
      DynamicMessage.getDefaultInstance(type).getParserForType().parseFrom(content);
  WellKnownTypePrinter printer = wellKnownTypePrinters.get(typeName);
  if (printer != null) {
    // If the type is one of the well-known types, we use a special
    // formatting.
    generator.print("{" + blankOrNewLine);
    generator.indent();
    generator.print("\"@type\":" + blankOrSpace + gson.toJson(typeUrl) + "," + blankOrNewLine);
    generator.print("\"value\":" + blankOrSpace);
    printer.print(this, contentMessage);
    generator.print(blankOrNewLine);
    generator.outdent();
    generator.print("}");
  } else {
    // Print the content message instead (with a "@type" field added).
    print(contentMessage, typeUrl);
  }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:44,代码来源:JsonFormat.java

示例6: getVerifiedSingleValue

import com.google.protobuf.MessageOrBuilder; //导入方法依赖的package包/类
private static Object getVerifiedSingleValue(final FieldDescriptor field, final Object value,
    final Class<? extends MessageOrBuilder> type) {
  if (value == null) {
    throw new NullPointerException();
  }

  switch (field.getJavaType()) {
    case INT:
      return Integer.class.cast(value);
    case LONG:
      return Long.class.cast(value);
    case FLOAT:
      return Float.class.cast(value);
    case DOUBLE:
      return Double.class.cast(value);
    case BOOLEAN:
      return Boolean.class.cast(value);
    case STRING:
      return String.class.cast(value);
    case BYTE_STRING:
      return ByteString.class.cast(value);
    case ENUM:
      if (value instanceof EnumValueDescriptor) {
        if (((EnumValueDescriptor) value).getType() == field.getEnumType()) {
          return value;
        }
      } else {
        EnumValueDescriptor enumValue = null;

        if (value instanceof Internal.EnumLite) {
          enumValue =
              field.getEnumType().findValueByNumber(((Internal.EnumLite) value).getNumber());
        } else if (value instanceof Number) {
          enumValue = field.getEnumType().findValueByNumber(((Number) value).intValue());
        } else if (value instanceof String) {
          enumValue = field.getEnumType().findValueByName((String) value);
        }

        if (enumValue != null) {
          return enumValue;
        }
      }

      break;
    case MESSAGE:
      final Class<? extends MessageOrBuilder> expectedType =
      type == null ? Message.class : (Class<? extends MessageOrBuilder>) type;
      final MessageOrBuilder resolvedValue =
          expectedType
          .cast(value instanceof LazyField ? ((LazyField) value).getValue() : value);

      if (resolvedValue.getDescriptorForType() == field.getMessageType()) {
        return resolvedValue;
      }

      break;
  }

  throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:61,代码来源:DynamicMessage.java


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