feat(server): Buffered streamer + use on stable state (#639)

This commit is contained in:
Vladislav 2023-01-15 12:17:04 +03:00 committed by GitHub
parent 7b7e3ea9d4
commit 7eff61c9ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 236 additions and 49 deletions

View file

@ -18,26 +18,18 @@ using namespace std;
namespace dfly {
std::error_code JournalWriter::Flush(io::Sink* sink) {
if (auto ec = sink->Write(buf_.InputBuffer()); ec)
return ec;
buf_.Clear();
return {};
}
base::IoBuf& JournalWriter::Accumulated() {
return buf_;
JournalWriter::JournalWriter(io::Sink* sink) : sink_{sink} {
}
void JournalWriter::Write(uint64_t v) {
uint8_t buf[10];
unsigned len = WritePackedUInt(v, buf);
buf_.WriteAndCommit(buf, len);
sink_->Write(io::Bytes{buf}.first(len));
}
void JournalWriter::Write(std::string_view sv) {
Write(sv.size());
buf_.WriteAndCommit(sv.data(), sv.size());
sink_->Write(io::Buffer(sv));
}
void JournalWriter::Write(CmdArgList args) {