Skip to content

Commit

Permalink
common/Formatter: write the pending string on flush
Browse files Browse the repository at this point in the history
The formatter would be deleted and automatically flush anyway but this is
conforming to the API.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
  • Loading branch information
batrick committed May 11, 2024
1 parent 668d840 commit 5a3584b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/common/Formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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? */
}
Expand All @@ -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;
Expand All @@ -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 <class T>
void add_value(std::string_view name, T val);
Expand All @@ -254,6 +254,14 @@ namespace ceph {
{
}
~JSONFormatterFile() {
flush();
}

void flush(std::ostream& os) override {
flush();
}
void flush() {
JSONFormatter::finish_pending_string();
file.flush();
}

Expand Down

0 comments on commit 5a3584b

Please sign in to comment.