Java 类com.google.protobuf.Internal 实例源码

项目:Okra-Ax    文件:AxAnyUtil.java   
public static <T extends Message> T unpack(AxAnyProto.AxAny any, Class<T> message) throws InvalidProtocolBufferException {
    T var1 = Internal.getDefaultInstance(message);
    if (!is(any, var1)) {
        throw new InvalidProtocolBufferException("Type of the Any message does not match the given class.");
    }
    T result = (T) var1.getParserForType()
            .parseFrom(any.getValue());
    return result;
}
项目:core-java    文件:ReferenceValidator.java   
ReferenceValidator(Enricher enricher,
        Class<? extends Message> eventClass,
        Class<? extends Message> enrichmentClass) {
    this.enricher = enricher;
    this.eventDescriptor = Internal.getDefaultInstance(eventClass)
                                   .getDescriptorForType();
    this.enrichmentDescriptor = Internal.getDefaultInstance(enrichmentClass)
                                        .getDescriptorForType();
}
项目:core-java    文件:MessageEnrichment.java   
@Override
public T apply(S eventMsg, C context) {
    checkNotNull(eventMsg);
    checkNotNull(context);
    ensureActive();
    verifyOwnState();

    final T defaultTarget = Internal.getDefaultInstance(getEnrichmentClass());
    final Message.Builder builder = defaultTarget.toBuilder();
    setFields(builder, eventMsg, context);
    @SuppressWarnings("unchecked") // types are checked during the initialization and validation
    final T result = (T) builder.build();
    return result;
}
项目:jprotobuf    文件:MapFieldLite.java   
/**
 * Calculate hash code for object.
 *
 * @param a the a
 * @return the int
 */
private static int calculateHashCodeForObject(Object a) {
    if (a instanceof byte[]) {
        return Internal.hashCode((byte[]) a);
    }
    // Enums should be stored as integers internally.
    if (a instanceof EnumLite) {
        throw new UnsupportedOperationException();
    }
    return a.hashCode();
}
项目:bazel    文件:FieldMaskUtil.java   
/**
 * Constructs a FieldMask from the passed field numbers.
 *
 * @throws IllegalArgumentException if any of the fields are invalid for the message.
 */
public static FieldMask fromFieldNumbers(
    Class<? extends Message> type, Iterable<Integer> fieldNumbers) {
  Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();

  FieldMask.Builder builder = FieldMask.newBuilder();
  for (Integer fieldNumber : fieldNumbers) {
    FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber);
    checkArgument(
        field != null,
        String.format("%s is not a valid field number for %s.", fieldNumber, type));
    builder.addPaths(field.getName());
  }
  return builder.build();
}
项目:commelina    文件:MatchingJoinMatch.java   
@Override
public boolean match(Internal.EnumLite forward, Internal.EnumLite opcode) {
    return DOMAIN.MATCHING_VALUE == forward.getNumber() && REQUEST_OPCODE.JOIN_MATCH_QUENE.equals(opcode);
}
项目:commelina    文件:MatchingWaitForMatchStatus.java   
@Override
public boolean match(Internal.EnumLite forward, Internal.EnumLite opcode) {
    return forward.getNumber() == DOMAIN.MATCHING_VALUE
            && NOTIFY_OPCODE.NOTIFY_MATCH_SUCCESS.getNumber() == opcode.getNumber();
}
项目:commelina    文件:MatchingWaitForJoinRoom.java   
@Override
public boolean match(Internal.EnumLite forward, Internal.EnumLite opcode) {
    return forward.getNumber() == DOMAIN.MATCHING_VALUE && opcode.getNumber() == REQUEST_OPCODE.JOIN_MATCH_QUENE_VALUE;
}
项目:commelina    文件:ResponseBodyMessage.java   
public static ResponseBodyMessage<String> error(Internal.EnumLite code) {
    Preconditions.checkArgument(code.getNumber() > 0);
    return success(code, null);
}
项目:commelina    文件:ResponseBodyMessage.java   
public static <T extends Serializable> ResponseBodyMessage<T> success(Internal.EnumLite code, T data) {
    return new ResponseBodyMessage<>(code.getNumber(), data);
}
项目:commelina    文件:ResponseBodyEntity.java   
public static ResponseBodyEntity<String> error(Internal.EnumLite code) {
    return success(code, null);
}
项目:commelina    文件:ResponseBodyEntity.java   
public static <T> ResponseBodyEntity<T> success(Internal.EnumLite code, T data) {
    return new ResponseBodyEntity<>(code.getNumber(), data);
}
项目:commelina    文件:ServiceEmptyMessage.java   
private ServiceEmptyMessage(Internal.EnumLite errorCode) {
    this.errorCode = errorCode;
}
项目:commelina    文件:ServiceEmptyMessage.java   
public static ServiceEmptyMessage newMessage(Internal.EnumLite errorCode) {
    return newMessage(errorCode);
}
项目:commelina    文件:ServiceEmptyMessage.java   
public Internal.EnumLite getErrorCode() {
    return errorCode;
}
项目:commelina    文件:ServiceMessage.java   
private ServiceMessage(Internal.EnumLite errorCode, T data) {
    this.errorCode = errorCode;
    this.data = data;
}
项目:commelina    文件:ServiceMessage.java   
public static <T> ServiceMessage<T> newMessage(Internal.EnumLite errorCode, T t) {
    return new ServiceMessage<>(errorCode, t);
}
项目:commelina    文件:ServiceMessage.java   
public static <T> ServiceMessage<T> newMessage(Internal.EnumLite errorCode) {
    return newMessage(errorCode, null);
}
项目:commelina    文件:ServiceMessage.java   
public Internal.EnumLite getErrorCode() {
    return errorCode;
}
项目:Okra-Ax    文件:AxAnyUtil.java   
public static <T extends Message> boolean is(AxAnyProto.AxAny any, Class<T> clazz) {
    return is(any, Internal.getDefaultInstance(clazz));
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public static Internal.EnumLiteMap<Type> internalGetValueMap() {
    return internalValueMap;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public static Internal.EnumLiteMap<Flags> internalGetValueMap() {
    return internalValueMap;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public static Internal.EnumLiteMap<Type> internalGetValueMap() {
    return internalValueMap;
}
项目:jprotobuf    文件:CodedConstant.java   
/**
 * Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
 *
 * @param type The field's type.
 * @param value Object representing the field's value. Must be of the exact type which would be returned by
 *            {@link Message#getField(Descriptors.FieldDescriptor)} for this field.
 * @return the int
 */
public static int computeElementSizeNoTag(final WireFormat.FieldType type, final Object value) {
    switch (type) {
        // Note: Minor violation of 80-char limit rule here because this would
        // actually be harder to read if we wrapped the lines.
        case DOUBLE:
            return CodedOutputStream.computeDoubleSizeNoTag((Double) value);
        case FLOAT:
            return CodedOutputStream.computeFloatSizeNoTag((Float) value);
        case INT64:
            return CodedOutputStream.computeInt64SizeNoTag((Long) value);
        case UINT64:
            return CodedOutputStream.computeUInt64SizeNoTag((Long) value);
        case INT32:
            return CodedOutputStream.computeInt32SizeNoTag((Integer) value);
        case FIXED64:
            return CodedOutputStream.computeFixed64SizeNoTag((Long) value);
        case FIXED32:
            return CodedOutputStream.computeFixed32SizeNoTag((Integer) value);
        case BOOL:
            return CodedOutputStream.computeBoolSizeNoTag((Boolean) value);
        case STRING:
            return CodedOutputStream.computeStringSizeNoTag((String) value);
        case GROUP:
            return CodedOutputStream.computeGroupSizeNoTag((MessageLite) value);
        case BYTES:
            if (value instanceof ByteString) {
                return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
            } else {
                return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value);
            }
        case UINT32:
            return CodedOutputStream.computeUInt32SizeNoTag((Integer) value);
        case SFIXED32:
            return CodedOutputStream.computeSFixed32SizeNoTag((Integer) value);
        case SFIXED64:
            return CodedOutputStream.computeSFixed64SizeNoTag((Long) value);
        case SINT32:
            return CodedOutputStream.computeSInt32SizeNoTag((Integer) value);
        case SINT64:
            return CodedOutputStream.computeSInt64SizeNoTag((Long) value);

        case MESSAGE:
            if (value instanceof LazyField) {
                return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value);
            } else {
                return computeObjectSizeNoTag(value);
            }

        case ENUM:
            if (value instanceof Internal.EnumLite) {
                return CodedOutputStream.computeEnumSizeNoTag(((Internal.EnumLite) value).getNumber());
            } else {
                if (value instanceof EnumReadable) {
                    return CodedOutputStream.computeEnumSizeNoTag(((EnumReadable) value).value());
                } else if (value instanceof Enum) {
                    return CodedOutputStream.computeEnumSizeNoTag(((Enum) value).ordinal());
                }

                return CodedOutputStream.computeEnumSizeNoTag((Integer) value);
            }
    }

    throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
}
项目:protobuf-el    文件:DynamicMessage.java   
private static void verifySingleValue(final FieldDescriptor field, final Object value,
    final Class<? extends MessageOrBuilder> type) {
  if (value == null) {
    throw new NullPointerException();
  }

  boolean isValid = false;

  switch (field.getJavaType()) {
    case INT:
      isValid = value instanceof Integer;
      break;
    case LONG:
      isValid = value instanceof Long;
      break;
    case FLOAT:
      isValid = value instanceof Float;
      break;
    case DOUBLE:
      isValid = value instanceof Double;
      break;
    case BOOLEAN:
      isValid = value instanceof Boolean;
      break;
    case STRING:
      isValid = value instanceof String;
      break;
    case BYTE_STRING:
      isValid = value instanceof ByteString;
      break;
    case ENUM:
      if (value instanceof EnumValueDescriptor) {
        isValid = ((EnumValueDescriptor) value).getType() == field.getEnumType();
      } else if (value instanceof Internal.EnumLite) {
        isValid =
            field.getEnumType().findValueByNumber(((Internal.EnumLite) value).getNumber()) != null;
      } else if (value instanceof Number) {
        isValid = field.getEnumType().findValueByNumber(((Number) value).intValue()) != null;
      } else if (value instanceof String) {
        isValid = field.getEnumType().findValueByName((String) value) != null;
      }

      break;
    case MESSAGE:
      final Class<? extends MessageOrBuilder> expectedType =
      type == null ? Message.class : (Class<? extends MessageOrBuilder>) type;
      final Object resolvedValue =
          value instanceof LazyField ? ((LazyField) value).getValue() : value;
          isValid =
              expectedType.cast(resolvedValue).getDescriptorForType() == field.getMessageType();
          break;
  }

  if (!isValid) {
    // TODO(kenton): When chaining calls to setField(), it can be hard to
    // tell from the stack trace which exact call failed, since the whole
    // chain is considered one line of code. It would be nice to print
    // more information here, e.g. naming the field. We used to do that.
    // But we can't now that FieldSet doesn't use descriptors. Maybe this
    // isn't a big deal, though, since it would only really apply when using
    // reflection and generally people don't chain reflection setters.
    throw new IllegalArgumentException(
        "Wrong object type used with protocol message reflection.");
  }
}
项目:protobuf-el    文件:DynamicMessage.java   
private static Object getVerifiedSingleValue(final FieldDescriptor field, final Object value,
    final Class<? extends MessageOrBuilder> type) {
  if (value == null) {
    throw new NullPointerException();
  }

  switch (field.getJavaType()) {
    case INT:
      return Integer.class.cast(value);
    case LONG:
      return Long.class.cast(value);
    case FLOAT:
      return Float.class.cast(value);
    case DOUBLE:
      return Double.class.cast(value);
    case BOOLEAN:
      return Boolean.class.cast(value);
    case STRING:
      return String.class.cast(value);
    case BYTE_STRING:
      return ByteString.class.cast(value);
    case ENUM:
      if (value instanceof EnumValueDescriptor) {
        if (((EnumValueDescriptor) value).getType() == field.getEnumType()) {
          return value;
        }
      } else {
        EnumValueDescriptor enumValue = null;

        if (value instanceof Internal.EnumLite) {
          enumValue =
              field.getEnumType().findValueByNumber(((Internal.EnumLite) value).getNumber());
        } else if (value instanceof Number) {
          enumValue = field.getEnumType().findValueByNumber(((Number) value).intValue());
        } else if (value instanceof String) {
          enumValue = field.getEnumType().findValueByName((String) value);
        }

        if (enumValue != null) {
          return enumValue;
        }
      }

      break;
    case MESSAGE:
      final Class<? extends MessageOrBuilder> expectedType =
      type == null ? Message.class : (Class<? extends MessageOrBuilder>) type;
      final MessageOrBuilder resolvedValue =
          expectedType
          .cast(value instanceof LazyField ? ((LazyField) value).getValue() : value);

      if (resolvedValue.getDescriptorForType() == field.getMessageType()) {
        return resolvedValue;
      }

      break;
  }

  throw new IllegalArgumentException("Wrong object type used with protocol message reflection.");
}
项目:bazel    文件:FieldMaskUtil.java   
/**
 * Checks whether paths in a given fields mask are valid.
 */
public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) {
  Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();

  return isValid(descriptor, fieldMask);
}
项目:bazel    文件:FieldMaskUtil.java   
/**
 * Checks whether a given field path is valid.
 */
public static boolean isValid(Class<? extends Message> type, String path) {
  Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();

  return isValid(descriptor, path);
}
项目:commelina    文件:Identify.java   
/**
 * 判断是否是对应 onCreatedAsk
 *
 * @param forward
 * @param opcode
 * @return
 */
boolean match(Internal.EnumLite forward, Internal.EnumLite opcode);