From 331887352772acc62b45d0aae36d049f6293c3be Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Tue, 31 Oct 2023 21:07:08 +0100 Subject: [PATCH] RUST: At the end, we will use the rust things to load/save documents, it will be easier in the long run --- README.md | 2 +- src/Rust/Cargo.lock | 3 +++ src/Rust/Cargo.toml | 10 ++++++--- src/Rust/vvs_lib/Cargo.toml | 2 ++ src/Rust/vvs_lib/src/lib.rs | 1 + src/Rust/vvs_lib/src/vivy.rs | 35 +++++++++++++++++++++++++++++++ src/Rust/vvs_lib/test/sample.vivy | 10 +++++++++ 7 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 src/Rust/vvs_lib/src/vivy.rs create mode 100644 src/Rust/vvs_lib/test/sample.vivy diff --git a/README.md b/README.md index 9efaab23..f3b40006 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Simply use cmake to build in another folder of the source folder: ```bash -cmake -Bbuild -DCMAKE_CXX_COMPILER=clang++ -CDMAKE_INSTALL_PREFIX=$HOME/.local -GNinja +cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -CDMAKE_INSTALL_PREFIX=$HOME/.local -GNinja ninja -Cbuild ninja -Cbuild install ``` diff --git a/src/Rust/Cargo.lock b/src/Rust/Cargo.lock index 55a9cd7a..47469ac7 100644 --- a/src/Rust/Cargo.lock +++ b/src/Rust/Cargo.lock @@ -458,6 +458,7 @@ version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -686,6 +687,8 @@ version = "0.5.0" dependencies = [ "cbindgen", "log", + "serde", + "serde_json", "vvs_ass", ] diff --git a/src/Rust/Cargo.toml b/src/Rust/Cargo.toml index 7cfb804b..3408350a 100644 --- a/src/Rust/Cargo.toml +++ b/src/Rust/Cargo.toml @@ -25,14 +25,18 @@ nom = { version = "7", default-features = false, features = ["std"] } nom_locate = { version = "4", default-features = false, features = ["std"] } # SerDe -toml = { version = "0.8", default-features = false, features = [ - "parse", - "display", +serde_json = { version = "1", default-features = false, features = [ + "std", + "preserve_order", ] } serde = { version = "1", default-features = false, features = [ "std", "derive", ] } +toml = { version = "0.8", default-features = false, features = [ + "parse", + "display", +] } [profile.release] strip = true diff --git a/src/Rust/vvs_lib/Cargo.toml b/src/Rust/vvs_lib/Cargo.toml index 77b27a26..51056514 100644 --- a/src/Rust/vvs_lib/Cargo.toml +++ b/src/Rust/vvs_lib/Cargo.toml @@ -12,6 +12,8 @@ crate-type = ["staticlib"] [dependencies] log.workspace = true +serde.workspace = true +serde_json.workspace = true vvs_ass = { path = "../vvs_ass" } diff --git a/src/Rust/vvs_lib/src/lib.rs b/src/Rust/vvs_lib/src/lib.rs index 55ca5a31..9dbbf954 100644 --- a/src/Rust/vvs_lib/src/lib.rs +++ b/src/Rust/vvs_lib/src/lib.rs @@ -7,6 +7,7 @@ use std::ffi::c_char; pub mod ass; +pub mod vivy; /// Represents a string slice, the user may not modify this slice, never! Note that the string is /// not null terminated and may contains null bytes in it, use the len attribute to get the length diff --git a/src/Rust/vvs_lib/src/vivy.rs b/src/Rust/vvs_lib/src/vivy.rs new file mode 100644 index 00000000..6866461b --- /dev/null +++ b/src/Rust/vvs_lib/src/vivy.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + +#[derive(Debug, PartialEq, Eq)] +pub enum VivyDocumentCapabilities { + AudioAble = (1 << 1), + VideoAble = (1 << 2), + AssAble = (1 << 3), +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "PascalCase")] +pub struct VivyDocument { + #[serde(default = "u64::default")] + pub capabilities: u64, + pub name: String, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "PascalCase")] +#[serde(tag = "DocumentVersion", content = "SubDocuments")] +pub enum VivySubDocument { + Alpha { + sub_ass: Option<PathBuf>, + sub_audio: Option<PathBuf>, + sub_video: Option<PathBuf>, + }, +} + +#[test] +fn test_deserialize() { + if let Err(err) = serde_json::from_str::<VivyDocument>(include_str!("../test/sample.vivy")) { + panic!("{err}") + } +} diff --git a/src/Rust/vvs_lib/test/sample.vivy b/src/Rust/vvs_lib/test/sample.vivy new file mode 100644 index 00000000..16bd90a6 --- /dev/null +++ b/src/Rust/vvs_lib/test/sample.vivy @@ -0,0 +1,10 @@ +{ + "Name": "test", + "Capabilities": 12, + "DocumentVersion": "alpha", + "SubDocuments": { + "SubAss": "vivy/src/Rust/vvs_ass/utils/empty.ass", + "SubVideo": "data/4036f7f60c08bf70741f118eca95dff61facfb66199351e9e40900071cd5322d.mkv" + } +} + -- GitLab