From: Patrick Donnelly Date: Thu, 9 May 2024 14:08:22 +0000 (-0400) Subject: common/Formatter: write the pending string on flush X-Git-Tag: v19.2.3~303^2~5 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fb2c7846d52c798ffcf1ccd6eb1d1f86982fd0d4;p=ceph.git common/Formatter: write the pending string on flush The formatter would be deleted and automatically flush anyway but this is conforming to the API. Signed-off-by: Patrick Donnelly (cherry picked from commit 5a3584b07821f5cc481817dbd0c8323df1c9f163) --- diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 65ffb0a68551e..4bfb5c41e08d5 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -200,7 +200,7 @@ namespace ceph { int get_len() const override; void write_raw_data(const char *data) override; - protected: +protected: virtual bool handle_value(std::string_view name, std::string_view s, bool quoted) { return false; /* is handling done? */ } @@ -219,8 +219,9 @@ namespace ceph { return m_ss; } - private: + void finish_pending_string(); +private: struct json_formatter_stack_entry_d { int size = 0; bool is_array = false; @@ -231,7 +232,6 @@ namespace ceph { void print_quoted_string(std::string_view s); void print_name(std::string_view name); void print_comma(json_formatter_stack_entry_d& entry); - void finish_pending_string(); template void add_value(std::string_view name, T val); @@ -254,6 +254,14 @@ public: { } ~JSONFormatterFile() { + flush(); + } + + void flush(std::ostream& os) override { + flush(); + } + void flush() { + JSONFormatter::finish_pending_string(); file.flush(); }