Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move current work to new rust API and add rust wrappers for unit_inte…
…rval
- Loading branch information
1 parent
0b87dde
commit b6a282d
Showing
9 changed files
with
152 additions
and
55 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use super::ptr_j::*; | ||
use super::result::ToJniResult; | ||
use crate::panic::{handle_exception_result, ToResult}; | ||
use crate::ptr::RPtrRepresentable; | ||
use jni::objects::{JObject}; | ||
use jni::sys::{jbyteArray, jobject}; | ||
use jni::JNIEnv; | ||
use cddl_lib::{UnitInterval}; | ||
|
||
#[allow(non_snake_case)] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_unitIntervalToBytes( | ||
env: JNIEnv, _: JObject, unit_interval: JRPtr | ||
) -> jobject { | ||
handle_exception_result(|| { | ||
let unit_interval = unit_interval.rptr(&env)?; | ||
unit_interval | ||
.typed_ref::<UnitInterval>() | ||
.map(|unit_interval| unit_interval.to_bytes()) | ||
.and_then(|bytes| env.byte_array_from_slice(&bytes).into_result()) | ||
.map(|arr| JObject::from(arr)) | ||
}) | ||
.jresult(&env) | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_unitIntervalFromBytes( | ||
env: JNIEnv, _: JObject, bytes: jbyteArray | ||
) -> jobject { | ||
handle_exception_result(|| { | ||
env | ||
.convert_byte_array(bytes) | ||
.into_result() | ||
.and_then(|bytes| UnitInterval::from_bytes(bytes).into_result()) | ||
.and_then(|unit_interval| unit_interval.rptr().jptr(&env)) | ||
}) | ||
.jresult(&env) | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn Java_io_emurgo_rnhaskellshelley_Native_unitIntervalNew( | ||
env: JNIEnv, _: JObject, index_0: jint, index_1: jint | ||
) -> jobject { | ||
handle_exception_result(|| { | ||
UnitInterval::new(index_0 as u32, index_1 as u32).rptr().jptr(&env) | ||
}) | ||
.jresult(&env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::data::DataPtr; | ||
use super::result::CResult; | ||
use super::string::{CharPtr}; | ||
use crate::panic::{handle_exception_result, ToResult}; | ||
use crate::ptr::{RPtr, RPtrRepresentable}; | ||
use cddl_lib::{UnitInterval}; | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn unit_interval_to_bytes( | ||
unit_interval: RPtr, result: &mut DataPtr, error: &mut CharPtr | ||
) -> bool { | ||
handle_exception_result(|| unit_interval.typed_ref::<UnitInterval>().map(|unit_interval| unit_interval.to_bytes())) | ||
.map(|bytes| bytes.into()) | ||
.response(result, error) | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn unit_interval_from_bytes( | ||
data: *const u8, len: usize, result: &mut RPtr, error: &mut CharPtr | ||
) -> bool { | ||
handle_exception_result(|| { | ||
UnitInterval::from_bytes(std::slice::from_raw_parts(data, len).into()).into_result() | ||
}) | ||
.map(|unit_interval| unit_interval.rptr()) | ||
.response(result, error) | ||
} | ||
|
||
pub unsafe extern "C" fn unit_interval_new( | ||
index_0: u32, index_1: u32, result: &mut RPtr, error: &mut CharPtr | ||
) -> bool { | ||
handle_exception_result(|| { | ||
UnitInterval::new(index_0, index_1) | ||
}) | ||
.map(|unit_interval| unit_interval.rptr()) | ||
.response(result, error) | ||
} |