use switchback_traits::{ResponseSeverity, Result};
pub trait Protocol: Send + Sync + 'static {
fn id(&self) -> &'static str;
}
pub trait ProtocolWire: Sized {
const PROTOCOL_ID: &'static str;
fn encode_to_vec(&self) -> Vec<u8>;
fn decode_from_bytes(bytes: &[u8]) -> Result<Self>;
}
pub trait OperationProtocol: Protocol {
type OperationMeta: ProtocolWire;
fn format_signature(&self, meta: &Self::OperationMeta) -> String;
fn operation_title_hint(&self, meta: &Self::OperationMeta) -> Option<String> {
let _ = meta;
None
}
}
pub trait ResponseProtocol: Protocol {
fn response_severity(&self, status_key: &str) -> ResponseSeverity;
}
pub trait ErrorProtocol: Protocol {
type ErrorMeta: ProtocolWire;
fn error_severity(&self, error_key: &str) -> ResponseSeverity;
fn format_error_label(&self, error_key: &str) -> String;
}
pub trait FieldCarrierProtocol: Protocol {
fn field_carrier_kinds(&self) -> &'static [&'static str];
fn valid_parameter_locations(&self) -> &'static [&'static str];
}