From a7f06bcfde19dbab9dcc58eeb4fdb1c362b1bf2a Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Thu, 23 May 2024 02:04:02 +0900 Subject: [PATCH 1/4] =?UTF-8?q?change:=20`manifest=5Fversion`=E3=82=92`vvm?= =?UTF-8?q?=5Fformat=5Fversion`=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/manifest.rs | 76 ++++++++++++++++++++++++---- model/sample.vvm/manifest.json | 2 +- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs index 3b17ae3f1..17d3fc48b 100644 --- a/crates/voicevox_core/src/manifest.rs +++ b/crates/voicevox_core/src/manifest.rs @@ -1,20 +1,46 @@ -use std::{collections::BTreeMap, fmt::Display, sync::Arc}; +use std::{ + collections::BTreeMap, + fmt::{self, Display}, + sync::Arc, +}; use derive_getters::Getters; use derive_more::Deref; use derive_new::new; -use serde::{Deserialize, Serialize}; +use serde::{de, Deserialize, Deserializer, Serialize}; use serde_with::{serde_as, DisplayFromStr}; use crate::StyleId; -pub type RawManifestVersion = String; -#[derive(Deserialize, Clone, Debug, PartialEq, new)] -pub struct ManifestVersion(RawManifestVersion); +#[derive(Clone)] +struct FormatVersionV1; -impl Display for ManifestVersion { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) +impl<'de> Deserialize<'de> for FormatVersionV1 { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + return deserializer.deserialize_str(Visitor); + + struct Visitor; + + impl<'de> de::Visitor<'de> for Visitor { + type Value = FormatVersionV1; + + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter.write_str("a string") + } + + fn visit_str(self, v: &str) -> Result + where + E: de::Error, + { + match v { + "1" => Ok(FormatVersionV1), + v => Err(E::custom(format!("未知の`vvm_format_version`です: `{v}`"))), + } + } + } } } @@ -41,7 +67,7 @@ pub struct Manifest { // FIXME: UUIDにする // https://github.com/VOICEVOX/voicevox_core/issues/581 #[allow(dead_code)] - manifest_version: ManifestVersion, + vvm_format_version: FormatVersionV1, metas_filename: String, #[serde(flatten)] domains: ManifestDomains, @@ -67,3 +93,35 @@ pub(crate) struct TalkManifest { pub(crate) struct StyleIdToModelInnerId( #[serde_as(as = "Arc>")] Arc>, ); + +#[cfg(test)] +mod tests { + use std::ops::Deref; + + use rstest::rstest; + use serde::Deserialize; + + use super::FormatVersionV1; + + #[rstest] + #[case("{\"vvm_format_version\":\"1\"}", Ok(()))] + #[case( + "{\"vvm_format_version\":\"2\"}", + Err("未知の`vvm_format_version`です: `2` at line 1 column 25") + )] + fn vvm_format_version_works( + #[case] input: &str, + #[case] expected: Result<(), &str>, + ) -> anyhow::Result<()> { + let actual = serde_json::from_str::(input).map_err(|e| e.to_string()); + let actual = actual.as_ref().map(|_| ()).map_err(Deref::deref); + assert_eq!(expected, actual); + return Ok(()); + + #[derive(Deserialize)] + struct ManifestPart { + #[allow(dead_code)] + vvm_format_version: FormatVersionV1, + } + } +} diff --git a/model/sample.vvm/manifest.json b/model/sample.vvm/manifest.json index 2c6721d08..81bb69d08 100644 --- a/model/sample.vvm/manifest.json +++ b/model/sample.vvm/manifest.json @@ -1,5 +1,5 @@ { - "manifest_version": "0.0.0", + "vvm_format_version": "1", "metas_filename": "metas.json", "talk": { "predict_duration_filename": "predict_duration.onnx", From 3bfac98e72a2e13d18296e3970cbcbf9e96d3a10 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Fri, 24 May 2024 22:54:25 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/manifest.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs index ee08aa660..b80d7393a 100644 --- a/crates/voicevox_core/src/manifest.rs +++ b/crates/voicevox_core/src/manifest.rs @@ -37,7 +37,10 @@ impl<'de> Deserialize<'de> for FormatVersionV1 { { match v { "1" => Ok(FormatVersionV1), - v => Err(E::custom(format!("未知の`vvm_format_version`です: `{v}`"))), + v => Err(E::custom(format!( + "`vvm_format_version={v}`とありますが、これは未知のフォーマットです。\ + 新しいバージョンのVOICEVOX COREであれば対応しているかもしれません" + ))), } } } @@ -106,7 +109,10 @@ mod tests { #[case("{\"vvm_format_version\":\"1\"}", Ok(()))] #[case( "{\"vvm_format_version\":\"2\"}", - Err("未知の`vvm_format_version`です: `2` at line 1 column 25") + Err( + "`vvm_format_version=2`とありますが、これは未知のフォーマットです。新しいバージョンの\ + VOICEVOX COREであれば対応しているかもしれません at line 1 column 25" + ) )] fn vvm_format_version_works( #[case] input: &str, From 7ed81a097c81face3f96c5343a71204c2058f8fc Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 25 May 2024 01:12:50 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/manifest.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs index b80d7393a..a7f11a537 100644 --- a/crates/voicevox_core/src/manifest.rs +++ b/crates/voicevox_core/src/manifest.rs @@ -38,8 +38,8 @@ impl<'de> Deserialize<'de> for FormatVersionV1 { match v { "1" => Ok(FormatVersionV1), v => Err(E::custom(format!( - "`vvm_format_version={v}`とありますが、これは未知のフォーマットです。\ - 新しいバージョンのVOICEVOX COREであれば対応しているかもしれません" + "未知の形式です(`vvm_format_version={v}`)。新しいバージョンのVOICEVOX \ + COREであれば対応しているかもしれません", ))), } } @@ -110,8 +110,8 @@ mod tests { #[case( "{\"vvm_format_version\":\"2\"}", Err( - "`vvm_format_version=2`とありますが、これは未知のフォーマットです。新しいバージョンの\ - VOICEVOX COREであれば対応しているかもしれません at line 1 column 25" + "未知の形式です(`vvm_format_version=2`)。新しいバージョンのVOICEVOX COREであれば対応\ + しているかもしれません at line 1 column 25", ) )] fn vvm_format_version_works( From c38b9a4745a2a3bd62ea689d511eb9e5fd693d31 Mon Sep 17 00:00:00 2001 From: Ryo Yamashita Date: Sat, 25 May 2024 02:30:51 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=87=E5=AD=97=E5=88=97=E3=81=A7?= =?UTF-8?q?=E3=81=AF=E3=81=AA=E3=81=8F=E6=95=B4=E6=95=B0=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/voicevox_core/src/manifest.rs | 14 +++++++------- model/sample.vvm/manifest.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/voicevox_core/src/manifest.rs b/crates/voicevox_core/src/manifest.rs index a7f11a537..0808a6414 100644 --- a/crates/voicevox_core/src/manifest.rs +++ b/crates/voicevox_core/src/manifest.rs @@ -20,7 +20,7 @@ impl<'de> Deserialize<'de> for FormatVersionV1 { where D: Deserializer<'de>, { - return deserializer.deserialize_str(Visitor); + return deserializer.deserialize_any(Visitor); struct Visitor; @@ -28,15 +28,15 @@ impl<'de> Deserialize<'de> for FormatVersionV1 { type Value = FormatVersionV1; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("a string") + formatter.write_str("an unsigned integer") } - fn visit_str(self, v: &str) -> Result + fn visit_u64(self, v: u64) -> Result where E: de::Error, { match v { - "1" => Ok(FormatVersionV1), + 1 => Ok(FormatVersionV1), v => Err(E::custom(format!( "未知の形式です(`vvm_format_version={v}`)。新しいバージョンのVOICEVOX \ COREであれば対応しているかもしれません", @@ -106,12 +106,12 @@ mod tests { use super::FormatVersionV1; #[rstest] - #[case("{\"vvm_format_version\":\"1\"}", Ok(()))] + #[case("{\"vvm_format_version\":1}", Ok(()))] #[case( - "{\"vvm_format_version\":\"2\"}", + "{\"vvm_format_version\":2}", Err( "未知の形式です(`vvm_format_version=2`)。新しいバージョンのVOICEVOX COREであれば対応\ - しているかもしれません at line 1 column 25", + しているかもしれません at line 1 column 23", ) )] fn vvm_format_version_works( diff --git a/model/sample.vvm/manifest.json b/model/sample.vvm/manifest.json index e49656a6d..db2ca92c1 100644 --- a/model/sample.vvm/manifest.json +++ b/model/sample.vvm/manifest.json @@ -1,5 +1,5 @@ { - "vvm_format_version": "1", + "vvm_format_version": 1, "id": "018fa5b1-146c-71e9-b523-6f6dabcf05fe", "metas_filename": "metas.json", "talk": {