use buffa_descriptor::generated::descriptor::MethodDescriptorProto;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RpcKind {
Unary,
ClientStreaming,
ServerStreaming,
BidiStreaming,
}
pub fn rpc_kind(method: &MethodDescriptorProto) -> RpcKind {
let client = method.client_streaming.unwrap_or(false);
let server = method.server_streaming.unwrap_or(false);
match (client, server) {
(false, false) => RpcKind::Unary,
(true, false) => RpcKind::ClientStreaming,
(false, true) => RpcKind::ServerStreaming,
(true, true) => RpcKind::BidiStreaming,
}
}
pub fn split_proto_type_name(fqn: &str) -> Option<(&str, &str)> {
let s = fqn.strip_prefix('.')?;
let (pkg, msg) = s.rsplit_once('.')?;
if pkg.is_empty() || msg.is_empty() {
return None;
}
Some((pkg, msg))
}