Trait ockam::protocols::ProtocolParser
source · [−]pub trait ProtocolParser: Sized {
fn check_id(id: &str) -> bool;
fn parse(pp: ProtocolPayload) -> Result<Self>;
}
Expand description
Map a ProtocolPayload
to a protocol specific type.
This trait should be implemented for the facade enum-type of a protocol, meaning that the usage will look something like this.
async fn handle_message(&mut self, _: &mut Context, msg: Routed<Any>) -> Result<()> {
let protocol_payload = ProtocolPayload::decode(msg.payload())?;
let resp = MyProtocolResponse::parse(protocol_payload)?;
println!("{:?}", resp);
Ok(())
}
Required Methods
A function which checks whether this parser should be called for a particular protocol payload.
Internally it’s recommended to use static strings and a set operation to speed up repeated queries.
fn parse(pp: ProtocolPayload) -> Result<Self>
fn parse(pp: ProtocolPayload) -> Result<Self>
Parse a ProtocolPayload, which must have a type supported by this parser.