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


Java EnumDescriptor.findValueByNumber方法代码示例

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


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

示例1: getValueForField

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
private Object getValueForField(FieldDescriptor field, Object value, Message.Builder builder) {
  // TODO: handle groups, oneof
  if (field.getType() == FieldDescriptor.Type.MESSAGE) {
    Descriptor fieldTypeDescriptor =
        descriptorMapping.get(getReferenceName(field.getMessageType()));
    return createProtoBuf(
        fieldTypeDescriptor, builder.newBuilderForField(field), (Map<String, Object>) value);
  }

  if (field.getType() == FieldDescriptor.Type.ENUM) {
    EnumDescriptor enumDescriptor =
        enumMapping.get(ProtoToGql.getReferenceName(field.getEnumType()));
    return enumDescriptor.findValueByNumber((int) value);
  }

  return value;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:18,代码来源:GqlInputConverter.java

示例2: parseEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
    throws InvalidProtocolBufferException {
  String value = json.getAsString();
  EnumValueDescriptor result = enumDescriptor.findValueByName(value);
  if (result == null) {
    // Try to interpret the value as a number.
    try {
      int numericValue = parseInt32(json);
      if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
        result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
      } else {
        result = enumDescriptor.findValueByNumber(numericValue);
      }
    } catch (InvalidProtocolBufferException e) {
      // Fall through. This exception is about invalid int32 value we get from parseInt32() but
      // that's not the exception we want the user to see. Since result == null, we will throw
      // an exception later.
    }

    if (result == null) {
      throw new InvalidProtocolBufferException(
          "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
    }
  }
  return result;
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:27,代码来源:JsonFormat.java

示例3: parseEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
/**
 * Parse Enum value {@link EnumValueDescriptor} associated with given {@link EnumDescriptor} from
 * given text if found. Otherwise, throw a {@link ParseException}.
 *
 * <p>The text could be either enum value name or enum value number.
 */
static EnumValueDescriptor parseEnum(EnumDescriptor enumType, String text) {
  EnumValueDescriptor value = null;
  if (lookingAtNumber(text)) {
    int number = parseUInt32(text);
    value = enumType.findValueByNumber(number);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with number %d", enumType.getFullName(), number));
    }
  } else {
    value = enumType.findValueByName(text);
    if (value == null) {
      throw new ParseException(String.format(
          "Enum type '%s' has no value with name '%s'", enumType.getFullName(), text));
    }
  }
  return value;
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:25,代码来源:ProtoFieldValueParser.java

示例4: printEnum

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
static void printEnum(int value, JsonGenerator gen, EnumDescriptor descriptor)
    throws IOException {
  EnumValueDescriptor valueDescriptor = descriptor.findValueByNumber(value);
  if (valueDescriptor == null) {
    gen.writeNumber(value);
  } else {
    gen.writeString(valueDescriptor.getName());
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:10,代码来源:SerializeSupport.java

示例5: handlePrimitive

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
private Object handlePrimitive(XMLEventReader parser, FieldDescriptor field, String value) {
    Object result = null;

    if (value == null) // precondition check
        return result;
    
    switch (field.getType()) {
        case INT32:
        case SINT32:
        case SFIXED32:
        	result = parseInt32(value);
            break;

        case INT64:
        case SINT64:
        case SFIXED64:
        	result = parseInt64(value);
            break;

        case UINT32:
        case FIXED32:
            result = parseUInt32(value);
            break;

        case UINT64:
        case FIXED64:
            result = parseUInt64(value);
            break;

        case FLOAT:
            result = parseFloat(value);
            break;

        case DOUBLE:
            result = parseDouble(value);
            break;

        case BOOL:
            result = parseBoolean(value);
            break;

        case STRING:
            result = value;
            break;

        case BYTES:
            result = unescapeBytes(value);
            break;

        case ENUM: {
            EnumDescriptor enumType = field.getEnumType();
            if (isDigits(value)) {
                int number = parseInt32(value);
                result = enumType.findValueByNumber(number);
                if (result == null) {
                    throw new RuntimeException("Enum type \""
                    		+ enumType.getFullName()
                    		+ "\" has no value with number "
                    		+ number + ".");
                }
            } else {
                String id = value;
                result = enumType.findValueByName(id);
                if (result == null) {
                	throw new RuntimeException("Enum type \""
                	        + enumType.getFullName() 
                	        + "\" has no value named \"" + id + "\".");
                }
            }
            break;
        }

        case MESSAGE:
        case GROUP:
            throw new RuntimeException("Can't get here.");
    }
    return result;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:79,代码来源:XmlJavaxFormat.java

示例6: handlePrimitive

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
private Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field) throws ParseException {
    Object value = null;
    if ("null".equals(tokenizer.currentToken())) {
        tokenizer.consume("null");
        return value;
    }
    switch (field.getType()) {
        case INT32:
        case SINT32:
        case SFIXED32:
            value = tokenizer.consumeInt32();
            break;

        case INT64:
        case SINT64:
        case SFIXED64:
            value = tokenizer.consumeInt64();
            break;

        case UINT32:
        case FIXED32:
            value = tokenizer.consumeUInt32();
            break;

        case UINT64:
        case FIXED64:
            value = tokenizer.consumeUInt64();
            break;

        case FLOAT:
            value = tokenizer.consumeFloat();
            break;

        case DOUBLE:
            value = tokenizer.consumeDouble();
            break;

        case BOOL:
            value = tokenizer.consumeBoolean();
            break;

        case STRING:
            value = tokenizer.consumeString();
            break;

        case BYTES:
            value = tokenizer.consumeByteString();
            break;

        case ENUM: {
            EnumDescriptor enumType = field.getEnumType();

            if (tokenizer.lookingAtInteger()) {
                int number = tokenizer.consumeInt32();
                value = enumType.findValueByNumber(number);
                if (value == null) {
                    throw tokenizer.parseExceptionPreviousToken("Enum type \""
                                                                + enumType.getFullName()
                                                                + "\" has no value with number "
                                                                + number + ".");
                }
            } else {
                String id = tokenizer.consumeIdentifier();
                value = enumType.findValueByName(id);
                if (value == null) {
                    throw tokenizer.parseExceptionPreviousToken("Enum type \""
                                                                + enumType.getFullName()
                                                                + "\" has no value named \""
                                                                + id + "\".");
                }
            }

            break;
        }

        case MESSAGE:
        case GROUP:
            throw new RuntimeException("Can't get here.");
    }
    return value;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:82,代码来源:JsonFormat.java

示例7: handlePrimitive

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
private Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field) throws ParseException {
  Object value = null;
  if ("null".equals(tokenizer.currentToken())) {
    tokenizer.consume("null");
    return value;
  }
  switch (field.getType()) {
    case INT32:
    case SINT32:
    case SFIXED32:
      value = tokenizer.consumeInt32();
      break;

    case INT64:
    case SINT64:
    case SFIXED64:
      value = tokenizer.consumeInt64();
      break;

    case UINT32:
    case FIXED32:
      value = tokenizer.consumeUInt32();
      break;

    case UINT64:
    case FIXED64:
      value = tokenizer.consumeUInt64();
      break;

    case FLOAT:
      value = tokenizer.consumeFloat();
      break;

    case DOUBLE:
      value = tokenizer.consumeDouble();
      break;

    case BOOL:
      value = tokenizer.consumeBoolean();
      break;

    case STRING:
      value = tokenizer.consumeString();
      break;

    case BYTES:
      value = tokenizer.consumeByteString();
      break;

    case ENUM: {
      EnumDescriptor enumType = field.getEnumType();

      if (tokenizer.lookingAtInteger()) {
        int number = tokenizer.consumeInt32();
        value = enumType.findValueByNumber(number);
        if (value == null) {
          throw tokenizer.parseExceptionPreviousToken("Enum type \""
              + enumType.getFullName()
              + "\" has no value with number "
              + number + ".");
        }
      } else {
        String id = tokenizer.consumeIdentifier();
        value = enumType.findValueByName(id);
        if (value == null) {
          throw tokenizer.parseExceptionPreviousToken("Enum type \""
              + enumType.getFullName()
              + "\" has no value named \""
              + id + "\".");
        }
      }

      break;
    }

    case MESSAGE:
    case GROUP:
      throw new RuntimeException("Can't get here.");
  }
  return value;
}
 
开发者ID:apache,项目名称:tajo,代码行数:82,代码来源:ProtobufJsonFormat.java

示例8: getEnumValue

import com.google.protobuf.Descriptors.EnumDescriptor; //导入方法依赖的package包/类
/**
 * Gets the enum value for the given enum type and number
 * 
 * @param enumTypeName the enum type name
 * @param enumNumber the enum number
 * @return the enum value descriptor (null if not found)
 */
public EnumValueDescriptor getEnumValue(String enumTypeName, int enumNumber) {
	EnumDescriptor enumType = getEnumDescriptor(enumTypeName);
	if (enumType == null) return null;
	return enumType.findValueByNumber(enumNumber);
}
 
开发者ID:os72,项目名称:protobuf-dynamic,代码行数:13,代码来源:DynamicSchema.java


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