29{
31 arser.add_argument(
"recipe").help(
"Source recipe file path to convert");
32 arser.add_argument(
"circle").help(
"Target circle file path");
33
34 try
35 {
36 arser.parse(argc, argv);
37 }
38 catch (const std::runtime_error &err)
39 {
40 std::cout << err.what() << std::endl;
42 return 255;
43 }
44
45 int32_t model_version = 1;
46
47 ::circlechef::ModelRecipe model_recipe;
48
49 std::string recipe_path =
arser.get<std::string>(
"recipe");
50
51 {
52 std::ifstream is{recipe_path};
53 google::protobuf::io::IstreamInputStream iis{&is};
54 if (!google::protobuf::TextFormat::Parse(&iis, &model_recipe))
55 {
56 std::cerr << "ERROR: Failed to parse recipe '" << recipe_path << "'" << std::endl;
57 return 255;
58 }
59
60 if (model_recipe.has_version())
61 {
62 model_version = model_recipe.version();
63 }
64 }
65
66 if (model_version > 1)
67 {
68 std::cerr << "ERROR: Unsupported recipe version: " << model_version << ", '" << recipe_path
69 << "'" << std::endl;
70 return 255;
71 }
72
74
75 std::string circle_path =
arser.get<std::string>(
"circle");
76
77 {
78 std::ofstream os{circle_path, std::ios::binary};
79 os.write(generated_model.base(), generated_model.size());
80 }
81
82 return 0;
83}
GeneratedModel cook(const ModelRecipe &model_recipe)