fixed serializing/deserializing
This commit is contained in:
parent
5d0d64f895
commit
162ee2076d
@ -45,30 +45,29 @@ namespace usub::core {
|
||||
}
|
||||
|
||||
void Command::serialize(std::ostream &out) const {
|
||||
auto op_val = static_cast<uint8_t>(op);
|
||||
auto op_val = static_cast<uint8_t>(this->op);
|
||||
out.write(reinterpret_cast<const char *>(&op_val), sizeof(op_val));
|
||||
out.write(reinterpret_cast<const char *>(&key), sizeof(key));
|
||||
out.write(reinterpret_cast<const char *>(&value_size), sizeof(value_size));
|
||||
out.write(value, value_size);
|
||||
out.write(reinterpret_cast<const char *>(&response_size), sizeof(response_size));
|
||||
out.write(response, response_size);
|
||||
out.write(reinterpret_cast<const char *>(&this->key), sizeof(this->key));
|
||||
out.write(reinterpret_cast<const char *>(&this->value_size), sizeof(this->value_size));
|
||||
out.write(this->value, sizeof(this->value));
|
||||
out.write(reinterpret_cast<const char *>(&this->response_size), sizeof(this->response_size));
|
||||
out.write(this->response, sizeof(this->response));
|
||||
}
|
||||
|
||||
Command Command::deserialize(std::istream &in) {
|
||||
Command cmd;
|
||||
|
||||
uint8_t op_val;
|
||||
uint8_t op_val = 0;
|
||||
in.read(reinterpret_cast<char *>(&op_val), sizeof(op_val));
|
||||
cmd.op = static_cast<OperationType>(op_val);
|
||||
|
||||
in.read(reinterpret_cast<char *>(&cmd.key), sizeof(cmd.key));
|
||||
|
||||
in.read(reinterpret_cast<char *>(&cmd.value_size), sizeof(cmd.value_size));
|
||||
if (cmd.value_size > 0)
|
||||
in.read(cmd.value, cmd.value_size);
|
||||
in.read(cmd.value, sizeof(cmd.value));
|
||||
|
||||
in.read(reinterpret_cast<char *>(&cmd.response_size), sizeof(cmd.response_size));
|
||||
if (cmd.response_size > 0)
|
||||
in.read(cmd.response, cmd.response_size);
|
||||
in.read(cmd.response, sizeof(cmd.response));
|
||||
|
||||
cmd.ready.store(1, std::memory_order_relaxed);
|
||||
cmd.response_ready.store(1, std::memory_order_relaxed);
|
||||
|
7
main.cpp
7
main.cpp
@ -94,13 +94,6 @@ int main() {
|
||||
using namespace usub::core;
|
||||
usub::core::DatabaseManager manager("../config.toml");
|
||||
manager.run_all();
|
||||
|
||||
// std::cout << sizeof(usub::core::SharedCommandQueue) << ", " << SharedCommandQueue::calculate_shm_size(1024) << "\n";
|
||||
// usub::core::SharedMemoryManager shm_manager{"rates_1", SharedCommandQueue::calculate_shm_size(1024)};
|
||||
// new(shm_manager.base_ptr()) SharedCommandQueue(1024);
|
||||
// auto* queue = static_cast<usub::core::SharedCommandQueue*>(shm_manager.base_ptr());
|
||||
// auto* cmd = queue->peek(0);
|
||||
// std::cout << cmd->ready.load() << '\n';
|
||||
}
|
||||
catch (const std::exception &ex) {
|
||||
std::cerr << "Fatal error: " << ex.what() << std::endl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user