SharedStorage/core/Command.h
2025-04-20 21:58:42 +03:00

77 lines
2.1 KiB
C++

//
// Created by Kirill Zhukov on 20.04.2025.
//
#ifndef COMMAND_H
#define COMMAND_H
#include <cstdint>
#include <atomic>
#include "utils/hash/Hash128.h"
namespace usub::core
{
enum class OperationType : uint8_t
{
PUT = 0,
DELETE = 1,
FIND = 2,
UNKNOWN = 0xFF
};
struct Command
{
std::atomic<uint8_t> ready;
OperationType op;
utils::Hash128 key;
uint32_t value_size;
char value[1024];
std::atomic<uint8_t> response_ready;
uint32_t response_size;
char response[1024];
Command()
{
ready.store(0, std::memory_order_relaxed);
response_ready.store(0, std::memory_order_relaxed);
op = OperationType::PUT;
key = utils::Hash128{};
value_size = 0;
response_size = 0;
}
Command(const Command& other)
{
ready.store(other.ready.load(std::memory_order_relaxed), std::memory_order_relaxed);
op = other.op;
key = other.key;
value_size = other.value_size;
std::memcpy(value, other.value, other.value_size);
response_ready.store(other.response_ready.load(std::memory_order_relaxed), std::memory_order_relaxed);
response_size = other.response_size;
std::memcpy(response, other.response, other.response_size);
}
Command& operator=(const Command& other)
{
if (this != &other)
{
ready.store(other.ready.load(std::memory_order_relaxed), std::memory_order_relaxed);
op = other.op;
key = other.key;
value_size = other.value_size;
std::memcpy(value, other.value, other.value_size);
response_ready.store(other.response_ready.load(std::memory_order_relaxed), std::memory_order_relaxed);
response_size = other.response_size;
std::memcpy(response, other.response, other.response_size);
}
return *this;
}
};
}
#endif // COMMAND_H