Skip to content

Conversation

@joaquinbejar
Copy link
Owner

@joaquinbejar joaquinbejar commented Sep 24, 2025

Add Snapshot Serialization, Checksum Validation, and Reconstruction for PriceLevel

Description

This pull request introduces snapshot-based serialization, deserialization, and checksum validation mechanisms for the PriceLevel data structure. The implementation ensures data integrity during persistence and transmission by leveraging SHA-256 checksums. Additionally, new methods enable reconstruction of PriceLevel instances from snapshots, snapshot packages, and JSON representations. Comprehensive error handling and test coverage have been added to validate correctness across different scenarios.


Changes Made

  • Snapshot & Package Handling

    • Added PriceLevelSnapshotPackage struct to encapsulate snapshots with checksum validation.
    • Implemented JSON-based serialization and deserialization for snapshots and packages.
    • Exposed PriceLevelSnapshotPackage in module exports.
  • Checksum Validation

    • Integrated checksum computation and validation using the sha2 crate.
    • Added methods for refreshing aggregates and validating integrity across serialized data.
  • Reconstruction

    • Implemented reconstruction of PriceLevel from:
      • PriceLevelSnapshot
      • PriceLevelSnapshotPackage
      • JSON representations
    • Ensured order position preservation during reconstruction.
  • Error Handling

    • Added new error variants in PriceLevelError:
      • SerializationError
      • DeserializationError
      • ChecksumMismatch
    • Updated fmt::Display for better error reporting.
  • Testing

    • Added unit tests for:
      • Serialization and deserialization of snapshots and packages.
      • Checksum validation and error handling for mismatches.
      • Reconstruction from snapshots, packages, and JSON.
      • Roundtrip consistency of snapshot serialization/deserialization.
  • Versioning & Dependencies

    • Bumped crate version to 0.3.2.
    • Added sha2 as a new dependency.

Testing

  • Unit Tests
    • Verified roundtrip serialization and deserialization for PriceLevelSnapshot and PriceLevelSnapshotPackage.
    • Validated checksum correctness and error handling for mismatched cases.
    • Confirmed accurate reconstruction of PriceLevel from snapshots and JSON formats.
  • Edge Cases
    • Tested corrupted/mismatched checksums.
    • Verified snapshot reconstruction with multiple orders.

Additional Notes

  • The introduction of checksum validation significantly improves resilience against corrupted or tampered data.
  • These changes lay the foundation for more advanced persistence and distributed synchronization mechanisms.
  • Follow-up work may include benchmarking snapshot serialization performance under heavy loads.

References


Checklist

  • Code changes reviewed and tested.
  • Unit tests added for all new functionality.
  • Documentation updated with new APIs and usage examples.
  • Crate version bumped to 0.4.0.
  • All tests passing.

Introduced a `PriceLevelSnapshotPackage` struct to support checksum validation and JSON serialization/deserialization. Added methods for computing checksums, refreshing aggregates, validating data integrity, and migrating between serialized formats.
…cksum handling

Introduced `SerializationError`, `DeserializationError`, and `ChecksumMismatch` variants to enhance error handling related to data serialization and integrity validation. Updated `fmt::Display` implementations to support the new error types.
Implemented methods for reconstructing `PriceLevel` from snapshots, snapshot packages, and JSON representations. Added support for serializing `PriceLevel` to checksum-protected packages and JSON formats.
…rialization, deserialization, and checksum validation

Expanded test coverage to include roundtrip validation, error handling for checksum mismatches, and JSON-based snapshot restoration for `PriceLevel` and `PriceLevelSnapshotPackage`.
… packages

Enhanced `PriceLevel` implementation with a `From<PriceLevelSnapshot>` conversion. Included new tests to verify order position preservation during reconstruction from snapshots and snapshot packages.
@joaquinbejar joaquinbejar merged commit d6cfa97 into main Sep 24, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants