marine_call_parameters/
lib.rs1#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
18use marine_macro::marine;
19
20use serde::Serialize;
21use serde::Deserialize;
22
23#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
25#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
26#[cfg_attr(
27 feature = "rkyv",
28 derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
29)]
30#[cfg_attr(feature = "rkyv", archive(check_bytes))]
31pub struct SecurityTetraplet {
32 pub peer_pk: String,
34
35 pub service_id: String,
37
38 pub function_name: String,
40
41 pub lens: String,
43}
44
45impl SecurityTetraplet {
46 pub fn new(
47 peer_pk: impl Into<String>,
48 service_id: impl Into<String>,
49 function_name: impl Into<String>,
50 lens: impl Into<String>,
51 ) -> Self {
52 Self {
53 peer_pk: peer_pk.into(),
54 service_id: service_id.into(),
55 function_name: function_name.into(),
56 lens: lens.into(),
57 }
58 }
59
60 pub fn literal_tetraplet(init_peer_id: impl Into<String>) -> Self {
63 Self {
64 peer_pk: init_peer_id.into(),
66 service_id: String::new(),
67 function_name: String::new(),
68 lens: String::new(),
70 }
71 }
72
73 pub fn add_lens(&mut self, lens: &str) {
74 self.lens.push_str(lens)
75 }
76}
77
78#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
80#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
81#[cfg_attr(
82 feature = "rkyv",
83 derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
84)]
85#[cfg_attr(feature = "rkyv", archive(check_bytes))]
86pub struct CallParameters {
87 pub particle: ParticleParameters,
89
90 pub service_id: String,
92
93 pub service_creator_peer_id: String,
95
96 pub host_id: String,
98
99 pub worker_id: String,
101
102 pub tetraplets: Vec<Vec<SecurityTetraplet>>,
104}
105
106#[cfg_attr(all(target_arch = "wasm32", feature = "marine-abi"), marine)]
107#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
108#[cfg_attr(
109 feature = "rkyv",
110 derive(::rkyv::Archive, ::rkyv::Serialize, ::rkyv::Deserialize)
111)]
112#[cfg_attr(feature = "rkyv", archive(check_bytes))]
113pub struct ParticleParameters {
114 pub id: String,
116
117 pub init_peer_id: String,
119
120 pub timestamp: u64,
122
123 pub ttl: u32,
125
126 pub script: String,
128
129 pub signature: Vec<u8>,
131
132 pub token: String,
134}
135
136use std::fmt;
137impl fmt::Display for SecurityTetraplet {
138 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 write!(
140 f,
141 "peer_pk: {}, service_id: {}, function_name: {}, lens: {}",
142 self.peer_pk, self.service_id, self.function_name, self.lens
143 )
144 }
145}
146
147#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
150pub fn get_call_parameters() -> CallParameters {
151 unsafe {
153 get_call_raw_parameters();
154 let raw_call_parameters = crate::internal::get_result_ptr();
155 CallParameters::__m_generated_deserialize(raw_call_parameters as _)
156 }
157}
158
159#[cfg(not(all(target_arch = "wasm32", feature = "marine-abi")))]
160pub fn get_call_parameters() -> CallParameters {
161 unimplemented!()
162}
163
164#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
165#[link(wasm_import_module = "__marine_host_api_v3")]
166#[allow(improper_ctypes)]
167extern "C" {
168 #[link_name = "get_call_parameters"]
170 fn get_call_raw_parameters();
171}
172
173#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
174#[allow(unused_extern_crates)]
175extern crate self as marine_rs_sdk;
176
177#[cfg(all(feature = "marine-abi", target_arch = "wasm32"))]
178#[allow(unused_imports)]
179mod internal {
180 pub(crate) use marine_rs_sdk_main::add_object_to_release;
181 pub(crate) use marine_rs_sdk_main::get_result_ptr;
182 pub(crate) use marine_rs_sdk_main::get_result_size;
183 pub(crate) use marine_rs_sdk_main::set_result_ptr;
184 pub(crate) use marine_rs_sdk_main::set_result_size;
185}