Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: manifest_versionvvm_format_version #794

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
@@ -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<D>(deserializer: D) -> Result<Self, D::Error>
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<E>(self, v: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
match v {
"1" => Ok(FormatVersionV1),
v => Err(E::custom(format!("未知の`vvm_format_version`です: `{v}`"))),
}
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

Expand All @@ -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,
Expand All @@ -67,3 +93,35 @@ pub(crate) struct TalkManifest {
pub(crate) struct StyleIdToModelInnerId(
#[serde_as(as = "Arc<BTreeMap<DisplayFromStr, _>>")] Arc<BTreeMap<StyleId, ModelInnerId>>,
);

#[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::<ManifestPart>(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,
}
}
}
2 changes: 1 addition & 1 deletion model/sample.vvm/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"manifest_version": "0.0.0",
"vvm_format_version": "1",
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
"metas_filename": "metas.json",
"talk": {
"predict_duration_filename": "predict_duration.onnx",
Expand Down
Loading