class ProtobufUtils {

    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;
    }

}