Added wakumessage

This commit is contained in:
danielsanchezq 2022-09-23 12:31:37 +02:00 committed by Daniel Sanchez Quiros
parent 28802ca4a1
commit 35e1393843

View File

@ -1,12 +1,12 @@
// std
// crates
use serde::Deserialize;
use serde::{Deserialize, Serialize};
// internal
/// JsonResponse wrapper.
/// `go-waku` ffi returns this type as a `char *` as per the [specification](https://rfc.vac.dev/spec/36/#jsonresponse-type)
///
/// This is internal, as it is better to use rust plain `Result` type.
#[derive(Deserialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum JsonResponse<T> {
@ -14,6 +14,8 @@ pub(crate) enum JsonResponse<T> {
Error(String),
}
/// Waku response, just a `Result` with an `String` error.
/// Convenient we can transform a [`JsonResponse`] into a [`Response`] (`Result`)
type Response<T> = Result<T, String>;
impl<T> From<JsonResponse<T>> for Response<T> {
@ -24,3 +26,14 @@ impl<T> From<JsonResponse<T>> for Response<T> {
}
}
}
/// JsonMessage, Waku message in JSON format.
/// as per the [specification](https://rfc.vac.dev/spec/36/#jsonmessage-type)
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WakuMessage {
payload: Box<[u8]>,
content_topic: String,
version: usize,
timestamp: usize,
}