com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass Java Examples

The following examples show how to use com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtobufUtils.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
public static MessageType getMessageType(Method method) {
    Class<?>[] types = method.getParameterTypes();
    Class returnType = method.getReturnType();
    if (types.length < 0) {
        throw new IllegalArgumentException("invalid rpc method params");
    }

    if (types.length != 1) {
        return MessageType.POJO;
    }

    Class<?> inputType = types[0];
    if (Message.class.isAssignableFrom(inputType)
            && Message.class.isAssignableFrom(returnType)) {
        return MessageType.PROTOBUF;
    }

    ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class);
    if (protobufClass != null) {
        return MessageType.JPROTOBUF;
    }

    Field[] fields = inputType.getDeclaredFields();
    for (Field field : fields) {
        Protobuf protobuf = field.getAnnotation(Protobuf.class);
        if (protobuf != null) {
            return MessageType.JPROTOBUF;
        }
    }

    return MessageType.POJO;
}
 
Example #2
Source File: ProtobufProxyUtils.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch field infos.
 *
 * @return the list
 */
public static List<FieldInfo> fetchFieldInfos(Class cls, boolean ignoreNoAnnotation) {
    // if set ProtobufClass annotation
    Annotation annotation = cls.getAnnotation(ProtobufClass.class);

    Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
    boolean isZipZap = false;
    if (zipZap != null) {
        isZipZap = true;
    }

    boolean typeDefined = false;
    List<Field> fields = null;
    if (annotation == null) {
        fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
        if (fields.isEmpty() && ignoreNoAnnotation) {
            throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
                    + Protobuf.class.getName() + " at class " + cls.getName());
        }
    } else {
        typeDefined = true;

        fields = FieldUtils.findMatchedFields(cls, null);
    }

    List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
    return fieldInfos;
}
 
Example #3
Source File: CodeGenerator.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch field infos.
 *
 * @return the list
 */
protected List<FieldInfo> fetchFieldInfos() {
    // if set ProtobufClass annotation
    Annotation annotation = cls.getAnnotation(ProtobufClass.class);
    
    Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
    boolean isZipZap = false;
    if (zipZap != null) {
        isZipZap = true;
    }
    
    boolean typeDefined = false;
    List<Field> fields = null;
    if (annotation == null) {
        fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
        if (fields.isEmpty()) {
            throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
                    + Protobuf.class.getName() + " at class " + cls.getName());
        }
    } else {
        typeDefined = true;
        
        fields = FieldUtils.findMatchedFields(cls, null);
    }
    
    List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
    return fieldInfos;
}