本文整理汇总了Java中com.google.protobuf.ProtocolMessageEnum类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolMessageEnum类的具体用法?Java ProtocolMessageEnum怎么用?Java ProtocolMessageEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolMessageEnum类属于com.google.protobuf包,在下文中一共展示了ProtocolMessageEnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPojoFieldValue
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
public static final void setPojoFieldValue(Object pojo, String setter, Object protobufValue,
ProtobufAttribute protobufAttribute, Field field)
throws InstantiationException, IllegalAccessException, JException {
Class<? extends Object> argClazz = null;
if (protobufValue instanceof List) {
final ArrayList<Object> newCollectionValues = new ArrayList<>();
newCollectionValues.addAll((Collection<?>) protobufValue);
protobufValue = newCollectionValues;
argClazz = ArrayList.class;
} else if (protobufValue instanceof Map) {
final Map<Object, Object> newMapValues = new HashMap<>();
newMapValues.putAll((Map<?, ?>) protobufValue);
protobufValue = newMapValues;
argClazz = Map.class;
} else if (protobufValue instanceof ProtocolMessageEnum) {
Class<?> fieldType = field.getType();
protobufValue = JReflectionUtils.runStaticMethod(fieldType, "forNumber",
((ProtocolMessageEnum) protobufValue).getNumber());
argClazz = field.getType();
} else {
protobufValue.getClass();
}
JReflectionUtils.runSetter(pojo, setter, protobufValue, argClazz);
}
示例2: checkSupported
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Checks whether this request is supported, forms the proper {@link Error error}
* and packs it into an exception.
*
* @param request the request to check for support
* @return an instance of exception or {@code Optional.absent()} if the request is supported.
*/
private Optional<InvalidRequestException> checkSupported(M request) {
final Optional<RequestNotSupported<M>> supported = isSupported(request);
if (!supported.isPresent()) {
return Optional.absent();
}
final RequestNotSupported<M> result = supported.get();
final ProtocolMessageEnum unsupportedErrorCode = result.getErrorCode();
final String errorMessage = result.getErrorMessage();
final String errorTypeName = unsupportedErrorCode.getDescriptorForType()
.getFullName();
final Error.Builder errorBuilder = Error.newBuilder()
.setType(errorTypeName)
.setCode(unsupportedErrorCode.getNumber())
.setMessage(errorMessage);
final Error error = errorBuilder.build();
final InvalidRequestException exception = result.createException(errorMessage,
request,
error);
return Optional.of(exception);
}
示例3: putField
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
private static <T> void putField(Message.Builder builder, Class<T> fieldClass, int fieldNumber,
JSONObject jsonObject, String key, boolean required, Function<String, T> handler) {
if (jsonObject.containsKey(key)) {
String value = (String) jsonObject.get(key);
if (value != null && !value.isEmpty()) {
Object object = handler.apply(value);
if (object instanceof ProtocolMessageEnum) {
Descriptors.EnumDescriptor enumDescriptor = builder.getDescriptorForType().findFieldByNumber(fieldNumber).getEnumType();
checkNotNull(enumDescriptor, "No enumDescriptor for " + fieldClass.getSimpleName());
Descriptors.EnumValueDescriptor enumValueDescriptor = enumDescriptor.findValueByNumber(((ProtocolMessageEnum) object).getNumber());
checkNotNull(enumValueDescriptor, "No enumValueDescriptor for " + ((ProtocolMessageEnum) object).getNumber());
object = enumValueDescriptor;
}
builder.setField(getFieldDesciptor(builder, fieldNumber), object);
}
} else if (required) {
throw new IllegalArgumentException("Required field " + key + " not set");
}
}
示例4: getProtobufFieldValue
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static final Object getProtobufFieldValue(Message protoBuf,
ProtobufAttribute protobufAttribute, Field field)
throws JException, InstantiationException, IllegalAccessException {
final String getter = ProtobufSerializerUtils.getProtobufGetter(protobufAttribute, field);
// This is used to determine if the Protobuf message has populated this value
Boolean isCollection = Boolean.FALSE;
if (Collection.class.isAssignableFrom(field.getType())) {
isCollection = Boolean.TRUE;
}
// Go ahead and fun the getter
Object protobufValue = JReflectionUtils.runMethod(protoBuf, getter, (Object[]) null);
if (isCollection && ((Collection) protobufValue).isEmpty()) {
return null;
}
// If the field itself is a ProtbufEntity, serialize that!
if (protobufValue instanceof Message
&& ProtobufSerializerUtils.isProtbufEntity(field.getType())) {
protobufValue = serializeFromProtobufEntity((Message) protobufValue, field.getType());
}
if (protobufValue instanceof Collection) {
protobufValue = convertCollectionFromProtobufs(field, (Collection<?>) protobufValue);
if (((Collection) protobufValue).isEmpty()) {
return null;
}
}
if (protobufValue instanceof ProtocolMessageEnum) {
protobufValue = JReflectionUtils.runStaticMethod(field.getType(), "forNumber",
((ProtocolMessageEnum) protobufValue).getNumber());
}
return protobufValue;
}
示例5: validateMessage
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Checks whether the {@code Message} of the given request conforms the constraints
*
* @param request the request message to validate.
* @return an instance of exception,
* or {@code Optional.absent()} if the request message is valid.
*/
private Optional<InvalidRequestException> validateMessage(M request) {
final List<ConstraintViolation> violations = MessageValidator.newInstance()
.validate(request);
if (violations.isEmpty()) {
return Optional.absent();
}
final ValidationError validationError =
ValidationError.newBuilder()
.addAllConstraintViolation(violations)
.build();
final ProtocolMessageEnum errorCode = getInvalidMessageErrorCode();
final String typeName = errorCode.getDescriptorForType()
.getFullName();
final String errorTextTemplate = getErrorText(request);
final String errorText = format("%s %s",
errorTextTemplate,
toText(violations));
final Error.Builder errorBuilder = Error.newBuilder()
.setType(typeName)
.setCode(errorCode.getNumber())
.setValidationError(validationError)
.setMessage(errorText);
final Error error = errorBuilder.build();
return Optional.of(onInvalidMessage(formatExceptionMessage(request), request, error));
}
示例6: getEnumValue
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
public static <T> EnumValueDescriptor getEnumValue(final FieldDescriptor key, final T value) {
MessageAdapter.verifyArgument(key.getJavaType() == JavaType.ENUM, "Not enum type!");
if (value instanceof EnumValueDescriptor) {
return getEnumValue(key, (EnumValueDescriptor) value);
} else if (value instanceof ProtocolMessageEnum) {
return getEnumValue(key, (ProtocolMessageEnum) value);
} else if (value instanceof String) {
return getEnumValue(key, (String) value);
} else if (value instanceof Integer) {
return getEnumValue(key, (Integer) value);
} else {
throw new IllegalArgumentException("value is not of the allowed type");
}
}
示例7: isProtoEnum
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
private boolean isProtoEnum(DeclaredType type) {
return env.getTypeUtils()
.isSubtype(
type,
env.getElementUtils()
.getTypeElement(ProtocolMessageEnum.class.getCanonicalName())
.asType());
}
示例8: writeEnums
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Writes a enum array if not empty.
*
* @see #writeEnum(ProtocolMessageEnum, JsonGenerator)
*/
public static void writeEnums(
String fieldName, List<? extends ProtocolMessageEnum> enums, JsonGenerator gen)
throws IOException {
if (!enums.isEmpty()) {
gen.writeArrayFieldStart(fieldName);
for (ProtocolMessageEnum e : enums) {
writeEnum(e, gen);
}
gen.writeEndArray();
}
}
示例9: nailConfigToScope
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Nails all the per-pipeline configuration parameters to a given Guice scope.
*
* @param config Configuration parameters to be fixed for the pipeline run duration.
* @param scope Guice scope used to fix the parameters.
*/
public static void nailConfigToScope(GroningenConfig config, BlockScope scope) {
scope.seed(GroningenConfig.class, config);
for (FieldDescriptor fd : GroningenParams.getDescriptor().getFields()) {
switch (fd.getJavaType()) {
case ENUM:
nailConfigParamToScope(ProtocolMessageEnum.class, fd, config, scope);
break;
case INT:
nailConfigParamToScope(Integer.class, fd, config, scope);
break;
case LONG:
nailConfigParamToScope(Long.class, fd, config, scope);
break;
case DOUBLE:
nailConfigParamToScope(Double.class, fd, config, scope);
break;
case STRING:
nailConfigParamToScope(String.class, fd, config, scope);
break;
default:
log.warning(String.format("unrecognized field descriptor type: %s.", fd.getJavaType()));
break;
}
}
}
示例10: configure
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* GroningenConfigParamsModule binds pipelineIterationScope to a specific SimpleScope
* implementation and binds all the configuration parameters (fields annotated with
* @NamedConfigParam) to a SimpleScope.seededKeyProvider(), which prevents them being
* injected outside of the scope (see bindConfigParamToSeededKeyProvider()).
*/
@Override
protected void configure() {
bind(GroningenConfig.class)
.toProvider(SimpleScope.<GroningenConfig>seededKeyProvider())
.in(PipelineIterationScoped.class);
for (FieldDescriptor fd : GroningenParams.getDescriptor().getFields()) {
switch (fd.getJavaType()) {
case ENUM:
bindConfigParamToSeededKeyProvider(ProtocolMessageEnum.class, fd);
break;
case INT:
bindConfigParamToSeededKeyProvider(Integer.class, fd);
break;
case LONG:
bindConfigParamToSeededKeyProvider(Long.class, fd);
break;
case DOUBLE:
bindConfigParamToSeededKeyProvider(Double.class, fd);
break;
case STRING:
bindConfigParamToSeededKeyProvider(String.class, fd);
break;
default:
log.warning(String.format("unrecognized field descriptor type: %s.", fd.getJavaType()));
break;
}
}
}
示例11: RequestNotSupported
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Creates an instance of {@code RequestNotSupported} value object
* by the specific error code and the error message.
*/
RequestNotSupported(ProtocolMessageEnum errorCode, String errorMessage) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
示例12: getErrorCode
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
private ProtocolMessageEnum getErrorCode() {
return errorCode;
}
示例13: getEnumClass
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/**
* Returns the {@link Class} representing the Java enumeration of this type.
*/
protected Class<? extends ProtocolMessageEnum> getEnumClass() {
return null;
}
示例14: getEnumClass
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Class<? extends ProtocolMessageEnum> getEnumClass() {
return boa.types.Ast.Comment.CommentKind.class;
}
示例15: getEnumClass
import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Class<? extends ProtocolMessageEnum> getEnumClass() {
return boa.types.Ast.Expression.ExpressionKind.class;
}