RPC: Wire version negotiation and envelope migration (S-RPC-05)

This commit is contained in:
faumaray committed 2026-12-03 20:03:18 +03:00
1 parent 2c026ea30c
commit 9ab482dc5d
3 files changed
+144

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#pragma once
#include <Void/Functional/Result.hpp>
#include <Void/RPC/Codec.hpp>
#include <Void/RPC/Types.hpp>
#include <cstdint>
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<WireEnvelope>
migrate_envelope(WireEnvelope envelope,
WireVersion local = kCurrentWireVersion);
} // namespace Void::RPC