本文整理汇总了Java中com.google.protobuf.Descriptors.FieldDescriptor.getEnumType方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor.getEnumType方法的具体用法?Java FieldDescriptor.getEnumType怎么用?Java FieldDescriptor.getEnumType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.Descriptors.FieldDescriptor
的用法示例。
在下文中一共展示了FieldDescriptor.getEnumType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePrimitive
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的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;
}
示例2: handlePrimitive
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
private Object handlePrimitive(Tokenizer tokenizer, FieldDescriptor field) throws ParseException {
Object value = null;
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: {
Descriptors.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;
}
示例3: handlePrimitive
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的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;
}
示例4: mustSkipNull
import com.google.protobuf.Descriptors.FieldDescriptor; //导入方法依赖的package包/类
/**
* Determines whether we skip processing of the field if it is null. We usually skip null values
* in the JSON to treat them as default, but must actually process the null for {@link Value} and
* {@link NullValue} because it means their value must be set.
*/
private boolean mustSkipNull(FieldDescriptor field) {
if (field.isRepeated()) {
return true;
}
if (field.getJavaType() == JavaType.MESSAGE
&& field.getMessageType() == Value.getDescriptor()) {
return false;
}
if (field.getJavaType() == JavaType.ENUM && field.getEnumType() == NullValue.getDescriptor()) {
return false;
}
return true;
}