rs-teststand-serde 0.0.2

Serialize a National Instruments TestStand™ PropertyObject tree to and from any serde format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
//! A serialisable mirror of a `PropertyObject` tree.

use std::collections::BTreeMap;

use rs_teststand::{Error, PropValType, PropertyObject, PropertyRepresentation};

/// Create-or-update: `PropOption_InsertIfMissing`.
const INSERT_IF_MISSING: i32 = 1;

/// Default options: `PropOption_NoOptions`.
const NO_OPTIONS: i32 = 0;

/// The prefix the engine emits for each base, paired with that base.
///
/// `0c` for octal is the engine's own choice, not C's bare leading zero, which
/// is why a generic parser would misread it.
const RADIX_PREFIXES: [(&str, u32); 3] = [("0x", 16), ("0b", 2), ("0c", 8)];

/// `printf` conversion characters that select a base other than ten.
const RADIX_CONVERSIONS: [char; 4] = ['x', 'X', 'o', 'b'];

/// One value from a `PropertyObject` tree, in a form serde can handle.
///
/// The representation is untagged, so the serialized form is ordinary data — a
/// container becomes an object, an array becomes a list, a scalar becomes a
/// scalar — rather than something carrying wrapper keys.
///
/// The engine distinguishes three numeric storages and matches them strictly,
/// so they are separate variants here: collapsing them to one would lose the
/// exactness that [`Integer`](Self::Integer) and [`Unsigned`](Self::Unsigned)
/// exist to provide.
///
/// Variant order matters for deserialisation: serde tries untagged variants top
/// to bottom, so an integral JSON number is read as [`Integer`](Self::Integer)
/// and only a value too large for `i64` falls through to
/// [`Unsigned`](Self::Unsigned), with fractional values reaching
/// [`Number`](Self::Number).
///
/// # Representation is not round-trip stable through plain JSON
///
/// JSON has one number type, so a value that fits both signed and unsigned —
/// `0`, or anything up to `i64::MAX` — comes back as [`Integer`](Self::Integer)
/// even if it left as [`Unsigned`](Self::Unsigned). The *number* is preserved
/// exactly; only the engine's choice of storage is not.
///
/// This is a property of the wire format, not a defect here, and it is the
/// price of emitting ordinary JSON instead of tagged objects. It matters only
/// when rebuilding a property whose representation must be unsigned: read the
/// representation from the live
/// [`PropertyObjectType`](rs_teststand::PropertyObjectType) rather than inferring it
/// from deserialized JSON. Values above `i64::MAX` are unambiguous and do
/// survive.
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum PropertyValue {
    /// No value.
    ///
    /// Produced for any non-finite number. The engine names three of these:
    /// `NAN` (not a number), `IND` (indeterminate — a special quiet NaN, from
    /// operations such as `Sqrt(-1)`, which the engine treats as equivalent to
    /// `NAN` in comparisons), and `INF`.
    ///
    /// JSON cannot write any of them, and inventing an encoding would force
    /// every consumer to learn it, so they all serialize as `null` — which any
    /// language already understands. An empty object reference is *not* null
    /// here: it round-trips as the string `"Nothing"`, so a reference stays
    /// distinguishable from a missing number.
    Null,
    /// A boolean.
    Bool(bool),
    /// A number stored as a signed 64-bit integer.
    Integer(i64),
    /// A number stored as an unsigned 64-bit integer.
    Unsigned(u64),
    /// A number stored as a double.
    Number(f64),
    /// A string.
    Text(String),
    /// An array. TestStand arrays are homogeneous.
    Array(Vec<Self>),
    /// A container, keyed by sub-property name.
    ///
    /// Ordered rather than hashed so a serialized tree is stable between runs
    /// and diffable.
    Container(BTreeMap<String, Self>),
}

impl PropertyValue {
    /// The `PropValType` to create a sub-property with for this value.
    ///
    /// Numeric variants all map to `Number`: the engine decides representation
    /// when the value is written, so the distinction is carried by the setter
    /// rather than by the creation type.
    fn creation_type(&self) -> PropValType {
        match self {
            Self::Bool(_) => PropValType::Boolean,
            // A null carries no type of its own; Number is the only kind that
            // can hold one (as NAN), so that is what it recreates.
            Self::Null | Self::Integer(_) | Self::Unsigned(_) | Self::Number(_) => {
                PropValType::Number
            }
            Self::Text(_) => PropValType::String,
            Self::Container(_) => PropValType::Container,
            // An empty array has no element type to inspect; a container is the
            // most permissive choice and matches how the tree is rebuilt.
            Self::Array(items) => items
                .first()
                .map_or(PropValType::Container, Self::creation_type),
        }
    }
}

/// The flat offset of an element, given the array's shape and the indices.
///
/// Column-major: the first index varies fastest, so
/// `offset = i0 + d0*(i1 + d1*(i2 + ...))`.
fn column_major_offset(lengths: &[i32], indices: &[i32]) -> i32 {
    let mut offset = 0;
    let mut stride = 1;
    for (length, index) in lengths.iter().zip(indices.iter()) {
        offset += index * stride;
        stride *= *length;
    }
    offset
}

/// Parses a radix-prefixed string back into a number.
///
/// Recognises what the engine emits: `0x` for hexadecimal, `0b` for binary and
/// the engine's own `0c` for octal. Anything else is a genuine string and is
/// left alone, so a value that merely begins with `0` is not mangled.
fn parse_radix(text: &str) -> Option<f64> {
    let trimmed = text.trim();
    let (negative, digits) = trimmed
        .strip_prefix('-')
        .map_or((false, trimmed), |rest| (true, rest));

    let lowered = digits.to_ascii_lowercase();
    let (radix, body) = RADIX_PREFIXES
        .into_iter()
        .find_map(|(prefix, radix)| lowered.strip_prefix(prefix).map(|rest| (radix, rest)))?;
    let magnitude = i64::from_str_radix(body, radix).ok()?;
    // i64 -> f64 is exact up to 2^53; beyond that the value was never a
    // faithful `Number` in the first place.
    #[allow(clippy::cast_precision_loss, reason = "engine numbers are f64 already")]
    let value = magnitude as f64;
    Some(if negative { -value } else { value })
}

/// Whether a numeric format selects a base other than ten.
///
/// Only these carry information a bare number cannot: a value shown as `0xa`
/// was authored in hex, and rendering it as `10` loses that intent. Width and
/// precision formats (`%.3f`, `%+.13e`) are presentation of the same decimal
/// value, so they stay numbers.
fn is_radix_format(format: &str) -> bool {
    let mut characters = format.chars();
    while let Some(character) = characters.next() {
        if character != '%' {
            continue;
        }
        // Skip flags, width and precision to reach the conversion character.
        for following in characters.by_ref() {
            if following.is_ascii_alphabetic() {
                return RADIX_CONVERSIONS.contains(&following);
            }
        }
    }
    false
}

/// Reading a `PropertyObject` tree out as data, and writing data back into one.
///
/// An extension trait rather than inherent methods, because this is an addition
/// to the COM API rather than part of it: `PropertyObject` is defined in
/// [`rs_teststand`], and only its own crate may add inherent methods to it. The
/// split is deliberate — the binding mirrors TestStand™ and nothing else, so a
/// consumer that never serialises anything carries no serde dependency.
///
/// ```no_run
/// use rs_teststand::Engine;
/// use rs_teststand_serde::PropertyObjectValue;
///
/// let engine = Engine::new()?;
/// let json = serde_json::to_string_pretty(&engine.globals()?.to_value()?)?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub trait PropertyObjectValue {
    /// Walks this property into a [`PropertyValue`].
    ///
    /// # Errors
    /// [`Error`] if any COM call fails.
    fn to_value(&self) -> Result<PropertyValue, Error>;

    /// Rebuilds this container's contents from a [`PropertyValue`].
    ///
    /// # Errors
    /// [`Error`] if `value` is not a container, or if any COM call fails.
    fn apply_value(&self, value: &PropertyValue) -> Result<(), Error>;
}

impl PropertyObjectValue for PropertyObject {
    /// Walks this property into a [`PropertyValue`].
    ///
    /// Arrays are read element by element, containers are recursed into, and a
    /// scalar is read through the accessor its representation requires — an
    /// `Int64` property is read as an integer rather than being forced through
    /// the floating-point accessor, which the engine would refuse.
    ///
    /// # Errors
    /// [`Error`] if any COM call fails.
    fn to_value(&self) -> Result<PropertyValue, Error> {
        let property_type = self.property_type()?;
        let value_type = property_type.value_type()?;

        // Arrays first: an array of numbers still reports Number as its type.
        if matches!(value_type, Ok(PropValType::Array)) {
            let lengths = property_type.array_dimensions()?.lengths()?;
            return array_to_value(self, &lengths);
        }

        // A container, or anything that behaves like one (a named type instance
        // reports its own type but is still a bag of fields).
        let sub_properties = self.get_num_sub_properties("")?;
        if matches!(value_type, Ok(PropValType::Container)) || sub_properties > 0 {
            let mut members = BTreeMap::new();
            for index in 0..sub_properties {
                let name = self.get_nth_sub_property_name("", index, NO_OPTIONS)?;
                let child = self.get_property_object(&name, NO_OPTIONS)?;
                members.insert(name, child.to_value()?);
            }
            return Ok(PropertyValue::Container(members));
        }

        match value_type {
            Ok(PropValType::Boolean) => Ok(PropertyValue::Bool(self.get_val_bool("", NO_OPTIONS)?)),
            Ok(PropValType::Number) => number_to_value(self, &property_type),
            // Strings read directly. Anything else that is still a leaf —
            // an object reference, an enumeration — is not a string and
            // `GetValString` refuses it, so fall back to the formatted value,
            // which the engine guarantees to produce for any object ("Nothing"
            // for an empty reference).
            Ok(PropValType::String) => {
                Ok(PropertyValue::Text(self.get_val_string("", NO_OPTIONS)?))
            }
            _ => Ok(PropertyValue::Text(
                self.get_val_string("", NO_OPTIONS)
                    .or_else(|_| self.get_formatted_value("", 0, "", true, ", "))?,
            )),
        }
    }

    /// Rebuilds this container's contents from a [`PropertyValue`].
    ///
    /// Existing sub-properties of the same name are updated in place; the
    /// container is not cleared first.
    ///
    /// # Errors
    /// [`Error`] if `value` is not a container, or if any COM call fails.
    fn apply_value(&self, value: &PropertyValue) -> Result<(), Error> {
        let PropertyValue::Container(members) = value else {
            return Err(Error::UnexpectedType {
                expected: "Container",
                actual: "scalar or array",
            });
        };
        for (name, member) in members {
            set_member(self, name, member)?;
        }
        Ok(())
    }
}

/// Builds a value for an array, nesting one level per dimension.
///
/// Elements are stored **column-major**: the first index varies fastest, so
/// a 10x2 array puts `[0][1]` at flat offset 10, not 1. Emitting them in
/// storage order would transpose the result, so the offset is computed from
/// the indices rather than walked linearly.
fn array_to_value(object: &PropertyObject, lengths: &[i32]) -> Result<PropertyValue, Error> {
    match lengths {
        // Not an array after all, or a shape the engine did not report.
        [] => Ok(PropertyValue::Array(Vec::new())),
        [single] => {
            let mut items = Vec::with_capacity((*single).max(0).try_into().unwrap_or(0));
            for offset in 0..*single {
                items.push(
                    object
                        .get_property_object_by_offset(offset, NO_OPTIONS)?
                        .to_value()?,
                );
            }
            Ok(PropertyValue::Array(items))
        }
        _ => {
            let mut indices = vec![0_i32; lengths.len()];
            nest(object, lengths, 0, &mut indices)
        }
    }
}

/// Recursively nests one dimension, outermost first.
fn nest(
    object: &PropertyObject,
    lengths: &[i32],
    depth: usize,
    indices: &mut Vec<i32>,
) -> Result<PropertyValue, Error> {
    let Some(&length) = lengths.get(depth) else {
        return Ok(PropertyValue::Array(Vec::new()));
    };
    let mut items = Vec::with_capacity(length.max(0).try_into().unwrap_or(0));
    for index in 0..length {
        if let Some(slot) = indices.get_mut(depth) {
            *slot = index;
        }
        if depth + 1 == lengths.len() {
            let offset = column_major_offset(lengths, indices);
            items.push(
                object
                    .get_property_object_by_offset(offset, NO_OPTIONS)?
                    .to_value()?,
            );
        } else {
            items.push(nest(object, lengths, depth + 1, indices)?);
        }
    }
    Ok(PropertyValue::Array(items))
}

/// Reads a numeric scalar, honouring its representation and display format.
///
/// Three cases the plain accessor cannot express:
///
/// * `NAN`, `INF` and `-INF` become [`PropertyValue::Null`] — JSON cannot
///   write them.
/// * A value whose format selects a radix (`%x`, `%o`, `%b`) becomes the
///   formatted string, so `10` under `%#x` serialises as `"0xa"` and the
///   author's chosen base survives the round trip.
/// * `Int64` and `UInt64` use their own accessors, which the engine
///   requires.
fn number_to_value(
    object: &PropertyObject,
    property_type: &rs_teststand::PropertyObjectType,
) -> Result<PropertyValue, Error> {
    match property_type.representation()? {
        Ok(PropertyRepresentation::Int64) => {
            return Ok(PropertyValue::Integer(
                object.get_val_integer64("", NO_OPTIONS)?,
            ));
        }
        Ok(PropertyRepresentation::UInt64) => {
            return Ok(PropertyValue::Unsigned(
                object.get_val_unsigned_integer64("", NO_OPTIONS)?,
            ));
        }
        _ => {}
    }

    let number = object.get_val_number("", NO_OPTIONS)?;
    // Covers NAN, IND and both infinities in one test: IND is a quiet NaN,
    // so the engine's three special constants are all non-finite.
    if !number.is_finite() {
        return Ok(PropertyValue::Null);
    }
    if is_radix_format(&object.numeric_format()?) {
        return Ok(PropertyValue::Text(
            object.get_formatted_value("", NO_OPTIONS, "", true, "")?,
        ));
    }
    Ok(PropertyValue::Number(number))
}

/// Creates or updates one sub-property from a value.
fn set_member(object: &PropertyObject, name: &str, value: &PropertyValue) -> Result<(), Error> {
    match value {
        // A null restores the engine's own "not a number": that is what it
        // came from, and what a consumer means by null in this position.
        PropertyValue::Null => object.set_val_number(name, INSERT_IF_MISSING, f64::NAN),
        PropertyValue::Bool(flag) => object.set_val_bool(name, INSERT_IF_MISSING, *flag),
        PropertyValue::Number(number) => object.set_val_number(name, INSERT_IF_MISSING, *number),
        PropertyValue::Integer(number) => {
            object.set_val_integer64(name, INSERT_IF_MISSING, *number)
        }
        PropertyValue::Unsigned(number) => {
            object.set_val_unsigned_integer64(name, INSERT_IF_MISSING, *number)
        }
        // A radix string such as "0xa" came from a number, not a string, so
        // it is parsed back rather than stored as text.
        PropertyValue::Text(text) => parse_radix(text).map_or_else(
            || object.set_val_string(name, INSERT_IF_MISSING, text),
            |number| object.set_val_number(name, INSERT_IF_MISSING, number),
        ),
        PropertyValue::Container(_) => {
            if !object.exists(name, NO_OPTIONS)? {
                object.new_sub_property(
                    name,
                    PropValType::Container,
                    false,
                    "",
                    INSERT_IF_MISSING,
                )?;
            }
            object
                .get_property_object(name, NO_OPTIONS)?
                .apply_value(value)
        }
        PropertyValue::Array(items) => set_array_member(object, name, items),
    }
}

/// Creates or updates an array sub-property and fills its elements.
fn set_array_member(
    object: &PropertyObject,
    name: &str,
    items: &[PropertyValue],
) -> Result<(), Error> {
    let element_type = items
        .first()
        .map_or(PropValType::Container, PropertyValue::creation_type);
    if !object.exists(name, NO_OPTIONS)? {
        object.new_sub_property(name, element_type, true, "", INSERT_IF_MISSING)?;
    }
    let array = object.get_property_object(name, NO_OPTIONS)?;
    let count = i32::try_from(items.len()).map_err(|_| Error::UnexpectedType {
        expected: "an array length within i32",
        actual: "a longer array",
    })?;
    array.set_num_elements(count, NO_OPTIONS)?;

    for (offset, item) in items.iter().enumerate() {
        let offset = i32::try_from(offset).unwrap_or(i32::MAX);
        let element = array.get_property_object_by_offset(offset, NO_OPTIONS)?;
        match item {
            PropertyValue::Container(_) => element.apply_value(item)?,
            PropertyValue::Bool(flag) => element.set_val_bool("", NO_OPTIONS, *flag)?,
            PropertyValue::Number(number) => element.set_val_number("", NO_OPTIONS, *number)?,
            PropertyValue::Integer(number) => {
                element.set_val_integer64("", NO_OPTIONS, *number)?;
            }
            PropertyValue::Unsigned(number) => {
                element.set_val_unsigned_integer64("", NO_OPTIONS, *number)?;
            }
            PropertyValue::Null => element.set_val_number("", NO_OPTIONS, f64::NAN)?,
            PropertyValue::Text(text) => match parse_radix(text) {
                Some(number) => element.set_val_number("", NO_OPTIONS, number)?,
                None => element.set_val_string("", NO_OPTIONS, text)?,
            },
            PropertyValue::Array(_) => {
                return Err(Error::UnexpectedType {
                    expected: "a scalar or container array element",
                    actual: "a nested array",
                });
            }
        }
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use std::collections::BTreeMap;

    use super::PropertyValue;

    type JsonResult<T> = Result<T, serde_json::Error>;

    fn json(value: &PropertyValue) -> JsonResult<String> {
        serde_json::to_string(value)
    }

    fn parse(text: &str) -> JsonResult<PropertyValue> {
        serde_json::from_str(text)
    }

    #[test]
    fn scalars_serialise_as_plain_json() -> JsonResult<()> {
        // Untagged: no wrapper keys, so the output is ordinary data.
        assert_eq!(json(&PropertyValue::Bool(true))?, "true");
        assert_eq!(
            json(&PropertyValue::Text("SN-001".to_owned()))?,
            "\"SN-001\""
        );
        assert_eq!(json(&PropertyValue::Number(1.5))?, "1.5");
        assert_eq!(json(&PropertyValue::Integer(-7))?, "-7");
        Ok(())
    }

    #[test]
    fn an_integral_number_parses_as_integer_not_float() -> JsonResult<()> {
        // Variant order decides this. Reading 42 as a float would lose the
        // exactness the integer representations exist to provide.
        assert_eq!(parse("42")?, PropertyValue::Integer(42));
        assert_eq!(parse("-42")?, PropertyValue::Integer(-42));
        Ok(())
    }

    #[test]
    fn a_value_beyond_i64_falls_through_to_unsigned() -> JsonResult<()> {
        // u64::MAX does not fit in i64, so Integer must fail and Unsigned catch
        // it — exactly the case a double would corrupt.
        assert_eq!(
            parse("18446744073709551615")?,
            PropertyValue::Unsigned(u64::MAX)
        );
        Ok(())
    }

    #[test]
    fn a_fractional_number_reaches_the_float_variant() -> JsonResult<()> {
        assert_eq!(parse("1.5")?, PropertyValue::Number(1.5));
        Ok(())
    }

    #[test]
    fn the_64bit_extremes_survive_a_json_round_trip() -> JsonResult<()> {
        for value in [
            PropertyValue::Integer(i64::MIN),
            PropertyValue::Integer(i64::MAX),
            PropertyValue::Unsigned(u64::MAX),
        ] {
            assert_eq!(parse(&json(&value)?)?, value, "lost {value:?}");
        }
        Ok(())
    }

    #[test]
    fn a_container_round_trips_with_stable_key_order() -> JsonResult<()> {
        let mut members = BTreeMap::new();
        members.insert("Zebra".to_owned(), PropertyValue::Integer(1));
        members.insert("Alpha".to_owned(), PropertyValue::Bool(false));
        let value = PropertyValue::Container(members);

        // BTreeMap keeps keys sorted, so serialized output is diffable.
        assert_eq!(json(&value)?, r#"{"Alpha":false,"Zebra":1}"#);
        assert_eq!(parse(&json(&value)?)?, value);
        Ok(())
    }

    #[test]
    fn nested_arrays_and_containers_round_trip() -> JsonResult<()> {
        let mut inner = BTreeMap::new();
        inner.insert("Mode".to_owned(), PropertyValue::Text("Voltage".to_owned()));
        let mut outer = BTreeMap::new();
        outer.insert(
            "Readings".to_owned(),
            PropertyValue::Array(vec![PropertyValue::Number(1.5), PropertyValue::Number(2.5)]),
        );
        outer.insert("Instrument".to_owned(), PropertyValue::Container(inner));
        let value = PropertyValue::Container(outer);
        assert_eq!(parse(&json(&value)?)?, value);
        Ok(())
    }
}

#[cfg(test)]
mod representation_tests {
    use super::PropertyValue;

    /// Pins the documented limitation so it stays a known trade-off rather than
    /// becoming a surprise.
    #[test]
    fn json_collapses_unsigned_into_signed_where_the_value_fits() -> Result<(), serde_json::Error> {
        let unsigned = PropertyValue::Unsigned(0);
        let text = serde_json::to_string(&unsigned)?;
        let parsed: PropertyValue = serde_json::from_str(&text)?;
        // The number survives; the storage choice does not.
        assert_eq!(parsed, PropertyValue::Integer(0));
        assert_ne!(parsed, unsigned);
        Ok(())
    }

    #[test]
    fn a_value_above_i64_max_keeps_its_unsigned_identity() -> Result<(), serde_json::Error> {
        // Unambiguous: no signed variant can hold it, so nothing is lost.
        let unsigned = PropertyValue::Unsigned(u64::MAX);
        let parsed: PropertyValue = serde_json::from_str(&serde_json::to_string(&unsigned)?)?;
        assert_eq!(parsed, unsigned);
        Ok(())
    }
}