From 5a3584b07821f5cc481817dbd0c8323df1c9f163 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Thu, 9 May 2024 10:08:22 -0400 Subject: [PATCH] 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 --- src/common/Formatter.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 65ffb0a6855..4bfb5c41e08 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(); } -- 2.39.5