use crate::alink::aiot_module::{get_aiot_json, ModuleRecvKind};
use crate::alink::alink_topic::ALinkSubscribeTopic;
use crate::alink::AlinkRequest;
use crate::{alink::AlinkResponse, Error};
use enum_iterator::IntoEnumIterator;
use enum_kinds::EnumKind;
use log::*;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use spin::Lazy;
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BootstrapNotifyParams {
pub cmd: u32,
}
pub type BootstrapNotify = AlinkRequest<BootstrapNotifyParams>;
#[derive(Debug, EnumKind)]
#[enum_kind(BootstrapRecvKind, derive(Serialize, IntoEnumIterator, Deserialize))]
pub enum BootstrapRecv {
BootstrapNotify(BootstrapNotify),
}
impl ModuleRecvKind for super::RecvKind {
type Recv = super::Recv;
fn get_topic(&self) -> ALinkSubscribeTopic {
match *self {
Self::BootstrapNotify => ALinkSubscribeTopic::new("/sys/+/+/thing/bootstrap/notify"),
}
}
fn to_payload(&self, payload: &[u8], _: &Vec<String>) -> crate::Result<Self::Recv> {
let json_str = get_aiot_json(payload);
match *self {
Self::BootstrapNotify => Ok(Self::Recv::BootstrapNotify(serde_json::from_str(
&json_str,
)?)),
}
}
}