diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2016-01-06 18:06:43 -0800 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2016-01-06 18:10:24 -0800 |
commit | 76195058e25d19fc918996d55d3ad69ee55cb77e (patch) | |
tree | 3b93b3195a1a411e11b93644429cc6c96668b128 /src/google/protobuf/io/zero_copy_stream_impl_lite.h | |
parent | 363316a8d79ad3bebf47c6347a038b6130212e28 (diff) |
Patch internal change 111557819.
Defer calls to mutable_unknown_fields() until it is actually required to
save memory for C++ lite runtime.
Change-Id: Ica9c1fd276cdb164942d1e7b6e098c83ee3ffdc5
Diffstat (limited to 'src/google/protobuf/io/zero_copy_stream_impl_lite.h')
-rw-r--r-- | src/google/protobuf/io/zero_copy_stream_impl_lite.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/src/google/protobuf/io/zero_copy_stream_impl_lite.h index a598ef2e..1c397dea 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -148,6 +148,9 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { void BackUp(int count); int64 ByteCount() const; + protected: + void SetString(string* target); + private: static const int kMinimumSize = 16; @@ -156,6 +159,27 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream); }; +// LazyStringOutputStream is a StringOutputStream with lazy acquisition of +// the output string from a callback. The string is owned externally, and not +// deleted in the stream destructor. +class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream { + public: + // Callback should be permanent (non-self-deleting). Ownership is transferred + // to the LazyStringOutputStream. + explicit LazyStringOutputStream(ResultCallback<string*>* callback); + ~LazyStringOutputStream(); + + // implements ZeroCopyOutputStream, overriding StringOutputStream ----------- + bool Next(void** data, int* size); + int64 ByteCount() const; + + private: + const scoped_ptr<ResultCallback<string*> > callback_; + bool string_is_set_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyStringOutputStream); +}; + // Note: There is no StringInputStream. Instead, just create an // ArrayInputStream as follows: // ArrayInputStream input(str.data(), str.size()); |