Files
Rediska/rediska/common/QueueMessage.hpp
Nikita Astafyev 35a6349071
Some checks failed
Code Analysis / analysis (push) Failing after 2m59s
chore: initial commit
2025-12-30 22:34:58 +07:00

43 lines
1.3 KiB
C++

#pragma once
#include <variant>
#include <vector>
#include "rediska/common/enums.hpp"
#include "rediska/common/types.hpp"
#include "rediska/common/MessageArguments.hpp"
#include <grpcpp/grpcpp.h>
#include <grpcpp/support/async_stream.h> // for ServerAsyncStreamingInterface completeness
// TODO: get rid of forward declaration somehow maybe
struct BaseRequestManager;
struct RequestEvent {
BaseRequestManager& manager;
};
// This just leaves the responder for you to delete.
struct FinishEvent {
std::unique_ptr<grpc::internal::ServerAsyncStreamingInterface> responder;
};
using EventVariant = std::variant<RequestEvent, FinishEvent>;
struct QueueMessage {
CacheValueId type;
CacheKey key;
OperationId operation;
MessageArguments arguments;
std::unique_ptr<grpc::internal::ServerAsyncStreamingInterface> responder;
template<typename ResponseT>
void respond(ResponseT response) {
if (auto* writer = dynamic_cast<grpc::ServerAsyncResponseWriter<ResponseT>*>(responder.get())) {
writer->Finish(response, grpc::Status::OK, std::make_unique<EventVariant>(FinishEvent { std::move(responder) }).release());
responder = nullptr;
} else {
throw std::runtime_error("Invalid responder type in QueueMessage::respond");
}
}
};