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


Java ProtocolMessageEnum类代码示例

本文整理汇总了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);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:25,代码来源:Protobuf2PojoHelp.java

示例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);
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:31,代码来源:RequestValidator.java

示例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");
  }
}
 
开发者ID:peter-edge,项目名称:smartystreets-java,代码行数:21,代码来源:AbstractSmartyStreetsApiHandler.java

示例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;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:33,代码来源:Protobuf2PojoHelp.java

示例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));
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:35,代码来源:RequestValidator.java

示例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");
  }
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:16,代码来源:MessageAdapter.java

示例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());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:9,代码来源:Marshallers.java

示例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();
  }
}
 
开发者ID:google,项目名称:openrtb,代码行数:17,代码来源:OpenRtbJsonUtils.java

示例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;
    }
  }
}
 
开发者ID:matttproud,项目名称:groningen,代码行数:33,代码来源:GroningenConfigParamsModule.java

示例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;
    }
  }
}
 
开发者ID:matttproud,项目名称:groningen,代码行数:36,代码来源:GroningenConfigParamsModule.java

示例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;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:9,代码来源:RequestValidator.java

示例12: getErrorCode

import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
private ProtocolMessageEnum getErrorCode() {
    return errorCode;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:4,代码来源:RequestValidator.java

示例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;
}
 
开发者ID:boalang,项目名称:compiler,代码行数:7,代码来源:BoaProtoMap.java

示例14: getEnumClass

import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Class<? extends ProtocolMessageEnum> getEnumClass() {
	return boa.types.Ast.Comment.CommentKind.class;
}
 
开发者ID:boalang,项目名称:compiler,代码行数:6,代码来源:CommentKindProtoMap.java

示例15: getEnumClass

import com.google.protobuf.ProtocolMessageEnum; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Class<? extends ProtocolMessageEnum> getEnumClass() {
	return boa.types.Ast.Expression.ExpressionKind.class;
}
 
开发者ID:boalang,项目名称:compiler,代码行数:6,代码来源:ExpressionKindProtoMap.java


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