Serialize RPC responses + event payloads via Void::Json (RpcDtos)
Replace the ~37 hand-built JSON strings in setupRpcHandlers and setupEventBusSubscriptions (and broadcastEvent) with reflectable DTOs in a new RpcDtos.hpp, serialized through Void::Json. This fixes a real correctness bug — track titles/artists, nicknames, playlist IDs, and play messages containing " or \ produced invalid JSON before; they are now correctly escaped (verified: `My "Song" \o/` -> `My \"Song\" \\o/`). Shapes preserved (same keys/order); the only change is absent optionals now serialize as null instead of being omitted. Build green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
75ee32a24b
commit
0779fdcf20
2 files changed
+282
-144
No files matched your search
@@ -0,0 +1,163 @@
|
||||
#pragma once
|
||||
|
||||
#include <TrackTypes.hpp>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Reflectable DTOs for the RPC responses and event-broadcast payloads. These
|
||||
// are serialized with Void::Json (reflection) instead of hand-built strings,
|
||||
// so member names are the JSON keys and values are always correctly escaped.
|
||||
namespace Echoion::Core::Dto
|
||||
{
|
||||
|
||||
// ── RPC handler responses ───────────────────────────────────────────────
|
||||
|
||||
struct Track {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::string album;
|
||||
std::optional<std::int64_t> duration; // milliseconds
|
||||
int source = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline Track toTrack(const Api::TrackInfo& t)
|
||||
{
|
||||
return Track{.id = t.id,
|
||||
.title = t.title,
|
||||
.artist = t.artist,
|
||||
.album = t.album,
|
||||
.duration = t.duration
|
||||
? std::optional<std::int64_t>(
|
||||
t.duration->count())
|
||||
: std::nullopt,
|
||||
.source = static_cast<int>(t.source)};
|
||||
}
|
||||
|
||||
struct QueueItem {
|
||||
std::uint64_t queueId = 0;
|
||||
Track track;
|
||||
bool isPlaying = false;
|
||||
};
|
||||
|
||||
struct QueueResponse {
|
||||
std::vector<QueueItem> queue;
|
||||
};
|
||||
|
||||
struct CurrentTrackResponse {
|
||||
std::optional<Track> track;
|
||||
};
|
||||
|
||||
struct Status {
|
||||
bool isPlaying = false;
|
||||
bool isPaused = false;
|
||||
float volume = 0.0f;
|
||||
bool repeat = false;
|
||||
bool shuffle = false;
|
||||
};
|
||||
|
||||
struct Success {
|
||||
bool success = true;
|
||||
};
|
||||
|
||||
struct SuccessMessage {
|
||||
bool success = true;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
struct SuccessVolume {
|
||||
bool success = true;
|
||||
float volume = 0.0f;
|
||||
};
|
||||
|
||||
// ── Event-broadcast payloads ────────────────────────────────────────────
|
||||
|
||||
struct TrackBrief {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
};
|
||||
|
||||
struct PlaybackStarted {
|
||||
TrackBrief track;
|
||||
std::int64_t position = 0;
|
||||
};
|
||||
|
||||
struct Position {
|
||||
std::int64_t position = 0;
|
||||
};
|
||||
|
||||
struct PositionProgress {
|
||||
std::int64_t position = 0;
|
||||
std::int64_t duration = 0;
|
||||
float progress = 0.0f;
|
||||
};
|
||||
|
||||
struct Volume {
|
||||
float volume = 0.0f;
|
||||
};
|
||||
|
||||
struct Shuffle {
|
||||
bool shuffle = false;
|
||||
};
|
||||
|
||||
struct Repeat {
|
||||
bool repeat = false;
|
||||
};
|
||||
|
||||
struct TrackQueued {
|
||||
std::uint64_t queueId = 0;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::uint32_t position = 0;
|
||||
std::uint32_t queueLength = 0;
|
||||
};
|
||||
|
||||
struct TrackRemoved {
|
||||
std::uint64_t queueId = 0;
|
||||
std::uint32_t queueLength = 0;
|
||||
};
|
||||
|
||||
struct QueueReordered {
|
||||
std::uint64_t queueId = 0;
|
||||
std::uint32_t oldPosition = 0;
|
||||
std::uint32_t newPosition = 0;
|
||||
};
|
||||
|
||||
struct PlaylistId {
|
||||
std::string playlistId;
|
||||
};
|
||||
|
||||
struct PlaylistTrackLoaded {
|
||||
std::string playlistId;
|
||||
std::uint32_t loaded = 0;
|
||||
std::uint32_t total = 0;
|
||||
};
|
||||
|
||||
struct PlaylistLoadCompleted {
|
||||
std::string playlistId;
|
||||
std::uint32_t totalTracks = 0;
|
||||
bool success = false;
|
||||
};
|
||||
|
||||
struct User {
|
||||
std::string uid;
|
||||
std::string nickname;
|
||||
};
|
||||
|
||||
struct ClientId {
|
||||
std::uint64_t clientId = 0;
|
||||
};
|
||||
|
||||
// Plugin-event track payload (duration in seconds, matching the legacy
|
||||
// broadcastEvent shape).
|
||||
struct EventTrack {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string artist;
|
||||
std::int64_t duration = 0;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Core::Dto
|
||||
Reference in new issue
Block a user