#include "rpc_server.hpp" #include #include #include auto slige_rpc::BufferedWriter::write(std::string message) -> Res { for (size_t i = 0; i < message.length(); ++i) { auto res = this->write((uint8_t)message[i]); if (!res.is_ok()) { return res.err(); } } return Unit {}; } auto slige_rpc::BufferedWriter::write(uint8_t byte) -> Res { if (this->occupied >= length) { auto res = this->flush(); if (!res.is_ok()) { return res.err(); } } this->buffer[this->occupied] = byte; return Unit {}; } auto slige_rpc::BufferedWriter::flush() -> Res { auto result = ::write(this->fd, this->buffer, this->occupied); if (result < 0) { return { { "unable to write" } }; } this->occupied = 0; return (size_t)result; }