Skip to main content

systemprompt_models/a2a/
transport.rs

1//! `ProtocolBinding` transport tags with parse/display.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
9pub enum ProtocolBinding {
10    #[serde(rename = "JSONRPC")]
11    #[default]
12    JsonRpc,
13    #[serde(rename = "GRPC")]
14    Grpc,
15    #[serde(rename = "HTTP+JSON")]
16    HttpJson,
17}
18
19pub type TransportProtocol = ProtocolBinding;
20
21impl From<ProtocolBinding> for String {
22    fn from(transport: ProtocolBinding) -> Self {
23        match transport {
24            ProtocolBinding::JsonRpc => "JSONRPC".to_owned(),
25            ProtocolBinding::Grpc => "GRPC".to_owned(),
26            ProtocolBinding::HttpJson => "HTTP+JSON".to_owned(),
27        }
28    }
29}
30
31impl std::str::FromStr for ProtocolBinding {
32    type Err = crate::errors::ParseEnumError;
33
34    fn from_str(s: &str) -> Result<Self, Self::Err> {
35        match s {
36            "JSONRPC" => Ok(Self::JsonRpc),
37            "GRPC" => Ok(Self::Grpc),
38            "HTTP+JSON" => Ok(Self::HttpJson),
39            _ => Err(crate::errors::ParseEnumError::new("protocol_binding", s)),
40        }
41    }
42}
43
44impl std::fmt::Display for ProtocolBinding {
45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46        match self {
47            Self::JsonRpc => write!(f, "JSONRPC"),
48            Self::Grpc => write!(f, "GRPC"),
49            Self::HttpJson => write!(f, "HTTP+JSON"),
50        }
51    }
52}
53
54impl ProtocolBinding {
55    pub const fn as_str(&self) -> &'static str {
56        match self {
57            Self::JsonRpc => "JSONRPC",
58            Self::Grpc => "GRPC",
59            Self::HttpJson => "HTTP+JSON",
60        }
61    }
62}