musikr: reformat
This commit is contained in:
parent
f3f349847a
commit
42dfe4edcc
5 changed files with 36 additions and 47 deletions
|
@ -13,10 +13,7 @@ impl<'local, 'a> JInputStream<'local, 'a> {
|
||||||
env: &'a mut JNIEnv<'local>,
|
env: &'a mut JNIEnv<'local>,
|
||||||
input: JObject<'local>,
|
input: JObject<'local>,
|
||||||
) -> Result<Self, jni::errors::Error> {
|
) -> Result<Self, jni::errors::Error> {
|
||||||
Ok(JInputStream {
|
Ok(JInputStream { env, input })
|
||||||
env,
|
|
||||||
input,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@ use jni::objects::{JClass, JObject};
|
||||||
use jni::sys::jstring;
|
use jni::sys::jstring;
|
||||||
use jni::JNIEnv;
|
use jni::JNIEnv;
|
||||||
|
|
||||||
mod taglib;
|
|
||||||
mod jni_stream;
|
mod jni_stream;
|
||||||
|
mod taglib;
|
||||||
|
|
||||||
pub use taglib::*;
|
|
||||||
use jni_stream::JInputStream;
|
use jni_stream::JInputStream;
|
||||||
|
pub use taglib::*;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
||||||
|
@ -19,7 +19,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let error = format!("Failed to create input stream: {}", e);
|
let error = format!("Failed to create input stream: {}", e);
|
||||||
let error_str = env.new_string(error).expect("Couldn't create error string!");
|
let error_str = env
|
||||||
|
.new_string(error)
|
||||||
|
.expect("Couldn't create error string!");
|
||||||
return error_str.into_raw();
|
return error_str.into_raw();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -29,7 +31,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
|
||||||
Some(file_ref) => file_ref,
|
Some(file_ref) => file_ref,
|
||||||
None => {
|
None => {
|
||||||
let error = "Failed to create File";
|
let error = "Failed to create File";
|
||||||
let error_str = env.new_string(error).expect("Couldn't create error string!");
|
let error_str = env
|
||||||
|
.new_string(error)
|
||||||
|
.expect("Couldn't create error string!");
|
||||||
return error_str.into_raw();
|
return error_str.into_raw();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[cxx::bridge]
|
#[cxx::bridge]
|
||||||
pub(crate) mod bindings {
|
pub(crate) mod bindings {
|
||||||
|
@ -395,8 +395,8 @@ impl ToString for bindings::TString {
|
||||||
// - This C-string is copied to a rust string before TagString is destroyed.
|
// - This C-string is copied to a rust string before TagString is destroyed.
|
||||||
CStr::from_ptr(c_str)
|
CStr::from_ptr(c_str)
|
||||||
}
|
}
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,33 +28,21 @@ pub extern "C" fn rust_stream_name(stream: *mut c_void) -> *const c_char {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_stream_read(
|
pub extern "C" fn rust_stream_read(stream: *mut c_void, buffer: *mut u8, length: usize) -> usize {
|
||||||
stream: *mut c_void,
|
|
||||||
buffer: *mut u8,
|
|
||||||
length: usize,
|
|
||||||
) -> usize {
|
|
||||||
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
||||||
let buffer = unsafe { std::slice::from_raw_parts_mut(buffer, length) };
|
let buffer = unsafe { std::slice::from_raw_parts_mut(buffer, length) };
|
||||||
stream.0.read(buffer).unwrap_or(0)
|
stream.0.read(buffer).unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_stream_write(
|
pub extern "C" fn rust_stream_write(stream: *mut c_void, data: *const u8, length: usize) {
|
||||||
stream: *mut c_void,
|
|
||||||
data: *const u8,
|
|
||||||
length: usize,
|
|
||||||
) {
|
|
||||||
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
||||||
let data = unsafe { std::slice::from_raw_parts(data, length) };
|
let data = unsafe { std::slice::from_raw_parts(data, length) };
|
||||||
stream.0.write_all(data).unwrap();
|
stream.0.write_all(data).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn rust_stream_seek(
|
pub extern "C" fn rust_stream_seek(stream: *mut c_void, offset: i64, whence: i32) {
|
||||||
stream: *mut c_void,
|
|
||||||
offset: i64,
|
|
||||||
whence: i32,
|
|
||||||
) {
|
|
||||||
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
|
||||||
let pos = match whence {
|
let pos = match whence {
|
||||||
0 => SeekFrom::Start(offset as u64),
|
0 => SeekFrom::Start(offset as u64),
|
||||||
|
|
Loading…
Reference in a new issue