rib/compiler/
compiler_output.rs1use crate::compiler::worker_functions_in_rib::WorkerFunctionsInRib;
16use crate::{RibByteCode, RibInputTypeInfo, RibOutputTypeInfo};
17
18#[derive(Debug, Clone)]
19pub struct CompilerOutput {
20 pub worker_invoke_calls: Option<WorkerFunctionsInRib>,
21 pub byte_code: RibByteCode,
22 pub rib_input_type_info: RibInputTypeInfo,
23 pub rib_output_type_info: Option<RibOutputTypeInfo>,
29}
30
31#[cfg(feature = "protobuf")]
32mod protobuf {
33 use crate::{
34 CompilerOutput, RibByteCode, RibInputTypeInfo, RibOutputTypeInfo, WorkerFunctionsInRib,
35 };
36 use golem_api_grpc::proto::golem::rib::CompilerOutput as ProtoCompilerOutput;
37
38 impl TryFrom<ProtoCompilerOutput> for CompilerOutput {
39 type Error = String;
40
41 fn try_from(value: ProtoCompilerOutput) -> Result<Self, Self::Error> {
42 let proto_rib_input = value.rib_input.ok_or("Missing rib_input")?;
43 let proto_byte_code = value.byte_code.ok_or("Missing byte_code")?;
44 let rib_input = RibInputTypeInfo::try_from(proto_rib_input)?;
45 let byte_code = RibByteCode::try_from(proto_byte_code)?;
46 let worker_invoke_calls = if let Some(value) = value.worker_invoke_calls {
47 Some(WorkerFunctionsInRib::try_from(value)?)
48 } else {
49 None
50 };
51
52 let rib_output_type_info = value
53 .rib_output
54 .map(RibOutputTypeInfo::try_from)
55 .transpose()?;
56
57 Ok(CompilerOutput {
58 worker_invoke_calls,
59 byte_code,
60 rib_input_type_info: rib_input,
61 rib_output_type_info,
62 })
63 }
64 }
65
66 impl TryFrom<CompilerOutput> for ProtoCompilerOutput {
67 type Error = String;
68
69 fn try_from(value: CompilerOutput) -> Result<Self, Self::Error> {
70 Ok(ProtoCompilerOutput {
71 byte_code: Some(golem_api_grpc::proto::golem::rib::RibByteCode::try_from(
72 value.byte_code,
73 )?),
74 rib_input: Some(golem_api_grpc::proto::golem::rib::RibInputType::from(
75 value.rib_input_type_info,
76 )),
77 worker_invoke_calls: value
78 .worker_invoke_calls
79 .map(golem_api_grpc::proto::golem::rib::WorkerFunctionsInRib::from),
80
81 rib_output: value
82 .rib_output_type_info
83 .map(golem_api_grpc::proto::golem::rib::RibOutputType::from),
84 })
85 }
86 }
87}