Skip to content

Commit bba388b

Browse files
authored
Merge pull request Tencent#896 from StilesCrisis/writer-flush-api
Writer flush api
2 parents 465fab4 + 31c6c50 commit bba388b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/rapidjson/prettywriter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
150150
(void)ret;
151151
RAPIDJSON_ASSERT(ret == true);
152152
if (Base::level_stack_.Empty()) // end of json text
153-
Base::os_->Flush();
153+
Base::Flush();
154154
return true;
155155
}
156156

@@ -174,7 +174,7 @@ class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding,
174174
(void)ret;
175175
RAPIDJSON_ASSERT(ret == true);
176176
if (Base::level_stack_.Empty()) // end of json text
177-
Base::os_->Flush();
177+
Base::Flush();
178178
return true;
179179
}
180180

include/rapidjson/writer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ class Writer {
267267
return EndValue(WriteRawValue(json, length));
268268
}
269269

270+
//! Flush the output stream.
271+
/*!
272+
Allows the user to flush the output stream immediately.
273+
*/
274+
void Flush() {
275+
os_->Flush();
276+
}
277+
270278
protected:
271279
//! Information for each nested level
272280
struct Level {
@@ -473,7 +481,7 @@ class Writer {
473481
// Flush the value if it is the top level one.
474482
bool EndValue(bool ret) {
475483
if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
476-
os_->Flush();
484+
Flush();
477485
return ret;
478486
}
479487

0 commit comments

Comments
 (0)