reifydb_core/interface/catalog/
binding.rs1use serde::{Deserialize, Serialize};
5
6use crate::interface::catalog::id::{BindingId, NamespaceId, ProcedureId};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub enum HttpMethod {
10 Get,
11 Post,
12 Put,
13 Patch,
14 Delete,
15}
16
17impl HttpMethod {
18 pub fn as_str(&self) -> &'static str {
19 match self {
20 Self::Get => "GET",
21 Self::Post => "POST",
22 Self::Put => "PUT",
23 Self::Patch => "PATCH",
24 Self::Delete => "DELETE",
25 }
26 }
27
28 pub fn parse(s: &str) -> Option<Self> {
29 match s {
30 "GET" => Some(Self::Get),
31 "POST" => Some(Self::Post),
32 "PUT" => Some(Self::Put),
33 "PATCH" => Some(Self::Patch),
34 "DELETE" => Some(Self::Delete),
35 _ => None,
36 }
37 }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
41pub enum BindingFormat {
42 Json,
43 Frames,
44 Rbcf,
45}
46
47impl BindingFormat {
48 pub fn as_str(&self) -> &'static str {
49 match self {
50 Self::Json => "json",
51 Self::Frames => "frames",
52 Self::Rbcf => "rbcf",
53 }
54 }
55
56 pub fn parse(s: &str) -> Option<Self> {
57 match s {
58 "json" => Some(Self::Json),
59 "frames" => Some(Self::Frames),
60 "rbcf" => Some(Self::Rbcf),
61 _ => None,
62 }
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67pub enum BindingProtocol {
68 Http {
69 method: HttpMethod,
70 path: String,
71 },
72 Grpc {
73 name: String,
74 },
75 Ws {
76 name: String,
77 },
78}
79
80impl BindingProtocol {
81 pub fn protocol_str(&self) -> &'static str {
82 match self {
83 Self::Http {
84 ..
85 } => "http",
86 Self::Grpc {
87 ..
88 } => "grpc",
89 Self::Ws {
90 ..
91 } => "ws",
92 }
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
97pub struct Binding {
98 pub id: BindingId,
99 pub namespace: NamespaceId,
100 pub name: String,
101 pub procedure_id: ProcedureId,
102 pub protocol: BindingProtocol,
103 pub format: BindingFormat,
104}
105
106impl Binding {
107 pub fn id(&self) -> BindingId {
108 self.id
109 }
110
111 pub fn namespace(&self) -> NamespaceId {
112 self.namespace
113 }
114
115 pub fn procedure_id(&self) -> ProcedureId {
116 self.procedure_id
117 }
118}