40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
//
|
|
// Created by Kirill Zhukov on 20.04.2025.
|
|
//
|
|
|
|
#include "Wal.h"
|
|
|
|
namespace usub::utils
|
|
{
|
|
WAL::WAL(const std::string& filename)
|
|
{
|
|
this->out.open(filename, std::ios::binary | std::ios::app);
|
|
if (!this->out.is_open()) throw std::runtime_error("Failed to open WAL");
|
|
}
|
|
|
|
void WAL::write_put(const Hash128& key, const std::string& value)
|
|
{
|
|
uint8_t op = 0;
|
|
uint32_t value_len = value.size();
|
|
this->out.write(reinterpret_cast<const char*>(&op), sizeof(op));
|
|
this->out.write(reinterpret_cast<const char*>(&key), sizeof(key));
|
|
this->out.write(reinterpret_cast<const char*>(&value_len), sizeof(value_len));
|
|
this->out.write(value.data(), value_len);
|
|
this->out.flush();
|
|
}
|
|
|
|
void WAL::write_delete(const Hash128& key)
|
|
{
|
|
uint8_t op = 1;
|
|
this->out.write(reinterpret_cast<const char*>(&op), sizeof(op));
|
|
this->out.write(reinterpret_cast<const char*>(&key), sizeof(key));
|
|
this->out.flush();
|
|
}
|
|
|
|
void WAL::close()
|
|
{
|
|
this->out.close();
|
|
}
|
|
} // utils
|
|
// usub
|