本文整理匯總了Java中com.google.protobuf.Descriptors.EnumValueDescriptor類的典型用法代碼示例。如果您正苦於以下問題:Java EnumValueDescriptor類的具體用法?Java EnumValueDescriptor怎麽用?Java EnumValueDescriptor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EnumValueDescriptor類屬於com.google.protobuf.Descriptors包,在下文中一共展示了EnumValueDescriptor類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: singularFromReflectionType
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
/**
* Like {@link #fromReflectionType(Object)}, but if the type is a repeated
* type, this converts a single element.
*/
private Object singularFromReflectionType(final Object value) {
switch (descriptor.getJavaType()) {
case MESSAGE:
if (type.isInstance(value)) {
return value;
} else {
// It seems the copy of the embedded message stored inside the
// extended message is not of the exact type the user was
// expecting. This can happen if a user defines a
// GeneratedExtension manually and gives it a different type.
// This should not happen in normal use. But, to be nice, we'll
// copy the message to whatever type the caller was expecting.
return messageDefaultInstance.newBuilderForType()
.mergeFrom((Message) value).build();
}
case ENUM:
return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
default:
return value;
}
}
示例2: parseEnum
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的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;
}
示例3: parseEnum
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的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;
}
示例4: ensureSingularEnumValueDescriptor
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
/** Verifies that the value is EnumValueDescriptor and matches Enum Type. */
private void ensureSingularEnumValueDescriptor(
FieldDescriptor field, Object value) {
if (value == null) {
throw new NullPointerException();
}
if (!(value instanceof EnumValueDescriptor)) {
throw new IllegalArgumentException(
"DynamicMessage should use EnumValueDescriptor to set Enum Value.");
}
// TODO(xiaofeng): Re-enable this check after Orgstore is fixed to not
// set incorrect EnumValueDescriptors.
// EnumDescriptor fieldType = field.getEnumType();
// EnumDescriptor fieldValueType = ((EnumValueDescriptor) value).getType();
// if (fieldType != fieldValueType) {
// throw new IllegalArgumentException(String.format(
// "EnumDescriptor %s of field doesn't match EnumDescriptor %s of field value",
// fieldType.getFullName(), fieldValueType.getFullName()));
// }
}
示例5: GeneratedExtension
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
Class singularType,
Message messageDefaultInstance,
ExtensionType extensionType) {
if (Message.class.isAssignableFrom(singularType) &&
!singularType.isInstance(messageDefaultInstance)) {
throw new IllegalArgumentException(
"Bad messageDefaultInstance for " + singularType.getName());
}
this.descriptorRetriever = descriptorRetriever;
this.singularType = singularType;
this.messageDefaultInstance = messageDefaultInstance;
if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
this.enumValueOf = getMethodOrDie(singularType, "valueOf",
EnumValueDescriptor.class);
this.enumGetValueDescriptor =
getMethodOrDie(singularType, "getValueDescriptor");
} else {
this.enumValueOf = null;
this.enumGetValueDescriptor = null;
}
this.extensionType = extensionType;
}
示例6: singularFromReflectionType
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
/**
* Like {@link #fromReflectionType(Object)}, but if the type is a repeated
* type, this converts a single element.
*/
// @Override
protected Object singularFromReflectionType(final Object value) {
FieldDescriptor descriptor = getDescriptor();
switch (descriptor.getJavaType()) {
case MESSAGE:
if (singularType.isInstance(value)) {
return value;
} else {
return messageDefaultInstance.newBuilderForType()
.mergeFrom((Message) value).build();
}
case ENUM:
return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
default:
return value;
}
}
示例7: SingularEnumFieldAccessor
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
SingularEnumFieldAccessor(
final FieldDescriptor descriptor, final String camelCaseName,
final Class<? extends GeneratedMessage> messageClass,
final Class<? extends Builder> builderClass,
final String containingOneofCamelCaseName) {
super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);
enumDescriptor = descriptor.getEnumType();
valueOfMethod = getMethodOrDie(type, "valueOf",
EnumValueDescriptor.class);
getValueDescriptorMethod =
getMethodOrDie(type, "getValueDescriptor");
supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
if (supportUnknownEnumValue) {
getValueMethod =
getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
getValueMethodBuilder =
getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
setValueMethod =
getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
}
}
示例8: RepeatedEnumFieldAccessor
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
RepeatedEnumFieldAccessor(
final FieldDescriptor descriptor, final String camelCaseName,
final Class<? extends GeneratedMessage> messageClass,
final Class<? extends Builder> builderClass) {
super(descriptor, camelCaseName, messageClass, builderClass);
enumDescriptor = descriptor.getEnumType();
valueOfMethod = getMethodOrDie(type, "valueOf",
EnumValueDescriptor.class);
getValueDescriptorMethod =
getMethodOrDie(type, "getValueDescriptor");
supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
if (supportUnknownEnumValue) {
getRepeatedValueMethod =
getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class);
getRepeatedValueMethodBuilder =
getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class);
setRepeatedValueMethod =
getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class);
addRepeatedValueMethod =
getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
}
}
示例9: singularFromReflectionType
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
/**
* Like {@link #fromReflectionType(Object)}, but if the type is a repeated
* type, this converts a single element.
*/
@Override
protected Object singularFromReflectionType(final Object value) {
FieldDescriptor descriptor = getDescriptor();
switch (descriptor.getJavaType()) {
case MESSAGE:
if (singularType.isInstance(value)) {
return value;
} else {
return messageDefaultInstance.newBuilderForType()
.mergeFrom((Message) value).build();
}
case ENUM:
return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
default:
return value;
}
}
示例10: GeneratedExtension
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
private GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever,
Class singularType,
Message messageDefaultInstance) {
if (Message.class.isAssignableFrom(singularType) &&
!singularType.isInstance(messageDefaultInstance)) {
throw new IllegalArgumentException(
"Bad messageDefaultInstance for " + singularType.getName());
}
this.descriptorRetriever = descriptorRetriever;
this.singularType = singularType;
this.messageDefaultInstance = messageDefaultInstance;
if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) {
this.enumValueOf = getMethodOrDie(singularType, "valueOf",
EnumValueDescriptor.class);
this.enumGetValueDescriptor =
getMethodOrDie(singularType, "getValueDescriptor");
} else {
this.enumValueOf = null;
this.enumGetValueDescriptor = null;
}
}
示例11: singularFromReflectionType
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
/**
* Like {@link #fromReflectionType(Object)}, but if the type is a repeated
* type, this converts a single element.
*/
private Object singularFromReflectionType(final Object value) {
FieldDescriptor descriptor = getDescriptor();
switch (descriptor.getJavaType()) {
case MESSAGE:
if (singularType.isInstance(value)) {
return value;
} else {
// It seems the copy of the embedded message stored inside the
// extended message is not of the exact type the user was
// expecting. This can happen if a user defines a
// GeneratedExtension manually and gives it a different type.
// This should not happen in normal use. But, to be nice, we'll
// copy the message to whatever type the caller was expecting.
return messageDefaultInstance.newBuilderForType()
.mergeFrom((Message) value).build();
}
case ENUM:
return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value);
default:
return value;
}
}
示例12: toMap
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
private static Object toMap(FieldDescriptor descr, Object value) {
if (value == null) {
return null;
}
final Object result;
switch(descr.getJavaType()) {
case MESSAGE:
result = toMap((Message )value);
break;
case ENUM:
result = ((EnumValueDescriptor )value).getName();
break;
default:
result = value;
break;
}
return result;
}
示例13: GeneratedExtension
import com.google.protobuf.Descriptors.EnumValueDescriptor; //導入依賴的package包/類
GeneratedExtension (ExtensionDescriptorRetriever descriptorRetriever,
Class singularType,
Message messageDefaultInstance,
ExtensionType extensionType) {
if (Message.class.isAssignableFrom (singularType)
&& !singularType.isInstance (messageDefaultInstance)) {
throw new IllegalArgumentException (
"Bad messageDefaultInstance for " + singularType.getName ());
}
this.descriptorRetriever = descriptorRetriever;
this.singularType = singularType;
this.messageDefaultInstance = messageDefaultInstance;
if (ProtocolMessageEnum.class.isAssignableFrom (singularType)) {
this.enumValueOf = getMethodOrDie (singularType, "valueOf",
EnumValueDescriptor.class);
this.enumGetValueDescriptor
= getMethodOrDie (singularType, "getValueDescriptor");
} else {
this.enumValueOf = null;
this.enumGetValueDescriptor = null;
}
this.extensionType = extensionType;
}