1use serde::{Serialize, de::DeserializeOwned};
20#[derive(Clone, Copy, Debug)]
31pub struct SchemaSettings {
32 pub preparation_bytes: std::num::NonZeroUsize,
33 pub preparation_work: std::num::NonZeroUsize,
34}
35
36#[derive(Clone, Copy, Debug)]
37pub struct StreamSettings {
38 pub items: std::num::NonZeroUsize,
39 pub bytes: std::num::NonZeroUsize,
40}
41
42#[derive(Debug, thiserror::Error)]
45pub enum ConfigError {
46 #[error("artifact configuration could not be encoded: {0}")]
47 Encode(serde_json::Error),
48
49 #[error("artifact configuration could not be decoded: {0}")]
50 Decode(serde_json::Error),
51}
52
53impl Default for SchemaSettings {
58 fn default() -> Self {
59 Self {
60 preparation_bytes: std::num::NonZeroUsize::new(4 * 1024 * 1024).unwrap(),
62 preparation_work: std::num::NonZeroUsize::new(1024 * 1024).unwrap(),
63 }
64 }
65}
66
67pub fn decode_config<C: DeserializeOwned>(bytes: &[u8]) -> Result<C, ConfigError> {
70 serde_json::from_slice(bytes).map_err(ConfigError::Decode)
71}
72
73pub fn validate_config(bytes: &[u8]) -> Result<(), ConfigError> {
74 decode_config::<serde::de::IgnoredAny>(bytes).map(|_| ())
75}
76
77pub fn encode_config<C: Serialize>(config: &C) -> Result<Vec<u8>, ConfigError> {
78 serde_json::to_vec(config).map_err(ConfigError::Encode)
79}
80
81