more app message call
This commit is contained in:
@@ -230,18 +230,23 @@ pub struct VeilidLog {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct VeilidAppMessage {
|
||||
/// Some(sender) if the message was sent directly, None if received via a private/safety route
|
||||
#[serde(with = "opt_json_as_string")]
|
||||
pub sender: Option<NodeId>,
|
||||
/// The content of the message to deliver to the application
|
||||
#[serde(with = "json_as_base64")]
|
||||
pub message: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct VeilidAppCall {
|
||||
/// Some(sender) if the request was sent directly, None if received via a private/safety route
|
||||
#[serde(with = "opt_json_as_string")]
|
||||
pub sender: Option<NodeId>,
|
||||
/// The content of the request to deliver to the application
|
||||
#[serde(with = "json_as_base64")]
|
||||
pub message: Vec<u8>,
|
||||
/// The id to reply to
|
||||
#[serde(with = "json_as_string")]
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
@@ -301,6 +306,14 @@ impl fmt::Display for NodeId {
|
||||
write!(f, "{}", self.key.encode())
|
||||
}
|
||||
}
|
||||
impl FromStr for NodeId {
|
||||
type Err = VeilidAPIError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(Self {
|
||||
key: DHTKey::try_decode(s)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize)]
|
||||
pub struct ValueKey {
|
||||
|
@@ -41,6 +41,23 @@ pub fn serialize_json<T: Serialize + Debug>(val: T) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod json_as_base64 {
|
||||
use data_encoding::BASE64URL_NOPAD;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn serialize<S: Serializer>(v: &Vec<u8>, s: S) -> Result<S::Ok, S::Error> {
|
||||
let base64 = BASE64URL_NOPAD.encode(v);
|
||||
String::serialize(&base64, s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, D::Error> {
|
||||
let base64 = String::deserialize(d)?;
|
||||
BASE64URL_NOPAD
|
||||
.decode(base64.as_bytes())
|
||||
.map_err(|e| serde::de::Error::custom(e))
|
||||
}
|
||||
}
|
||||
|
||||
pub mod json_as_string {
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
Reference in New Issue
Block a user