elite_rpc/protocol.rs
1//! Contrct definition for the protocol
2//!
3//! Author: Vincenzo Palazzo <vincenzopalazzo@member.fsf.org>
4use serde::Serialize;
5
6/// Type of Encoding.
7///
8/// FIXME: It is not supporting all the type of encoding
9/// but some of them.
10pub enum Encoding {
11 UTF8,
12}
13
14/// Contract definition of the protocol.
15pub trait Protocol: Clone {
16 type InnerType: Serialize;
17
18 /// Create a new instance of the protocol.
19 fn new() -> anyhow::Result<Self>
20 where
21 Self: Sized;
22
23 /// Build the Request for this protocol.
24 ///
25 /// Returning the request to send to the transport and
26 /// also a addons info to the URL.
27 ///
28 /// Like in post there is informtion to add to the base URl.
29 fn to_request(
30 &self,
31 method: &str,
32 request: &Self::InnerType,
33 ) -> anyhow::Result<(String, Self::InnerType)>;
34
35 /// Build the response fom the response
36 #[allow(clippy::wrong_self_convention)]
37 fn from_request(
38 &self,
39 content: &[u8],
40 encoding: Option<Encoding>,
41 ) -> anyhow::Result<Self::InnerType>;
42}