synapse-proto 0.0.2

Protocol Buffers message definitions for Synapse RPC
Documentation
fn main() {
    // Set up the vendored protoc
    unsafe {
        std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap());
    }

    let mut config = prost_build::Config::new();

    // Use Bytes for byte fields (more efficient)
    config.bytes(["."]);

    // Add serde derives to all types
    config.type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]");

    // Custom serde for request_id (UUID as string in JSON)
    config.field_attribute(
        "RpcRequest.request_id",
        "#[serde(with = \"crate::serde_helpers::uuid_string\")]",
    );
    config.field_attribute(
        "RpcResponse.request_id",
        "#[serde(with = \"crate::serde_helpers::uuid_string\")]",
    );

    // Custom serde for payload (supports both plain text and base64)
    config.field_attribute(
        "RpcRequest.payload",
        "#[serde(with = \"crate::serde_helpers::payload_flexible\")]",
    );
    config.field_attribute(
        "RpcResponse.payload",
        "#[serde(with = \"crate::serde_helpers::payload_flexible\")]",
    );

    // instance_id fields also as UUID strings
    config.field_attribute(
        "InterfaceRegister.instance_id",
        "#[serde(with = \"crate::serde_helpers::uuid_string\")]",
    );
    config.field_attribute(
        "InterfaceDeregister.instance_id",
        "#[serde(with = \"crate::serde_helpers::uuid_string\")]",
    );

    // Compile the core proto file
    config
        .compile_protos(&["proto/synapse.proto"], &["proto/"])
        .expect("Failed to compile protobuf files");

    println!("cargo:rerun-if-changed=proto/synapse.proto");
}