本文整理汇总了Java中com.google.protobuf.Descriptors.EnumDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java Descriptors.EnumDescriptor方法的具体用法?Java Descriptors.EnumDescriptor怎么用?Java Descriptors.EnumDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.Descriptors
的用法示例。
在下文中一共展示了Descriptors.EnumDescriptor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enumValueFor
import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
private static Object enumValueFor(FieldDescriptor field, Random random) {
final Descriptors.EnumDescriptor descriptor = field.getEnumType();
final List<Descriptors.EnumValueDescriptor> enumValues = descriptor.getValues();
if (enumValues.isEmpty()) {
return null;
}
// Value under index 0 is usually used to store `undefined` option
// Use values with indexes from 1 to n
final int index = random.nextInt(enumValues.size() - 1) + 1;
final Descriptors.EnumValueDescriptor enumValue = descriptor.findValueByNumber(index);
return enumValue;
}
示例2: handlePrimitive
import com.google.protobuf.Descriptors; //导入方法依赖的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: massageValueToJavaValue
import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
protected Object massageValueToJavaValue(Object value, Class clz){
if(clz.equals(Integer.class) || clz.equals(Long.class) || clz.equals(Float.class) || clz.equals(Double.class) ||clz.equals(Boolean.class) ||
clz.equals(int.class) || clz.equals(long.class) || clz.equals(float.class) || clz.equals(double.class) || clz.equals(boolean.class)){
// 判断clz时,如果是boolean, 估计是直接返回的boolean type,因此同时包含类型的判断
return value;
}else if(clz.equals(String.class)){
if(value instanceof String){
return value;
}else if(value instanceof Descriptors.EnumDescriptor){
return ((Descriptors.EnumDescriptor)value).getName();
}else if(value instanceof Descriptors.EnumValueDescriptor){
return ((Descriptors.EnumValueDescriptor) value).getName();
}
}else if(clz.isEnum()){
try{
if(value instanceof String){
return Enum.valueOf(clz, (String) value);
}else if(value instanceof Descriptors.EnumValueDescriptor){
return Enum.valueOf(clz, ((Descriptors.EnumValueDescriptor) value).getName() );
}
}catch (Exception e){
return null;
}
}else if(clz.equals(BigDecimal.class)){
return new BigDecimal((double)value);
}else if(clz.equals(LocalDateTime.class)){
if(!"".equals(value)) {
try {
return LocalDateTime.parse((String) value, dateTimeFormatter);
} catch (Exception ex) {
return LocalDateTime.parse((String) value);
}
}
}else if(clz.equals(LocalDate.class)){
if(!"".equals(value)){
return LocalDate.parse((String) value);
}
}else if(clz.equals(LocalTime.class)){
if(!"".equals(value)){
return LocalTime.parse((String) value);
}
}else if(clz.equals(byte[].class)){
return ((ByteString) value).toByteArray();
}
return null;
}
示例4: getDescriptorForType
import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public final Descriptors.EnumDescriptor getDescriptorForType() {
return getDescriptor();
}
示例5: getDescriptor
import com.google.protobuf.Descriptors; //导入方法依赖的package包/类
public static final Descriptors.EnumDescriptor getDescriptor() {
return (Descriptors.EnumDescriptor)PushSMPMessageProtos.PushSMPMessageContent.GroupContext.getDescriptor().getEnumTypes().get(0);
}