Migrate core infrastructure to VoidLibrary

This commit is contained in:
faumaray committed 2026-06-22 15:53:23 +03:00
1 parent 53801f2b53
commit 2bdb63766d
65 files changed
+16109 -12011

No files matched your search

@@ -0,0 +1,31 @@
#pragma once
#include "Types.hpp"
#include "echoion/core/state/StateVersions.hpp"
#include <cstdint>
#include <string>
namespace Echoion::Core
{
// Handles migration between state versions
class StateMigration
{
public:
// Migrate from any old version to current
static Api::Result<StateV1> migrate(uint32_t fromVersion,
const std::string& jsonData);
// Specific migrations
static StateV1 fromV0(const StateV0& v0);
// Check if migration path exists
static bool canMigrate(uint32_t fromVersion);
private:
// Migration chain: V0 -> V1 -> V2 -> ...
// Each version only knows how to migrate from previous
};
} // namespace Echoion::Core
@@ -0,0 +1,43 @@
#pragma once
#include "StateBlob.hpp"
#include "echoion/core/state/StateVersions.hpp"
#include <Types.hpp>
#include <cstdint>
#include <string>
namespace Echoion::Core
{
class StateSerializer
{
public:
// Current version being used
static constexpr uint32_t CURRENT_VERSION = 1;
// Serialize current state to opaque blob
static Api::StateBlob serialize(const StateV1& state);
// Deserialize blob to current version (handles migration)
static Api::Result<StateV1> deserialize(const Api::StateBlob& blob);
// Check if version is supported
static bool isVersionSupported(uint32_t version);
// Get supported version range
static uint32_t getMinimumSupportedVersion();
static uint32_t getCurrentVersion();
private:
// Extract version from JSON blob
static uint32_t extractVersion(const std::string& jsonStr);
// Helper to get current timestamp
static std::string getCurrentTimestampISO8601();
// Make it accessible to StateMigration
friend class StateMigration;
};
} // namespace Echoion::Core
@@ -0,0 +1,66 @@
#pragma once
#include "TrackTypes.hpp"
#include <chrono>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
namespace Echoion::Core
{
using namespace Echoion::Api;
// State V0 - Initial version (placeholder for testing migration)
struct StateV0 {
std::vector<std::string> trackIds;
float volume = 0.5f;
};
// State V1 - Current version with full playback state
struct StateV1 {
// Playback state
struct PlaybackState {
TrackInfo currentTrack;
int64_t positionMs = 0; // Use int64 for JSON compatibility
bool isPlaying = false;
bool isPaused = false;
float volume = 0.5f;
bool shuffle = false;
bool repeat = false;
};
// Queue entry with metadata
struct QueueEntryState {
TrackInfo track;
uint64_t queueId = 0;
std::string addedBy;
std::string addedAt; // ISO 8601
};
// Session state for RPC clients
struct SessionState {
uint64_t clientId = 0;
std::string authToken;
std::string lastActivity; // ISO 8601
};
// Main state
PlaybackState playback;
bool hasPlayback =
false; // Flag to indicate if playback state is valid
std::vector<QueueEntryState> queue;
std::vector<SessionState> sessions;
// Version info
uint32_t version = 1;
std::string savedAt; // ISO 8601
};
} // namespace Echoion::Core
// StateV0/StateV1 (and the nested PlaybackState/QueueEntryState/SessionState)
// are plain reflectable aggregates whose member names are the desired JSON
// keys, so Void::Json reflection serializes them with no annotations. The only
// non-reflectable member is TrackInfo, which supplies its own
// to_json()/from_json() in TrackTypes.hpp.