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 all commits
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
82 changes: 73 additions & 9 deletions crates/voicevox_core/src/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
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, VoiceModelId};

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_any(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("an unsigned integer")
}

fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: de::Error,
{
match v {
1 => Ok(FormatVersionV1),
v => Err(E::custom(format!(
"未知の形式です(`vvm_format_version={v}`)。新しいバージョンのVOICEVOX \
COREであれば対応しているかもしれません",
))),
}
}
}
}
}

Expand All @@ -39,7 +68,7 @@ impl Display for InnerVoiceId {
#[derive(Deserialize, Getters, Clone)]
pub struct Manifest {
#[allow(dead_code)]
manifest_version: ManifestVersion,
vvm_format_version: FormatVersionV1,
pub(crate) id: VoiceModelId,
metas_filename: String,
#[serde(flatten)]
Expand All @@ -66,3 +95,38 @@ pub(crate) struct TalkManifest {
pub(crate) struct StyleIdToInnerVoiceId(
#[serde_as(as = "Arc<BTreeMap<DisplayFromStr, _>>")] Arc<BTreeMap<StyleId, InnerVoiceId>>,
);

#[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`)。新しいバージョンのVOICEVOX COREであれば対応\
しているかもしれません at line 1 column 23",
)
)]
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,
"id": "018fa5b1-146c-71e9-b523-6f6dabcf05fe",
"metas_filename": "metas.json",
"talk": {
Expand Down
Loading