anicraft-format: add write_version for explicit envelope version (#2420)

This commit is contained in:
Dylan M. Taylor
2026-11-19 14:00:33 -05:00
committed by GitHub
parent 8dbe9705ff
commit 08da5e1486
+6 -1
View File
@@ -34,7 +34,12 @@ struct EnvelopeOut<'a, P, T> {
/// Serializes the envelope in its stable wire order and uses AniCraft's compact/pretty threshold.
pub fn write<P: Serialize, T: Serialize>(generator: &str, paths: &[P], document: &T) -> Result<String, serde_json::Error> {
let envelope = EnvelopeOut { format: FORMAT_NAME, version: FORMAT_VERSION, generator, paths, document };
write_version(FORMAT_VERSION, generator, paths, document)
}
/// Serializes the envelope with an explicit format version and AniCraft's compact/pretty threshold.
pub fn write_version<P: Serialize, T: Serialize>(version: u32, generator: &str, paths: &[P], document: &T) -> Result<String, serde_json::Error> {
let envelope = EnvelopeOut { format: FORMAT_NAME, version, generator, paths, document };
let compact = serde_json::to_string(&envelope)?;
if compact.len() < PRETTY_LIMIT { serde_json::to_string_pretty(&envelope) } else { Ok(compact) }
}