[M3] codec+galaxy: MxValueKind::for_data_type + GalaxyTagMetadata::resolve_write_kind

Last codec-side prerequisite before F13 (NmxClient high-level write
wrappers) can land. Two small additions, both wire-byte-direct ports
of the .NET reference's MxDataType → MxValueKind lookup logic.

mxaccess-codec
- MxValueKind::for_data_type(MxDataType, is_array) -> Option<MxValueKind>:
  fuses NmxWriteMessage.cs:58-86 (TryGetValueKind's 12 base mappings
  for data types 1..=6 scalar+array) with the two scalar fallbacks the
  .NET GalaxyTagMetadata.ProjectWriteValue layers on top
  (GalaxyRepositoryTagResolver.cs:65-69): ElapsedTime → Int32,
  InternationalizedString → String. Returns None for any other
  combination — including arrays of those two types and unsupported
  scalars (ReferenceType, StatusType, Enum, etc.).
- 6 new tests covering the base table, both fallbacks, the array-of-
  unsupported rejection, and the no-mapping branch for ReferenceType /
  StatusType / Enum / DataQualityType / BigString / Unknown / NoData /
  End sentinels.

mxaccess-galaxy
- GalaxyTagMetadata::resolve_write_kind() -> Result<MxValueKind,
  UnsupportedDataType>: pure delegation to MxValueKind::for_data_type
  + a typed error carrying (mx_data_type, is_array) for diagnostics.
- GalaxyTagMetadata::is_writable() — Ok-side accessor for browse UIs.
- UnsupportedDataType public error type (re-exported from lib.rs).
- 7 new tests: Double scalar → Float64, Boolean array → BoolArray,
  ElapsedTime scalar → Int32 (the fallback path), array-of-ElapsedTime
  rejected, InternationalizedString → String, ReferenceType rejected,
  Unknown sentinel rejected.

Test count delta: 446 -> 459 (+13; codec 215 -> 221, galaxy 49 -> 56).
All four DoD gates green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-05 08:33:42 -04:00
parent baea6eaa41
commit 68aa2e30ab
3 changed files with 307 additions and 9 deletions
+177
View File
@@ -116,6 +116,61 @@ impl MxValueKind {
pub fn to_u8(self) -> u8 {
self as u8
}
/// Map a model-side `(MxDataType, is_array)` pair to the wire-side
/// `MxValueKind` the LMX server expects on a Write body.
///
/// Mirrors `NmxWriteMessage.GetValueKind` + `TryGetValueKind`
/// (`NmxWriteMessage.cs:58-86`) **plus** the two scalar fallbacks the
/// .NET `GalaxyTagMetadata.ProjectWriteValue`
/// (`GalaxyRepositoryTagResolver.cs:53-72`) layers on top:
///
/// - `ElapsedTime` (scalar) → `Int32`. The .NET reference converts a
/// `TimeSpan` value to `int totalMilliseconds` at `cs:67-68`; the
/// wire kind is `Int32` regardless of the source CLR type.
/// - `InternationalizedString` (scalar) → `String`
/// (`cs:69`).
///
/// Returns `None` for any other combination — including arrays of
/// `ElapsedTime` / `InternationalizedString` / `Enum` / `BigString`,
/// which the .NET reference explicitly rejects at `cs:60-63`.
///
/// The 12 base mappings (data types 1..=6, scalar and array each):
///
/// ```text
/// (Boolean, false) → Boolean (Boolean, true) → BoolArray
/// (Integer, false) → Int32 (Integer, true) → Int32Array
/// (Float, false) → Float32 (Float, true) → Float32Array
/// (Double, false) → Float64 (Double, true) → Float64Array
/// (String, false) → String (String, true) → StringArray
/// (Time, false) → DateTime (Time, true) → DateTimeArray
/// ```
#[must_use]
pub fn for_data_type(data_type: MxDataType, is_array: bool) -> Option<MxValueKind> {
match (data_type, is_array) {
(MxDataType::Boolean, false) => Some(MxValueKind::Boolean),
(MxDataType::Integer, false) => Some(MxValueKind::Int32),
(MxDataType::Float, false) => Some(MxValueKind::Float32),
(MxDataType::Double, false) => Some(MxValueKind::Float64),
(MxDataType::String, false) => Some(MxValueKind::String),
(MxDataType::Time, false) => Some(MxValueKind::DateTime),
(MxDataType::Boolean, true) => Some(MxValueKind::BoolArray),
(MxDataType::Integer, true) => Some(MxValueKind::Int32Array),
(MxDataType::Float, true) => Some(MxValueKind::Float32Array),
(MxDataType::Double, true) => Some(MxValueKind::Float64Array),
(MxDataType::String, true) => Some(MxValueKind::StringArray),
(MxDataType::Time, true) => Some(MxValueKind::DateTimeArray),
// ProjectWriteValue scalar fallbacks (`cs:65-69`):
(MxDataType::ElapsedTime, false) => Some(MxValueKind::Int32),
(MxDataType::InternationalizedString, false) => Some(MxValueKind::String),
// Everything else (arrays of unsupported types, or unsupported
// scalars like ReferenceType / StatusType / Enum / etc.) is
// rejected. Mirrors the `_ => Return(default, out valueKind,
// success: false)` arm at `cs:84` plus the
// `ArgumentOutOfRangeException` paths at `cs:62,70`.
_ => None,
}
}
}
/// Attribute-model data type — port of `MxDataType.cs:3-24`.
@@ -468,4 +523,126 @@ mod tests {
assert_eq!(MxDataType::default(), MxDataType::Unknown);
assert_eq!(MxDataType::default().to_i16(), -1);
}
#[test]
fn for_data_type_scalar_base_table() {
// Mirrors NmxWriteMessage.cs:72-77 (scalar arms of TryGetValueKind).
assert_eq!(
MxValueKind::for_data_type(MxDataType::Boolean, false),
Some(MxValueKind::Boolean)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Integer, false),
Some(MxValueKind::Int32)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Float, false),
Some(MxValueKind::Float32)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Double, false),
Some(MxValueKind::Float64)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::String, false),
Some(MxValueKind::String)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Time, false),
Some(MxValueKind::DateTime)
);
}
#[test]
fn for_data_type_array_base_table() {
// Mirrors NmxWriteMessage.cs:78-83 (array arms of TryGetValueKind).
assert_eq!(
MxValueKind::for_data_type(MxDataType::Boolean, true),
Some(MxValueKind::BoolArray)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Integer, true),
Some(MxValueKind::Int32Array)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Float, true),
Some(MxValueKind::Float32Array)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Double, true),
Some(MxValueKind::Float64Array)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::String, true),
Some(MxValueKind::StringArray)
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::Time, true),
Some(MxValueKind::DateTimeArray)
);
}
#[test]
fn for_data_type_elapsed_time_scalar_falls_back_to_int32() {
// GalaxyRepositoryTagResolver.cs:67-68: ElapsedTime scalar maps to
// Int32 (caller is expected to convert TimeSpan to milliseconds).
assert_eq!(
MxValueKind::for_data_type(MxDataType::ElapsedTime, false),
Some(MxValueKind::Int32)
);
}
#[test]
fn for_data_type_internationalized_string_scalar_falls_back_to_string() {
// GalaxyRepositoryTagResolver.cs:69.
assert_eq!(
MxValueKind::for_data_type(MxDataType::InternationalizedString, false),
Some(MxValueKind::String)
);
}
#[test]
fn for_data_type_array_of_unsupported_returns_none() {
// GalaxyRepositoryTagResolver.cs:60-63 explicitly rejects array of
// unsupported types — no fallback applies in the array case.
assert_eq!(
MxValueKind::for_data_type(MxDataType::ElapsedTime, true),
None
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::InternationalizedString, true),
None
);
assert_eq!(MxValueKind::for_data_type(MxDataType::Enum, true), None);
assert_eq!(
MxValueKind::for_data_type(MxDataType::BigString, true),
None
);
}
#[test]
fn for_data_type_unsupported_scalars_return_none() {
// ReferenceType, StatusType, Enum, etc. are not in either the base
// table or the ProjectWriteValue fallbacks → None.
assert_eq!(
MxValueKind::for_data_type(MxDataType::ReferenceType, false),
None
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::StatusType, false),
None
);
assert_eq!(MxValueKind::for_data_type(MxDataType::Enum, false), None);
assert_eq!(
MxValueKind::for_data_type(MxDataType::DataQualityType, false),
None
);
assert_eq!(
MxValueKind::for_data_type(MxDataType::BigString, false),
None
);
assert_eq!(MxValueKind::for_data_type(MxDataType::Unknown, false), None);
assert_eq!(MxValueKind::for_data_type(MxDataType::NoData, false), None);
assert_eq!(MxValueKind::for_data_type(MxDataType::End, false), None);
}
}