hyprstream_ts_codegen/py_codegen/
mod.rs1#![allow(dead_code)]
9
10use hyprstream_rpc_build::backend::CodegenBackend;
11use hyprstream_rpc_build::schema::types::{FieldDef, ParsedSchema};
12
13pub struct PythonBackend;
15
16impl CodegenBackend for PythonBackend {
17 fn map_type(&self, capnp_type: &str) -> String {
18 match capnp_type {
19 "Void" => "None".into(),
20 "Bool" => "bool".into(),
21 "UInt8" | "UInt16" | "UInt32" | "UInt64" | "Int8" | "Int16" | "Int32" | "Int64" => {
22 "int".into()
23 }
24 "Float32" | "Float64" => "float".into(),
25 "Text" => "str".into(),
26 "Data" => "bytes".into(),
27 _ if capnp_type.starts_with("List(") => {
28 let inner = &capnp_type[5..capnp_type.len() - 1];
29 format!("list[{}]", self.map_type(inner))
30 }
31 _ => capnp_type.to_owned(),
32 }
33 }
34
35 fn setter_method(&self, _type_name: &str) -> Option<String> {
36 None
38 }
39
40 fn getter_expr(&self, reader_var: &str, field: &FieldDef) -> String {
41 format!("{reader_var}.{}", field.name)
43 }
44
45 fn default_value(&self, capnp_type: &str) -> String {
46 match capnp_type {
47 "Void" => "None".into(),
48 "Bool" => "False".into(),
49 "Text" => "\"\"".into(),
50 "Data" => "b\"\"".into(),
51 _ if capnp_type.starts_with("List(") => "[]".into(),
52 _ if capnp_type.contains("Int") || capnp_type.contains("Float") => "0".into(),
53 _ => "None".into(),
54 }
55 }
56
57 fn generate_service_file(&self, service_name: &str, _schema: &ParsedSchema) -> String {
58 format!("# Generated for {service_name} — Python codegen not yet implemented\n")
60 }
61
62 fn runtime_file(&self) -> (String, String) {
63 (
65 "capnp.py".to_owned(),
66 "# Cap'n Proto Python runtime — not yet implemented\n".to_owned(),
67 )
68 }
69
70 fn file_extension(&self) -> &str {
71 "py"
72 }
73}