Live video on the AT Protocol
1use std::{fs, path::Path};
2
3use anyhow::Result;
4use c2pa::{Builder, ManifestDefinition, Reader};
5use schemars::{schema::RootSchema, schema_for, JsonSchema};
6use serde::{Deserialize, Serialize};
7use serde_with::skip_serializing_none;
8
9fn write_schema(schema: &RootSchema, name: &str) {
10 println!("Exporting JSON schema for {name}");
11 let output = serde_json::to_string_pretty(schema).expect("Failed to serialize schema");
12 let output_dir = Path::new("./target/schema");
13 fs::create_dir_all(output_dir).expect("Could not create schema directory");
14 let output_path = output_dir.join(format!("{name}.schema.json"));
15 fs::write(&output_path, output).expect("Unable to write schema");
16 println!("Wrote schema to {}", output_path.display());
17}
18
19#[skip_serializing_none]
20#[derive(Debug, Default, Deserialize, Serialize, JsonSchema)]
21pub struct Everything {
22 pub builder: Builder,
23 pub manifest_definition: ManifestDefinition,
24 pub reader: Reader,
25}
26
27fn main() -> Result<()> {
28 let everything = schema_for!(Everything);
29 write_schema(&everything, "C2PA");
30
31 Ok(())
32}