wasmcloud_actor_core/
generated.rs1extern crate rmp_serde as rmps;
2use rmps::{Deserializer, Serializer};
3use serde::{Deserialize, Serialize};
4use std::io::Cursor;
5
6#[cfg(feature = "guest")]
7extern crate wapc_guest as guest;
8#[cfg(feature = "guest")]
9use guest::prelude::*;
10
11#[cfg(feature = "guest")]
12pub struct Handlers {}
13
14#[cfg(feature = "guest")]
15impl Handlers {
16 pub fn register_health_request(
19 f: fn(HealthCheckRequest) -> HandlerResult<HealthCheckResponse>,
20 ) {
21 *HEALTH_REQUEST.write().unwrap() = Some(f);
22 register_function(&"HealthRequest", health_request_wrapper);
23 }
24}
25
26#[cfg(feature = "guest")]
27lazy_static::lazy_static! {
28static ref HEALTH_REQUEST: std::sync::RwLock<Option<fn(HealthCheckRequest) -> HandlerResult<HealthCheckResponse>>> = std::sync::RwLock::new(None);
29}
30
31#[cfg(feature = "guest")]
32fn health_request_wrapper(input_payload: &[u8]) -> CallResult {
33 let input = deserialize::<HealthCheckRequest>(input_payload)?;
34 let lock = HEALTH_REQUEST.read().unwrap().unwrap();
35 let result = lock(input)?;
36 serialize(result)
37}
38
39#[derive(Debug, PartialEq, Deserialize, Serialize, Default, Clone)]
41pub struct CapabilityConfiguration {
42 #[serde(rename = "module")]
44 pub module: String,
45 #[serde(rename = "values")]
47 pub values: std::collections::HashMap<String, String>,
48}
49
50#[derive(Debug, PartialEq, Deserialize, Serialize, Default, Clone)]
52pub struct HealthCheckRequest {
53 #[serde(rename = "placeholder")]
55 pub placeholder: bool,
56}
57
58#[derive(Debug, PartialEq, Deserialize, Serialize, Default, Clone)]
63pub struct HealthCheckResponse {
64 #[serde(rename = "healthy")]
66 pub healthy: bool,
67 #[serde(rename = "message")]
69 pub message: String,
70}
71
72pub fn serialize<T>(
76 item: T,
77) -> ::std::result::Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>>
78where
79 T: Serialize,
80{
81 let mut buf = Vec::new();
82 item.serialize(&mut Serializer::new(&mut buf).with_struct_map())?;
83 Ok(buf)
84}
85
86pub fn deserialize<'de, T: Deserialize<'de>>(
90 buf: &[u8],
91) -> ::std::result::Result<T, Box<dyn std::error::Error + Send + Sync>> {
92 let mut de = Deserializer::new(Cursor::new(buf));
93 match Deserialize::deserialize(&mut de) {
94 Ok(t) => Ok(t),
95 Err(e) => Err(format!("Failed to de-serialize: {}", e).into()),
96 }
97}