oxicode 0.2.2

A modern binary serialization library - successor to bincode
Documentation
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
#![allow(
    clippy::approx_constant,
    clippy::useless_vec,
    clippy::len_zero,
    clippy::unnecessary_cast,
    clippy::redundant_closure,
    clippy::too_many_arguments,
    clippy::type_complexity,
    clippy::needless_borrow,
    clippy::enum_variant_names,
    clippy::upper_case_acronyms,
    clippy::inconsistent_digit_grouping,
    clippy::unit_cmp,
    clippy::assertions_on_constants,
    clippy::iter_on_single_items,
    clippy::expect_fun_call,
    clippy::redundant_pattern_matching,
    variant_size_differences,
    clippy::absurd_extreme_comparisons,
    clippy::nonminimal_bool,
    clippy::for_kv_map,
    clippy::needless_range_loop,
    clippy::single_match,
    clippy::collapsible_if,
    clippy::needless_return,
    clippy::redundant_clone,
    clippy::map_entry,
    clippy::match_single_binding,
    clippy::bool_comparison,
    clippy::derivable_impls,
    clippy::manual_range_contains,
    clippy::needless_borrows_for_generic_args,
    clippy::manual_map,
    clippy::vec_init_then_push,
    clippy::identity_op,
    clippy::manual_flatten,
    clippy::single_char_pattern,
    clippy::search_is_some,
    clippy::option_map_unit_fn,
    clippy::while_let_on_iterator,
    clippy::clone_on_copy,
    clippy::box_collection,
    clippy::redundant_field_names,
    clippy::ptr_arg,
    clippy::large_enum_variant,
    clippy::match_ref_pats,
    clippy::needless_pass_by_value,
    clippy::unused_unit,
    clippy::let_and_return,
    clippy::suspicious_else_formatting,
    clippy::manual_strip,
    clippy::match_like_matches_macro,
    clippy::from_over_into,
    clippy::wrong_self_convention,
    clippy::inherent_to_string,
    clippy::new_without_default,
    clippy::unnecessary_wraps,
    clippy::field_reassign_with_default,
    clippy::manual_find,
    clippy::unnecessary_lazy_evaluations,
    clippy::should_implement_trait,
    clippy::missing_safety_doc,
    clippy::unusual_byte_groupings,
    clippy::bool_assert_comparison,
    clippy::zero_prefixed_literal,
    clippy::await_holding_lock,
    clippy::manual_saturating_arithmetic,
    clippy::explicit_counter_loop,
    clippy::needless_lifetimes,
    clippy::single_component_path_imports,
    clippy::uninlined_format_args,
    clippy::iter_cloned_collect,
    clippy::manual_str_repeat,
    clippy::excessive_precision,
    clippy::precedence,
    clippy::unnecessary_literal_unwrap
)]
use oxicode::{decode_from_slice, encode_to_vec, Decode, Encode};
use proptest::prelude::*;

// ── Domain Types: Robotic Surgery & Surgical Navigation ──

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct JointAngles {
    shoulder_yaw: f64,
    shoulder_pitch: f64,
    elbow: f64,
    wrist_roll: f64,
    wrist_pitch: f64,
    wrist_yaw: f64,
    gripper_aperture: f64,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct Vec3 {
    x: f64,
    y: f64,
    z: f64,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct Quaternion {
    w: f64,
    x: f64,
    y: f64,
    z: f64,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct EndEffectorPose {
    position: Vec3,
    orientation: Quaternion,
    timestamp_us: u64,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct HapticFeedback {
    force_x: f32,
    force_y: f32,
    force_z: f32,
    torque_x: f32,
    torque_y: f32,
    torque_z: f32,
    vibration_amplitude: f32,
    vibration_freq_hz: u16,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct CameraParams {
    focal_length_mm: f64,
    sensor_width_px: u32,
    sensor_height_px: u32,
    fov_horizontal_deg: f32,
    fov_vertical_deg: f32,
    white_balance_k: u16,
    exposure_us: u32,
    gain_db: f32,
    is_infrared: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct TissueDeformation {
    node_id: u32,
    displacement: Vec3,
    strain_xx: f64,
    strain_yy: f64,
    strain_zz: f64,
    strain_xy: f64,
    young_modulus_kpa: f64,
    poisson_ratio: f64,
    is_punctured: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct SuturePoint {
    entry_point: Vec3,
    exit_point: Vec3,
    tension_newtons: f32,
    thread_diameter_mm: f32,
    stitch_index: u16,
    is_knotted: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct SutureTrack {
    suture_id: u32,
    points: Vec<SuturePoint>,
    total_length_mm: f64,
    material_code: u8,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct TrocarPort {
    port_id: u8,
    insertion_site: Vec3,
    angle_deg: f32,
    diameter_mm: f32,
    depth_mm: f32,
    instrument_present: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct InsufflationReading {
    pressure_mmhg: f32,
    flow_rate_lpm: f32,
    volume_liters: f32,
    co2_concentration_pct: f32,
    timestamp_ms: u64,
    alarm_active: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
enum ElectrosurgeryMode {
    Cut {
        power_watts: f32,
    },
    Coagulate {
        power_watts: f32,
        duty_cycle_pct: u8,
    },
    Blend {
        cut_power: f32,
        coag_power: f32,
        blend_ratio: u8,
    },
    Bipolar {
        power_watts: f32,
        impedance_ohms: f32,
    },
    Standby,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct ElectrosurgerySettings {
    mode: ElectrosurgeryMode,
    activation_duration_ms: u32,
    tissue_contact: bool,
    temperature_c: f32,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct NavigationCoordinate {
    patient_space: Vec3,
    image_space: Vec3,
    confidence: f32,
    landmark_id: u16,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct RegistrationTransform {
    rotation: [f64; 9],
    translation: Vec3,
    fiducial_error_mm: f64,
    num_landmarks: u16,
    is_valid: bool,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct ToolTipDynamics {
    velocity: Vec3,
    acceleration: Vec3,
    speed_mm_per_sec: f64,
    jerk_magnitude: f64,
    timestamp_us: u64,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct CollisionVolume {
    center: Vec3,
    half_extents: Vec3,
    safety_margin_mm: f32,
    priority: u8,
    is_active: bool,
    label: String,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
enum ProcedurePhase {
    Preparation,
    Incision,
    Dissection { depth_mm: f32 },
    Resection { margin_mm: f32 },
    Hemostasis { blood_loss_ml: f32 },
    Anastomosis { stitch_count: u16 },
    Closure,
    Completed,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct BloodLossEstimate {
    cumulative_ml: f64,
    rate_ml_per_min: f32,
    sponge_count: u16,
    suction_volume_ml: f64,
    hematocrit_pct: f32,
    confidence_pct: f32,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct PostOpScore {
    operative_time_min: u32,
    estimated_blood_loss_ml: f64,
    complication_grade: u8,
    pain_score: u8,
    mobility_score: u8,
    wound_healing_grade: u8,
    readmission_risk_pct: f32,
    notes_length: u32,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct InstrumentKinematics {
    arm_id: u8,
    joints: JointAngles,
    pose: EndEffectorPose,
    dynamics: ToolTipDynamics,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct SurgicalSnapshot {
    frame_id: u64,
    phase: ProcedurePhase,
    blood_loss: BloodLossEstimate,
    insufflation: InsufflationReading,
    electrosurgery: ElectrosurgerySettings,
}

#[derive(Debug, PartialEq, Clone, Encode, Decode)]
struct ProcedureRecord {
    procedure_id: u64,
    patient_hash: u64,
    post_op: PostOpScore,
    trocar_ports: Vec<TrocarPort>,
    registration: RegistrationTransform,
}

// ── Strategies ──

prop_compose! {
    fn arb_vec3()(x in any::<f64>(), y in any::<f64>(), z in any::<f64>()) -> Vec3 {
        Vec3 { x, y, z }
    }
}

prop_compose! {
    fn arb_quaternion()(w in any::<f64>(), x in any::<f64>(), y in any::<f64>(), z in any::<f64>()) -> Quaternion {
        Quaternion { w, x, y, z }
    }
}

prop_compose! {
    fn arb_joint_angles()(
        shoulder_yaw in any::<f64>(),
        shoulder_pitch in any::<f64>(),
        elbow in any::<f64>(),
        wrist_roll in any::<f64>(),
        wrist_pitch in any::<f64>(),
        wrist_yaw in any::<f64>(),
        gripper_aperture in any::<f64>()
    ) -> JointAngles {
        JointAngles {
            shoulder_yaw, shoulder_pitch, elbow,
            wrist_roll, wrist_pitch, wrist_yaw, gripper_aperture,
        }
    }
}

prop_compose! {
    fn arb_end_effector_pose()(
        position in arb_vec3(),
        orientation in arb_quaternion(),
        timestamp_us in any::<u64>()
    ) -> EndEffectorPose {
        EndEffectorPose { position, orientation, timestamp_us }
    }
}

prop_compose! {
    fn arb_haptic_feedback()(
        force_x in any::<f32>(),
        force_y in any::<f32>(),
        force_z in any::<f32>(),
        torque_x in any::<f32>(),
        torque_y in any::<f32>(),
        torque_z in any::<f32>(),
        vibration_amplitude in any::<f32>(),
        vibration_freq_hz in any::<u16>()
    ) -> HapticFeedback {
        HapticFeedback {
            force_x, force_y, force_z,
            torque_x, torque_y, torque_z,
            vibration_amplitude, vibration_freq_hz,
        }
    }
}

prop_compose! {
    fn arb_camera_params()(
        focal_length_mm in any::<f64>(),
        sensor_width_px in any::<u32>(),
        sensor_height_px in any::<u32>(),
        fov_horizontal_deg in any::<f32>(),
        fov_vertical_deg in any::<f32>(),
        white_balance_k in any::<u16>(),
        exposure_us in any::<u32>(),
        gain_db in any::<f32>(),
        is_infrared in any::<bool>()
    ) -> CameraParams {
        CameraParams {
            focal_length_mm, sensor_width_px, sensor_height_px,
            fov_horizontal_deg, fov_vertical_deg,
            white_balance_k, exposure_us, gain_db, is_infrared,
        }
    }
}

prop_compose! {
    fn arb_tissue_deformation()(
        node_id in any::<u32>(),
        displacement in arb_vec3(),
        strain_xx in any::<f64>(),
        strain_yy in any::<f64>(),
        strain_zz in any::<f64>(),
        strain_xy in any::<f64>(),
        young_modulus_kpa in any::<f64>(),
        poisson_ratio in any::<f64>(),
        is_punctured in any::<bool>()
    ) -> TissueDeformation {
        TissueDeformation {
            node_id, displacement,
            strain_xx, strain_yy, strain_zz, strain_xy,
            young_modulus_kpa, poisson_ratio, is_punctured,
        }
    }
}

prop_compose! {
    fn arb_suture_point()(
        entry_point in arb_vec3(),
        exit_point in arb_vec3(),
        tension_newtons in any::<f32>(),
        thread_diameter_mm in any::<f32>(),
        stitch_index in any::<u16>(),
        is_knotted in any::<bool>()
    ) -> SuturePoint {
        SuturePoint {
            entry_point, exit_point,
            tension_newtons, thread_diameter_mm,
            stitch_index, is_knotted,
        }
    }
}

prop_compose! {
    fn arb_suture_track()(
        suture_id in any::<u32>(),
        points in prop::collection::vec(arb_suture_point(), 0..4),
        total_length_mm in any::<f64>(),
        material_code in any::<u8>()
    ) -> SutureTrack {
        SutureTrack { suture_id, points, total_length_mm, material_code }
    }
}

prop_compose! {
    fn arb_trocar_port()(
        port_id in any::<u8>(),
        insertion_site in arb_vec3(),
        angle_deg in any::<f32>(),
        diameter_mm in any::<f32>(),
        depth_mm in any::<f32>(),
        instrument_present in any::<bool>()
    ) -> TrocarPort {
        TrocarPort {
            port_id, insertion_site,
            angle_deg, diameter_mm, depth_mm, instrument_present,
        }
    }
}

prop_compose! {
    fn arb_insufflation()(
        pressure_mmhg in any::<f32>(),
        flow_rate_lpm in any::<f32>(),
        volume_liters in any::<f32>(),
        co2_concentration_pct in any::<f32>(),
        timestamp_ms in any::<u64>(),
        alarm_active in any::<bool>()
    ) -> InsufflationReading {
        InsufflationReading {
            pressure_mmhg, flow_rate_lpm, volume_liters,
            co2_concentration_pct, timestamp_ms, alarm_active,
        }
    }
}

fn arb_electrosurgery_mode() -> impl Strategy<Value = ElectrosurgeryMode> {
    prop_oneof![
        any::<f32>().prop_map(|p| ElectrosurgeryMode::Cut { power_watts: p }),
        (any::<f32>(), any::<u8>()).prop_map(|(p, d)| ElectrosurgeryMode::Coagulate {
            power_watts: p,
            duty_cycle_pct: d
        }),
        (any::<f32>(), any::<f32>(), any::<u8>()).prop_map(|(c, g, b)| ElectrosurgeryMode::Blend {
            cut_power: c,
            coag_power: g,
            blend_ratio: b
        }),
        (any::<f32>(), any::<f32>()).prop_map(|(p, i)| ElectrosurgeryMode::Bipolar {
            power_watts: p,
            impedance_ohms: i
        }),
        Just(ElectrosurgeryMode::Standby),
    ]
}

prop_compose! {
    fn arb_electrosurgery_settings()(
        mode in arb_electrosurgery_mode(),
        activation_duration_ms in any::<u32>(),
        tissue_contact in any::<bool>(),
        temperature_c in any::<f32>()
    ) -> ElectrosurgerySettings {
        ElectrosurgerySettings {
            mode, activation_duration_ms, tissue_contact, temperature_c,
        }
    }
}

prop_compose! {
    fn arb_navigation_coordinate()(
        patient_space in arb_vec3(),
        image_space in arb_vec3(),
        confidence in any::<f32>(),
        landmark_id in any::<u16>()
    ) -> NavigationCoordinate {
        NavigationCoordinate { patient_space, image_space, confidence, landmark_id }
    }
}

prop_compose! {
    fn arb_registration_transform()(
        rotation in prop::array::uniform9(any::<f64>()),
        translation in arb_vec3(),
        fiducial_error_mm in any::<f64>(),
        num_landmarks in any::<u16>(),
        is_valid in any::<bool>()
    ) -> RegistrationTransform {
        RegistrationTransform {
            rotation, translation, fiducial_error_mm, num_landmarks, is_valid,
        }
    }
}

prop_compose! {
    fn arb_tool_tip_dynamics()(
        velocity in arb_vec3(),
        acceleration in arb_vec3(),
        speed_mm_per_sec in any::<f64>(),
        jerk_magnitude in any::<f64>(),
        timestamp_us in any::<u64>()
    ) -> ToolTipDynamics {
        ToolTipDynamics {
            velocity, acceleration, speed_mm_per_sec, jerk_magnitude, timestamp_us,
        }
    }
}

prop_compose! {
    fn arb_collision_volume()(
        center in arb_vec3(),
        half_extents in arb_vec3(),
        safety_margin_mm in any::<f32>(),
        priority in any::<u8>(),
        is_active in any::<bool>(),
        label in "[a-zA-Z0-9_]{0,16}"
    ) -> CollisionVolume {
        CollisionVolume {
            center, half_extents, safety_margin_mm, priority, is_active, label,
        }
    }
}

fn arb_procedure_phase() -> impl Strategy<Value = ProcedurePhase> {
    prop_oneof![
        Just(ProcedurePhase::Preparation),
        Just(ProcedurePhase::Incision),
        any::<f32>().prop_map(|d| ProcedurePhase::Dissection { depth_mm: d }),
        any::<f32>().prop_map(|m| ProcedurePhase::Resection { margin_mm: m }),
        any::<f32>().prop_map(|b| ProcedurePhase::Hemostasis { blood_loss_ml: b }),
        any::<u16>().prop_map(|s| ProcedurePhase::Anastomosis { stitch_count: s }),
        Just(ProcedurePhase::Closure),
        Just(ProcedurePhase::Completed),
    ]
}

prop_compose! {
    fn arb_blood_loss()(
        cumulative_ml in any::<f64>(),
        rate_ml_per_min in any::<f32>(),
        sponge_count in any::<u16>(),
        suction_volume_ml in any::<f64>(),
        hematocrit_pct in any::<f32>(),
        confidence_pct in any::<f32>()
    ) -> BloodLossEstimate {
        BloodLossEstimate {
            cumulative_ml, rate_ml_per_min, sponge_count,
            suction_volume_ml, hematocrit_pct, confidence_pct,
        }
    }
}

prop_compose! {
    fn arb_post_op_score()(
        operative_time_min in any::<u32>(),
        estimated_blood_loss_ml in any::<f64>(),
        complication_grade in any::<u8>(),
        pain_score in any::<u8>(),
        mobility_score in any::<u8>(),
        wound_healing_grade in any::<u8>(),
        readmission_risk_pct in any::<f32>(),
        notes_length in any::<u32>()
    ) -> PostOpScore {
        PostOpScore {
            operative_time_min, estimated_blood_loss_ml,
            complication_grade, pain_score, mobility_score,
            wound_healing_grade, readmission_risk_pct, notes_length,
        }
    }
}

prop_compose! {
    fn arb_instrument_kinematics()(
        arm_id in any::<u8>(),
        joints in arb_joint_angles(),
        pose in arb_end_effector_pose(),
        dynamics in arb_tool_tip_dynamics()
    ) -> InstrumentKinematics {
        InstrumentKinematics { arm_id, joints, pose, dynamics }
    }
}

prop_compose! {
    fn arb_surgical_snapshot()(
        frame_id in any::<u64>(),
        phase in arb_procedure_phase(),
        blood_loss in arb_blood_loss(),
        insufflation in arb_insufflation(),
        electrosurgery in arb_electrosurgery_settings()
    ) -> SurgicalSnapshot {
        SurgicalSnapshot { frame_id, phase, blood_loss, insufflation, electrosurgery }
    }
}

prop_compose! {
    fn arb_procedure_record()(
        procedure_id in any::<u64>(),
        patient_hash in any::<u64>(),
        post_op in arb_post_op_score(),
        trocar_ports in prop::collection::vec(arb_trocar_port(), 0..5),
        registration in arb_registration_transform()
    ) -> ProcedureRecord {
        ProcedureRecord {
            procedure_id, patient_hash, post_op, trocar_ports, registration,
        }
    }
}

// ── Tests ──

#[test]
fn test_joint_angles_roundtrip() {
    proptest!(|(val in arb_joint_angles())| {
        let encoded = encode_to_vec(&val).expect("encode joint angles failed");
        let (decoded, _) = decode_from_slice::<JointAngles>(&encoded)
            .expect("decode joint angles failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_end_effector_pose_roundtrip() {
    proptest!(|(val in arb_end_effector_pose())| {
        let encoded = encode_to_vec(&val).expect("encode end effector pose failed");
        let (decoded, _) = decode_from_slice::<EndEffectorPose>(&encoded)
            .expect("decode end effector pose failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_haptic_feedback_roundtrip() {
    proptest!(|(val in arb_haptic_feedback())| {
        let encoded = encode_to_vec(&val).expect("encode haptic feedback failed");
        let (decoded, _) = decode_from_slice::<HapticFeedback>(&encoded)
            .expect("decode haptic feedback failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_camera_params_roundtrip() {
    proptest!(|(val in arb_camera_params())| {
        let encoded = encode_to_vec(&val).expect("encode camera params failed");
        let (decoded, _) = decode_from_slice::<CameraParams>(&encoded)
            .expect("decode camera params failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_tissue_deformation_roundtrip() {
    proptest!(|(val in arb_tissue_deformation())| {
        let encoded = encode_to_vec(&val).expect("encode tissue deformation failed");
        let (decoded, _) = decode_from_slice::<TissueDeformation>(&encoded)
            .expect("decode tissue deformation failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_suture_point_roundtrip() {
    proptest!(|(val in arb_suture_point())| {
        let encoded = encode_to_vec(&val).expect("encode suture point failed");
        let (decoded, _) = decode_from_slice::<SuturePoint>(&encoded)
            .expect("decode suture point failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_suture_track_roundtrip() {
    proptest!(|(val in arb_suture_track())| {
        let encoded = encode_to_vec(&val).expect("encode suture track failed");
        let (decoded, _) = decode_from_slice::<SutureTrack>(&encoded)
            .expect("decode suture track failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_trocar_port_roundtrip() {
    proptest!(|(val in arb_trocar_port())| {
        let encoded = encode_to_vec(&val).expect("encode trocar port failed");
        let (decoded, _) = decode_from_slice::<TrocarPort>(&encoded)
            .expect("decode trocar port failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_insufflation_reading_roundtrip() {
    proptest!(|(val in arb_insufflation())| {
        let encoded = encode_to_vec(&val).expect("encode insufflation reading failed");
        let (decoded, _) = decode_from_slice::<InsufflationReading>(&encoded)
            .expect("decode insufflation reading failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_electrosurgery_settings_roundtrip() {
    proptest!(|(val in arb_electrosurgery_settings())| {
        let encoded = encode_to_vec(&val).expect("encode electrosurgery settings failed");
        let (decoded, _) = decode_from_slice::<ElectrosurgerySettings>(&encoded)
            .expect("decode electrosurgery settings failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_navigation_coordinate_roundtrip() {
    proptest!(|(val in arb_navigation_coordinate())| {
        let encoded = encode_to_vec(&val).expect("encode navigation coordinate failed");
        let (decoded, _) = decode_from_slice::<NavigationCoordinate>(&encoded)
            .expect("decode navigation coordinate failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_registration_transform_roundtrip() {
    proptest!(|(val in arb_registration_transform())| {
        let encoded = encode_to_vec(&val).expect("encode registration transform failed");
        let (decoded, _) = decode_from_slice::<RegistrationTransform>(&encoded)
            .expect("decode registration transform failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_tool_tip_dynamics_roundtrip() {
    proptest!(|(val in arb_tool_tip_dynamics())| {
        let encoded = encode_to_vec(&val).expect("encode tool tip dynamics failed");
        let (decoded, _) = decode_from_slice::<ToolTipDynamics>(&encoded)
            .expect("decode tool tip dynamics failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_collision_volume_roundtrip() {
    proptest!(|(val in arb_collision_volume())| {
        let encoded = encode_to_vec(&val).expect("encode collision volume failed");
        let (decoded, _) = decode_from_slice::<CollisionVolume>(&encoded)
            .expect("decode collision volume failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_procedure_phase_roundtrip() {
    proptest!(|(val in arb_procedure_phase())| {
        let encoded = encode_to_vec(&val).expect("encode procedure phase failed");
        let (decoded, _) = decode_from_slice::<ProcedurePhase>(&encoded)
            .expect("decode procedure phase failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_blood_loss_estimate_roundtrip() {
    proptest!(|(val in arb_blood_loss())| {
        let encoded = encode_to_vec(&val).expect("encode blood loss estimate failed");
        let (decoded, _) = decode_from_slice::<BloodLossEstimate>(&encoded)
            .expect("decode blood loss estimate failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_post_op_score_roundtrip() {
    proptest!(|(val in arb_post_op_score())| {
        let encoded = encode_to_vec(&val).expect("encode post op score failed");
        let (decoded, _) = decode_from_slice::<PostOpScore>(&encoded)
            .expect("decode post op score failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_instrument_kinematics_roundtrip() {
    proptest!(|(val in arb_instrument_kinematics())| {
        let encoded = encode_to_vec(&val).expect("encode instrument kinematics failed");
        let (decoded, _) = decode_from_slice::<InstrumentKinematics>(&encoded)
            .expect("decode instrument kinematics failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_surgical_snapshot_roundtrip() {
    proptest!(|(val in arb_surgical_snapshot())| {
        let encoded = encode_to_vec(&val).expect("encode surgical snapshot failed");
        let (decoded, _) = decode_from_slice::<SurgicalSnapshot>(&encoded)
            .expect("decode surgical snapshot failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_procedure_record_roundtrip() {
    proptest!(|(val in arb_procedure_record())| {
        let encoded = encode_to_vec(&val).expect("encode procedure record failed");
        let (decoded, _) = decode_from_slice::<ProcedureRecord>(&encoded)
            .expect("decode procedure record failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_vec_collision_volumes_roundtrip() {
    proptest!(|(val in prop::collection::vec(arb_collision_volume(), 0..6))| {
        let encoded = encode_to_vec(&val).expect("encode collision volume vec failed");
        let (decoded, _) = decode_from_slice::<Vec<CollisionVolume>>(&encoded)
            .expect("decode collision volume vec failed");
        prop_assert_eq!(val, decoded);
    });
}

#[test]
fn test_multi_arm_kinematics_roundtrip() {
    proptest!(|(arms in prop::collection::vec(arb_instrument_kinematics(), 1..4),
                camera in arb_camera_params(),
                nav_points in prop::collection::vec(arb_navigation_coordinate(), 0..5))| {
        let combined: (Vec<InstrumentKinematics>, CameraParams, Vec<NavigationCoordinate>) =
            (arms, camera, nav_points);
        let encoded = encode_to_vec(&combined).expect("encode multi-arm scene failed");
        let (decoded, _) = decode_from_slice::<(
            Vec<InstrumentKinematics>,
            CameraParams,
            Vec<NavigationCoordinate>,
        )>(&encoded)
            .expect("decode multi-arm scene failed");
        prop_assert_eq!(combined, decoded);
    });
}