#![warn(missing_docs)]
use super::error::Error;
use super::error::Result;
#[derive(Debug, Clone)]
pub enum Method {
ConnectPeerViaHttp,
ConnectWithDid,
ConnectWithSeed,
ListPeers,
CreateOffer,
AnswerOffer,
AcceptAnswer,
SendTo,
Disconnect,
SendSimpleText,
SendHttpRequestMessage,
SendCustomMessage,
PublishMessageToTopic,
FetchMessagesOfTopic,
RegisterService,
LookupService,
PollMessage,
NodeInfo,
NodeDid,
}
impl Method {
pub fn as_str(&self) -> &str {
match self {
Method::ConnectPeerViaHttp => "connectPeerViaHttp",
Method::ConnectWithDid => "connectWithDid",
Method::ConnectWithSeed => "connectWithSeed",
Method::ListPeers => "listPeers",
Method::CreateOffer => "createOffer",
Method::AnswerOffer => "answerOffer",
Method::SendTo => "sendTo",
Method::Disconnect => "disconnect",
Method::AcceptAnswer => "acceptAnswer",
Method::SendSimpleText => "sendSimpleText",
Method::SendHttpRequestMessage => "sendHttpRequestMessage",
Method::SendCustomMessage => "sendCustomMessage",
Method::PublishMessageToTopic => "publishMessageToTopic",
Method::FetchMessagesOfTopic => "fetchMessagesOfTopic",
Method::RegisterService => "registerService",
Method::LookupService => "lookupService",
Method::PollMessage => "pollMessage",
Method::NodeInfo => "nodeInfo",
Method::NodeDid => "nodeDid",
}
}
}
impl ToString for Method {
fn to_string(&self) -> String {
self.as_str().to_owned()
}
}
impl TryFrom<&str> for Method {
type Error = crate::error::Error;
fn try_from(value: &str) -> Result<Self> {
Ok(match value {
"connectPeerViaHttp" => Self::ConnectPeerViaHttp,
"connectWithDid" => Self::ConnectWithDid,
"connectWithSeed" => Self::ConnectWithSeed,
"listPeers" => Self::ListPeers,
"createOffer" => Self::CreateOffer,
"answerOffer" => Self::AnswerOffer,
"sendTo" => Self::SendTo,
"disconnect" => Self::Disconnect,
"acceptAnswer" => Self::AcceptAnswer,
"sendSimpleText" => Self::SendSimpleText,
"sendHttpRequestMessage" => Self::SendHttpRequestMessage,
"sendCustomMessage" => Self::SendCustomMessage,
"publishMessageToTopic" => Method::PublishMessageToTopic,
"fetchMessagesOfTopic" => Method::FetchMessagesOfTopic,
"registerService" => Method::RegisterService,
"lookupService" => Method::LookupService,
"pollMessage" => Method::PollMessage,
"nodeInfo" => Method::NodeInfo,
"nodeDid" => Method::NodeDid,
_ => return Err(Error::InvalidMethod),
})
}
}