Skip to main content

muse_code_sdk/msp/method/lifecycle/
session_resume_input_assets.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use serde::Deserialize;
4use serde::Deserializer;
5use serde::Serialize;
6use serde::Serializer;
7
8/// What a cold load does when a retained input image file is missing or
9/// corrupt. Omitted means `fail`.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub enum MissingInputAssets {
13    /// Refuse the resume, as before this member existed.
14    Fail,
15    /// Resume, put a text marker in each such image's place, and list the
16    /// images in `unavailableInputAssets`.
17    Report,
18}
19
20/// One retained input image a `report` load replaced with a marker. It names no
21/// run: each digest is listed once.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24#[non_exhaustive]
25pub struct UnavailableInputAsset {
26    /// The sha256 of the stored image bytes, lowercase hex.
27    pub digest: String,
28    /// The stored media type, e.g. `image/png`.
29    pub media_type: String,
30    pub byte_length: u64,
31    pub width: u64,
32    pub height: u64,
33    pub reason: UnavailableInputAssetReason,
34    /// The client's own name for the image, when its part carried one.
35    #[serde(default, skip_serializing_if = "Option::is_none")]
36    pub client_ref: Option<ClientRef>,
37}
38
39/// A client's own name for an image part: 1 to 256 bytes of UTF-8, returned
40/// verbatim. Open, so a later optional member decodes on an older client.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase")]
43pub struct ClientRef {
44    pub name: String,
45}
46
47/// Why the image was replaced. Open: a newer host's word decodes to `Unknown`.
48#[derive(Debug, Clone, PartialEq, Eq)]
49#[non_exhaustive]
50pub enum UnavailableInputAssetReason {
51    /// No file at the asset's path.
52    Missing,
53    /// The file fails its length, digest or image-metadata check.
54    Corrupt,
55    /// A value from a newer host, kept verbatim; never construct it with a
56    /// known word.
57    Unknown(String),
58}
59
60impl UnavailableInputAssetReason {
61    /// The exact wire spelling, including a value from a newer host.
62    fn as_str(&self) -> &str {
63        match self {
64            Self::Missing => "missing",
65            Self::Corrupt => "corrupt",
66            Self::Unknown(value) => value,
67        }
68    }
69}
70
71impl Serialize for UnavailableInputAssetReason {
72    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
73    where
74        S: Serializer,
75    {
76        serializer.serialize_str(self.as_str())
77    }
78}
79
80impl<'de> Deserialize<'de> for UnavailableInputAssetReason {
81    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
82    where
83        D: Deserializer<'de>,
84    {
85        let value = String::deserialize(deserializer)?;
86        Ok(match value.as_str() {
87            "missing" => Self::Missing,
88            "corrupt" => Self::Corrupt,
89            _ => Self::Unknown(value),
90        })
91    }
92}