#[cfg(feature = "emitter-kotlin")]
pub mod kotlin;
pub mod rust;
#[cfg(feature = "emitter-swift")]
pub mod swift;
#[cfg(feature = "emitter-typescript")]
pub mod typescript;
#[cfg(feature = "emitter-unity")]
pub mod unity;
use crate::ir::manifest::SchemaManifest;
use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct EmitterConfig {
pub output_dir: PathBuf,
pub wasm_bindings: bool,
pub native_bindings: bool,
pub manifest: SchemaManifest,
}
pub trait Emitter {
fn platform(&self) -> &'static str;
fn extension(&self) -> &'static str;
fn emit(&self, config: &EmitterConfig) -> anyhow::Result<Vec<GeneratedFile>>;
}
#[derive(Debug, Clone)]
pub struct GeneratedFile {
pub path: PathBuf,
pub content: String,
}
pub const VERSION_BYTE_COMMENT: &str = r#"
// ============================================================================
// MOTTO GENERATED CODE - DO NOT EDIT
//
// This file was generated by motto from a Rust schema definition.
// Any changes will be overwritten on next generation.
//
// Protocol Version Byte: {VERSION_BYTE}
// Schema Fingerprint: {FINGERPRINT}
// Generated At: {TIMESTAMP}
// ============================================================================
"#;
pub mod utils {
use heck::{ToLowerCamelCase, ToPascalCase, ToSnakeCase, ToUpperCamelCase};
pub fn to_pascal_case(s: &str) -> String {
s.to_pascal_case()
}
pub fn to_camel_case(s: &str) -> String {
s.to_lower_camel_case()
}
pub fn to_snake_case(s: &str) -> String {
s.to_snake_case()
}
pub fn to_upper_camel_case(s: &str) -> String {
s.to_upper_camel_case()
}
pub fn escape_reserved(name: &str, reserved: &[&str]) -> String {
if reserved.contains(&name) {
format!("{}_", name)
} else {
name.to_string()
}
}
pub fn generate_header(version_byte: u8, fingerprint: &str, timestamp: &str) -> String {
super::VERSION_BYTE_COMMENT
.replace("{VERSION_BYTE}", &format!("0x{:02X}", version_byte))
.replace("{FINGERPRINT}", fingerprint)
.replace("{TIMESTAMP}", timestamp)
}
}