client/Response: add method Fmt() based on libfmt

This commit is contained in:
Max Kellermann
2021-05-21 20:35:29 +02:00
parent a9c704b76e
commit 0440c41cba
27 changed files with 241 additions and 195 deletions

View File

@@ -22,6 +22,8 @@
#include "util/FormatString.hxx"
#include "util/AllocatedString.hxx"
#include <fmt/format.h>
TagMask
Response::GetTagMask() const noexcept
{
@@ -56,17 +58,21 @@ Response::Format(const char *fmt, ...) noexcept
return success;
}
bool
Response::VFmt(fmt::string_view format_str, fmt::format_args args) noexcept
{
fmt::memory_buffer buffer;
fmt::vformat_to(buffer, format_str, args);
return Write(buffer.data(), buffer.size());
}
bool
Response::WriteBinary(ConstBuffer<void> payload) noexcept
{
assert(payload.size <= client.binary_limit);
return
#ifdef _WIN32
Format("binary: %lu\n", (unsigned long)payload.size) &&
#else
Format("binary: %zu\n", payload.size) &&
#endif
Fmt("binary: {}\n", payload.size) &&
Write(payload.data, payload.size) &&
Write("\n");
}