snapshot_storage.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "snapshot.h"
  3. namespace sunrise::server::bap::encrypted::push::snapshot {
  4. /** Prior live payload prefixes that a new preparation may not overwrite. */
  5. struct Reservation {
  6. std::size_t rawWriteOffset{};
  7. std::size_t compressedWriteOffset{};
  8. std::size_t rawClearSize{};
  9. std::size_t compressedClearSize{};
  10. };
  11. /**
  12. * Finds payload prefixes borrowed by a caller's earlier prepared snapshot.
  13. * @param scratch Raw and compressed snapshot storage owned by the lock.
  14. * @param prepared Caller output that may still hold a live prepared snapshot.
  15. * @return Checked write offsets and carried-over cleanup extents, or an empty reservation.
  16. */
  17. [[nodiscard]] Reservation reserve_prior(const Scratch& scratch, const Prepared& prepared) noexcept;
  18. /**
  19. * Wipes the staging tails but keeps a reserved prior snapshot valid.
  20. * @param scratch Raw and compressed snapshot storage owned by the lock.
  21. * @param reservation Prefixes whose live payload bytes must survive rejection.
  22. */
  23. void clear_after(Scratch& scratch, const Reservation& reservation) noexcept;
  24. /**
  25. * Publishes a finished snapshot and re-points its object span at the caller's storage.
  26. * @param staged Finished internal snapshot whose descriptors borrow scratch buffers.
  27. * @param output Gets the snapshot only when the staged storage is valid.
  28. * @return True when the staged object view belongs to its own descriptor array.
  29. */
  30. [[nodiscard]] bool commit(const Prepared& staged, Prepared& output) noexcept;
  31. } // namespace sunrise::server::bap::encrypted::push::snapshot