Skip to content

Commit

Permalink
add codegen example
Browse files Browse the repository at this point in the history
  • Loading branch information
lonerapier committed Aug 28, 2024
1 parent 01c2a79 commit fa63840
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
6 changes: 6 additions & 0 deletions json_examples/codegen/value_string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"keys": [
"a"
],
"value_type": "string"
}
40 changes: 17 additions & 23 deletions src/bin/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
use std::fs;

use clap::Parser;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(name = "codegen")]
struct Args {
/// Path to the JSON file
#[arg(short, long)]
json_file: PathBuf,
}

#[derive(Debug, Deserialize)]
enum ValueType {
Expand Down Expand Up @@ -153,25 +162,7 @@ fn extract_number(data: Data, cfb: &mut String) {
"#;
}

fn parse_json_request() -> std::io::Result<()> {
let request = r#"
{
"keys": ["a"],
"value_type": "string"
}
"#;

let data: Data = serde_json::from_str(request)?;
// let key_bytes = data
// .keys
// .iter()
// .map(|k| match k {
// Key::String(key) => key.as_bytes().to_owned(),
// Key::Num(num) => num.to_string().as_bytes().to_owned(),
// })
// .collect::<Vec<Vec<u8>>>();
println!("{:?}", data);

fn parse_json_request(data: Data) -> Result<(), Box<dyn std::error::Error>> {
let mut cfb = String::new();
cfb += PRAGMA;
cfb += "include \"./fetcher.circom\";\n\n";
Expand Down Expand Up @@ -379,7 +370,10 @@ fn parse_json_request() -> std::io::Result<()> {
Ok(())
}

pub fn main() -> std::io::Result<()> {
parse_json_request()?;
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
let data = std::fs::read(&args.json_file)?;
let json_data: Data = serde_json::from_slice(&data)?;
parse_json_request(json_data)?;
Ok(())
}

0 comments on commit fa63840

Please sign in to comment.