#pragma once #include #include #include #include namespace Void::RPC { struct WireVersion { std::uint16_t major{kWireMajorV1}; std::uint16_t minor{kWireMinorV1}; [[nodiscard]] bool operator==(const WireVersion&) const noexcept = default; }; inline constexpr WireVersion kCurrentWireVersion{kWireMajorV1, kWireMinorV1}; enum class WireVersionCompatibility : std::uint8_t { Same, /// The peer speaks a newer minor: unknown optional extensions are /// length-skipped, so the exchange stays compatible. PeerNewerMinor, /// The peer speaks an older minor: omit fields it cannot know. PeerOlderMinor, /// Different major: the wire formats are not interoperable. IncompatibleMajor }; [[nodiscard]] WireVersionCompatibility negotiate_wire_version(WireVersion peer, WireVersion local = kCurrentWireVersion) noexcept; /// Migrate a decoded envelope to the local wire version. /// /// Compatible minors are accepted (the envelope's fields are already /// interpreted by the decoder); a different major fails with /// RpcStatusCode::IncompatibleVersion. The returned envelope reports the /// local version so later stages never see a foreign minor. [[nodiscard]] Void::Result::Result migrate_envelope(WireEnvelope envelope, WireVersion local = kCurrentWireVersion); } // namespace Void::RPC