saluki_core/data_model/payload/
mod.rs1use std::fmt;
4
5use bitmask_enum::bitmask;
6
7mod grpc;
8pub use self::grpc::GrpcPayload;
9
10mod http;
11pub use self::http::HttpPayload;
12use crate::topology::interconnect::Dispatchable;
13
14mod metadata;
15pub use self::metadata::PayloadMetadata;
16
17mod raw;
18pub use self::raw::RawPayload;
19
20#[bitmask(u8)]
25#[bitmask_config(vec_debug)]
26pub enum PayloadType {
27 Raw,
29
30 Http,
32
33 Grpc,
35}
36
37impl Default for PayloadType {
38 fn default() -> Self {
39 Self::none()
40 }
41}
42
43impl fmt::Display for PayloadType {
44 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45 let mut types = Vec::new();
46
47 if self.contains(Self::Raw) {
48 types.push("Raw");
49 }
50
51 if self.contains(Self::Http) {
52 types.push("HTTP");
53 }
54
55 if self.contains(Self::Grpc) {
56 types.push("gRPC");
57 }
58
59 write!(f, "{}", types.join("|"))
60 }
61}
62
63#[derive(Clone)]
65#[allow(clippy::large_enum_variant)]
66pub enum Payload {
67 Raw(RawPayload),
71
72 Http(HttpPayload),
76
77 Grpc(GrpcPayload),
81}
82
83impl Payload {
84 pub fn payload_type(&self) -> PayloadType {
86 match self {
87 Payload::Raw(_) => PayloadType::Raw,
88 Payload::Http(_) => PayloadType::Http,
89 Payload::Grpc(_) => PayloadType::Grpc,
90 }
91 }
92
93 pub fn try_into_raw(self) -> Option<RawPayload> {
97 match self {
98 Payload::Raw(payload) => Some(payload),
99 _ => None,
100 }
101 }
102
103 pub fn try_into_http_payload(self) -> Option<HttpPayload> {
107 match self {
108 Payload::Http(payload) => Some(payload),
109 _ => None,
110 }
111 }
112
113 pub fn try_into_grpc_payload(self) -> Option<GrpcPayload> {
117 match self {
118 Payload::Grpc(payload) => Some(payload),
119 _ => None,
120 }
121 }
122}
123
124impl Dispatchable for Payload {
125 fn item_count(&self) -> usize {
126 1
127 }
128}