123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- extern crate zry_rust_ffi_utils;
- use zry_rust_ffi_utils::bytes_vec::ZRFUBytesVec;
- use zry_rust_ffi_utils::caller::ProcCallerLibSide;
- use zry_rust_ffi_utils::proc::{ZRFUProcArgs, ZRFUProcInstanceTrait, ZRFUProcReturn};
- use zry_rust_ffi_utils::proc::ZRFUProcResultCode;
- use serde::{Serialize, Deserialize};
- use ciborium::{cbor, Value};
- use zry_rust_ffi_utils::{proc_def_ar, proc_def_a, proc_def_r, proc_def_n};
- use zrfu_macro::zrfu_proc_def;
- #[no_mangle]
- pub extern "C" fn LibWithZRFU_Init(caller: &dyn ProcCallerLibSide){
- caller.register_proc(String::from("TestFuncAR"), TestProcAR::factory);
- caller.register_proc(String::from("TestFuncA"), TestProcA::factory);
- caller.register_proc(String::from("TestFuncR"), TestProcR::factory);
- caller.register_proc(String::from("TestFuncN"), TestProcN::factory);
- }
- #[derive(Debug, Serialize, Deserialize)]
- struct TestProcCborIn {
- a: String,
- b: i64,
- c: Value,
- d: Value,
- }
- #[derive(Debug, Serialize, Deserialize)]
- struct TestProcCborOut {
- a: String,
- b: i64,
- c: Value,
- d: Value,
- }
- zrfu_proc_def!{
- proc fn TestProcAR (argsdata: TestProcCborIn) -> (retdata: TestProcCborOut) {
- println!("hello, this function '{}' has args and return.", self.proc_name.as_str());
- println!("args data: {:?}", argsdata);
- let retdata = TestProcCborOut{
- a: argsdata.a.clone(),
- b: argsdata.b,
- c: argsdata.c.clone(),
- d: argsdata.d.clone(),
- };
- }
- }
- zrfu_proc_def!{
- proc fn TestProcA (argsdata: TestProcCborIn) -> () {
- println!("hello, this function '{}' has args but no return.", self.proc_name.as_str());
- println!("args data: {:?}", argsdata);
- }
- }
- zrfu_proc_def!{
- proc fn TestProcR () -> (retdata: TestProcCborOut) {
- println!("hello, this function '{}' has return but no args.", self.proc_name.as_str());
- let c_res = cbor!({
- "reimu" => "hakurei",
- "satori" => "komeiji",
- "koishi" => "komeiji",
- });
- let d_res = cbor!({
- "cirno" => 9,
- "satori" => 5,
- "remilia" => "scarlet",
- });
- let retdata = TestProcCborOut{
- a: String::from("hello, gensokyo"),
- b: 123456,
- c: c_res.unwrap(),
- d: d_res.unwrap(),
- };
- }
- }
- zrfu_proc_def!{
- proc fn TestProcN () -> () {
- println!("hello, this function '{}' has neither args nor return.", self.proc_name.as_str());
- }
- }
- /*
- proc_def_ar!(
- TestProcAR (TestProcCborIn as argsdata ; TestProcCborOut as retdata) {
- println!("hello, this function '{}' has args and return.", self.proc_name);
- println!("args data: {:?}", argsdata);
- let retdata = TestProcCborOut{
- a: argsdata.a.clone(),
- b: argsdata.b,
- c: argsdata.c.clone(),
- d: argsdata.d.clone(),
- };
- }
- );
- proc_def_a!(
- TestProcA (TestProcCborIn as argsdata) {
- println!("hello, this function '{}' has args but has no return.", self.proc_name);
- println!("args data: {:?}", argsdata);
- }
- );
- proc_def_r!(
- TestProcR (TestProcCborOut as retdata) {
- println!("hello, this function '{}' has no args but has return.", self.proc_name);
- let retdata = TestProcCborOut{
- a: String::from("hello, gensokyo"),
- b: 123456,
- c: cbor!({
- "reimu" => "hakurei",
- "satori" => "komeiji",
- "koishi" => "komeiji",
- }),
- d: cbor!({
- "cirno" => 9,
- "satori" => 5,
- "remilia" => "scarlet",
- }),
- };
- }
- );
- proc_def_n!(
- TestProcN () {
- println!("hello, this function '{}' has neither args nor return.", self.proc_name);
- }
- );
- */
|