Skip to content

RON serde does not round-trip fixed-N interpolator data #53

Description

@kylecarow

InterpDataNDBase round-trips through RON. Every fixed-N type fails, in both the
plain and Nested serialization formats:

Data1D   derived    FAIL 2:11: Expected opening `[`
Data1D   nested     FAIL 2:11: Expected opening `[`
DataND   derived    OK
DataND   nested     FAIL 2:11: Expected opening `[`
Interp1D derived    FAIL 3:15: Expected opening `[`
Interp1D nested     FAIL 3:15: Expected opening `[`

Cause

InterpDataBase<D, N> stores its grid as [ArrayBase<D, Ix1>; N], a fixed-size array.
Serde treats that as a tuple, so RON writes (...), but deserialize_fixed asks for a
sequence and RON's deserializer then requires [...]. InterpDataNDBase is unaffected
because its grid is a Vec<ArrayBase<D, Ix1>>, which serializes as a sequence either way.

The Nested path fails for the same reason: GridArrWrapper also wraps the fixed-size
array.

Repro

Add ron as a dev-dependency, then:

let data = Interp1D::new(
    array![0., 1., 2.],
    array![0.0, 0.4, 0.8],
    strategy::Linear,
    Extrapolate::Error,
)
.unwrap()
.data;

let s = ron::to_string(&data).unwrap();
ron::from_str::<ninterp::data::InterpData1D<f64>>(&s).unwrap(); // panics

Scope

Pre-existing, not a regression: reproduces identically on main and on every released
version that has the fixed-N grid. JSON and bincode are unaffected, since neither
distinguishes tuples from sequences on the wire. Not currently covered by
tests/serde_formats.rs, which tests JSON and bincode only.

Possible fixes

  • Serialize the fixed-size grid as a sequence rather than a tuple (a custom
    serialize_with on the grid field, mirroring what deserialize_fixed already
    expects). Changes the RON output shape; leaves JSON and bincode output identical.
  • Accept both tuple and sequence input in deserialize_fixed, leaving the output shape
    alone. Fixes reading but leaves RON output asymmetric with InterpDataNDBase.
  • Document RON as unsupported and leave it.

Worth deciding alongside whether tests/serde_formats.rs should cover a third,
self-describing format at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions