scientific_workflow/persistence/local/json_payload_decoder/vec_f64.rs
1//! JSON decoding for a state field whose concrete payload is `Vec<f64>`.
2//!
3//! [`JsonVecF64Decoder`] converts exactly one raw JSON field value into an owned
4//! vector of double-precision values. The
5//! [`StoredStateSeriesReader`](crate::persistence::advanced::StoredStateSeriesReader)
6//! remains responsible for finding the field by key, selecting this decoder,
7//! and inserting the returned vector into the matching state slot.
8//!
9//! The expected JSON representation is an array of JSON numbers accepted by
10//! Serde JSON for `f64`, for example `[1.0,-2.5,3.25]`.
11//! Deserialization allocates the final vector directly and does not first build
12//! a [`serde_json::Value`] tree. An empty array is valid. JSON `null`, scalar
13//! values, nested arrays, and non-numeric elements are rejected by Serde.
14//!
15//! This decoder performs no key lookup, record parsing, state mutation,
16//! filesystem access, or domain-specific validation of vector length and
17//! values. Applications needing constraints such as a fixed dimension or a
18//! finite-only vector should register a custom decoder for that key.
19
20use super::JsonPayloadDecoder;
21
22/// Stateless default decoder for payloads stored as `Vec<f64>`.
23///
24/// The unit struct is zero-sized and may be copied freely while configuring
25/// decoder registries. Each registry entry still binds it to exactly one key
26/// and the concrete `Vec<f64>` output type.
27#[derive(Clone, Copy, Debug, Default)]
28pub struct JsonVecF64Decoder;
29
30impl JsonPayloadDecoder<Vec<f64>> for JsonVecF64Decoder {
31 type Error = serde_json::Error;
32
33 /// Deserializes one complete raw JSON array directly into `Vec<f64>`.
34 ///
35 /// The returned vector owns its allocation. On failure, the original
36 /// `serde_json::Error` is returned so the decoder registry can retain it as
37 /// the source of a stream-, index-, and key-aware persistence error.
38 fn decode_json_payload(&self, raw_json: &str) -> Result<Vec<f64>, Self::Error> {
39 serde_json::from_str(raw_json)
40 }
41}