1pub mod execute {
2 use crate::error::NihilityRpcError;
3
4 tonic::include_proto!("nihility.execute");
5
6 #[derive(Debug, Clone)]
7 pub enum ExecuteData {
8 String(String),
9 }
10
11 impl TryFrom<ExecuteRequest> for ExecuteData {
12 type Error = NihilityRpcError;
13
14 fn try_from(value: ExecuteRequest) -> Result<Self, Self::Error> {
15 match value.r#type() {
16 ExecuteType::String => Ok(ExecuteData::String(String::from_utf8(value.payload)?)),
17 }
18 }
19 }
20
21 impl From<ExecuteData> for ExecuteRequest {
22 fn from(value: ExecuteData) -> Self {
23 match value {
24 ExecuteData::String(string_value) => ExecuteRequest {
25 r#type: ExecuteType::String.into(),
26 payload: string_value.into_bytes(),
27 },
28 }
29 }
30 }
31
32 impl TryFrom<ExecuteResponse> for ExecuteData {
33 type Error = NihilityRpcError;
34
35 fn try_from(value: ExecuteResponse) -> Result<Self, Self::Error> {
36 match value.r#type() {
37 ExecuteType::String => Ok(ExecuteData::String(String::from_utf8(value.payload)?)),
38 }
39 }
40 }
41
42 impl From<ExecuteData> for ExecuteResponse {
43 fn from(value: ExecuteData) -> Self {
44 match value {
45 ExecuteData::String(string_value) => ExecuteResponse {
46 r#type: ExecuteType::String.into(),
47 payload: string_value.into_bytes(),
48 },
49 }
50 }
51 }
52}