#pragma once template struct Differential { [[nodiscard]] static Differential Prepare(const T& aPreviousValue) noexcept; [[nodiscard]] static Differential Make(const T& aPreviousValue, const T& aNextValue) noexcept; void Serialize(TiltedPhoques::Buffer::Writer& aWriter) noexcept; void Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept; private: Differential() = default; T m_previousValue{}; std::optional m_nextValue{}; }; template Differential Differential::Prepare(const T& aPreviousValue) noexcept { Differential diff; diff.m_previousValue = aPreviousValue; return diff; } template Differential Differential::Make(const T& aPreviousValue, const T& aNextValue) noexcept { Differential diff; diff.m_previousValue = aPreviousValue; diff.m_nextValue = aNextValue; return diff; } template void Differential::Serialize(TiltedPhoques::Buffer::Writer& aWriter) noexcept { m_nextValue.GenerateDifferential(m_previousValue, aWriter); } template void Differential::Deserialize(TiltedPhoques::Buffer::Reader& aReader) noexcept { m_nextValue = m_previousValue; m_nextValue.ApplyDifferential(aReader); }