systemprompt_models/a2a/
transport.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
4pub enum ProtocolBinding {
5 #[serde(rename = "JSONRPC")]
6 #[default]
7 JsonRpc,
8 #[serde(rename = "GRPC")]
9 Grpc,
10 #[serde(rename = "HTTP+JSON")]
11 HttpJson,
12}
13
14pub type TransportProtocol = ProtocolBinding;
15
16impl From<ProtocolBinding> for String {
17 fn from(transport: ProtocolBinding) -> Self {
18 match transport {
19 ProtocolBinding::JsonRpc => "JSONRPC".to_string(),
20 ProtocolBinding::Grpc => "GRPC".to_string(),
21 ProtocolBinding::HttpJson => "HTTP+JSON".to_string(),
22 }
23 }
24}
25
26impl std::str::FromStr for ProtocolBinding {
27 type Err = anyhow::Error;
28
29 fn from_str(s: &str) -> Result<Self, Self::Err> {
30 match s {
31 "JSONRPC" => Ok(Self::JsonRpc),
32 "GRPC" => Ok(Self::Grpc),
33 "HTTP+JSON" => Ok(Self::HttpJson),
34 _ => Err(anyhow::anyhow!("Invalid protocol binding: {}", s)),
35 }
36 }
37}
38
39impl std::fmt::Display for ProtocolBinding {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 match self {
42 Self::JsonRpc => write!(f, "JSONRPC"),
43 Self::Grpc => write!(f, "GRPC"),
44 Self::HttpJson => write!(f, "HTTP+JSON"),
45 }
46 }
47}
48
49impl ProtocolBinding {
50 pub const fn as_str(&self) -> &'static str {
51 match self {
52 Self::JsonRpc => "JSONRPC",
53 Self::Grpc => "GRPC",
54 Self::HttpJson => "HTTP+JSON",
55 }
56 }
57}