Added wakumessage

This commit is contained in:
danielsanchezq 2022-09-23 12:31:37 +02:00
parent e76361d5fc
commit 6db57b44b6
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,3 @@
use bindgen;
use std::env;
use std::env::set_current_dir;
use std::path::PathBuf;

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,
}