Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataize returns u8 array #2444

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eo-runtime/src/main/rust/eo_env/src/eo_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'local> EOEnv<'_> {
}
}

pub fn dataize(&mut self, v: u32) -> Option<Vec<i8>> {
pub fn dataize(&mut self, v: u32) -> Option<Vec<u8>> {
let java_array = JByteArray::from(
self.java_env
.call_method(
Expand All @@ -114,6 +114,7 @@ impl<'local> EOEnv<'_> {
if self.java_env.get_byte_array_region(&java_array, 0, &mut bytes[0..]).is_err() {
return None;
}
return Some(bytes);
let unsigned = unsafe { &*(&bytes[0..] as *const _ as *const [u8]) };
return Some(unsigned.to_vec());
}
}
9 changes: 3 additions & 6 deletions eo-runtime/src/test/eo/org/eolang/rust-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@

pub fn foo(env: &mut EOEnv) -> EO {
let a = env.find("^.a") as u32;
let b = env.find("^.b") as u32;
let bytes_a = env.dataize(a).unwrap();
let mut arr_a = unsafe { &*(&bytes_a[0..] as *const _ as *const [u8]) };
let a = bytes_a.as_slice().read_i64::<BigEndian>().unwrap();

let b = env.find("^.b") as u32;
let bytes_b = env.dataize(b).unwrap();
let mut arr_b = unsafe { &*(&bytes_b[0..] as *const _ as *const [u8]) };

let a = arr_a.read_i64::<BigEndian>().unwrap();
let b = arr_b.read_i64::<BigEndian>().unwrap();
let b = bytes_b.as_slice().read_i64::<BigEndian>().unwrap();
println!("sum 5 + 10 = {}", a + b);

EOInt(a + b)
Expand Down
Loading