diff options
Diffstat (limited to 'src/google/protobuf/util/internal/json_objectwriter.h')
-rw-r--r-- | src/google/protobuf/util/internal/json_objectwriter.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/google/protobuf/util/internal/json_objectwriter.h b/src/google/protobuf/util/internal/json_objectwriter.h index cb7e2fb3..31edc292 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.h +++ b/src/google/protobuf/util/internal/json_objectwriter.h @@ -93,7 +93,8 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { stream_(out), sink_(out), indent_string_(indent_string.ToString()), - use_websafe_base64_for_bytes_(false) {} + use_websafe_base64_for_bytes_(false), + empty_name_ok_for_next_key_(false) {} virtual ~JsonObjectWriter(); // ObjectWriter methods. @@ -111,11 +112,19 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { virtual JsonObjectWriter* RenderString(StringPiece name, StringPiece value); virtual JsonObjectWriter* RenderBytes(StringPiece name, StringPiece value); virtual JsonObjectWriter* RenderNull(StringPiece name); + virtual JsonObjectWriter* RenderNullAsEmpty(StringPiece name); void set_use_websafe_base64_for_bytes(bool value) { use_websafe_base64_for_bytes_ = value; } + // Whether empty strings should be rendered for the next JSON key. This + // setting is only valid until the next key is rendered, after which it gets + // reset to false. + virtual void empty_name_ok_for_next_key() { + empty_name_ok_for_next_key_ = true; + } + protected: class LIBPROTOBUF_EXPORT Element : public BaseElement { public: @@ -195,6 +204,10 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { // Writes an individual character to the output. void WriteChar(const char c) { stream_->WriteRaw(&c, sizeof(c)); } + // Returns the current value of empty_name_ok_for_next_key_ and resets it to + // false. + bool GetAndResetEmptyKeyOk(); + google::protobuf::scoped_ptr<Element> element_; google::protobuf::io::CodedOutputStream* stream_; ByteSinkWrapper sink_; @@ -204,6 +217,11 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { // to regular base64 encoding. bool use_websafe_base64_for_bytes_; + // Whether empty strings should be rendered for the next JSON key. This + // setting is only valid until the next key is rendered, after which it gets + // reset to false. + bool empty_name_ok_for_next_key_; + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonObjectWriter); }; |