diff options
author | Adam Cozzette <acozzette@google.com> | 2017-12-01 10:05:10 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2017-12-01 10:05:10 -0800 |
commit | 92a7e778e7394386f413cec28d67a07630f784b1 (patch) | |
tree | cb5673c7c09b0d3905b48a24765d07e423bc5b30 /src/google/protobuf/implicit_weak_message.h | |
parent | ce0a53273a400369932ba788d17500336a6ecaad (diff) | |
download | protobuf-92a7e778e7394386f413cec28d67a07630f784b1.tar.gz protobuf-92a7e778e7394386f413cec28d67a07630f784b1.tar.bz2 protobuf-92a7e778e7394386f413cec28d67a07630f784b1.zip |
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/implicit_weak_message.h')
-rw-r--r-- | src/google/protobuf/implicit_weak_message.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 12cc7db9..a822172e 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -35,10 +35,16 @@ #include <google/protobuf/arena.h> #include <google/protobuf/message_lite.h> +// This file is logically internal-only and should only be used by protobuf +// generated code. + namespace google { namespace protobuf { namespace internal { +// An implementation of MessageLite that treats all data as unknown. This type +// acts as a placeholder for an implicit weak field in the case where the true +// message type does not get linked into the binary. class LIBPROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { public: ImplicitWeakMessage() : arena_(NULL) {} @@ -69,7 +75,7 @@ class LIBPROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { output->WriteString(data_); } - int GetCachedSize() const { return data_.size(); } + int GetCachedSize() const { return static_cast<int>(data_.size()); } typedef void InternalArenaConstructable_; @@ -79,6 +85,49 @@ class LIBPROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage); }; +// A type handler for use with implicit weak repeated message fields. +template <typename ImplicitWeakType> +class ImplicitWeakTypeHandler { + public: + typedef ImplicitWeakType Type; + typedef ::google::protobuf::MessageLite WeakType; +#if LANG_CXX11 + static const bool Moveable = false; +#endif + + // With implicit weak fields, we need separate NewFromPrototype and + // NewFromPrototypeWeak functions. The former is used when we want to create a + // strong dependency on the message type, and it just delegates to the + // GenericTypeHandler. The latter avoids creating a strong dependency, by + // simply calling MessageLite::New. + static inline ::google::protobuf::MessageLite* NewFromPrototype( + const ::google::protobuf::MessageLite* prototype, ::google::protobuf::Arena* arena = NULL) { + return prototype->New(arena); + } + + static inline void Delete(::google::protobuf::MessageLite* value, Arena* arena) { + if (arena == NULL) { + delete value; + } + } + static inline ::google::protobuf::Arena* GetArena(::google::protobuf::MessageLite* value) { + return value->GetArena(); + } + static inline void* GetMaybeArenaPointer(::google::protobuf::MessageLite* value) { + return value->GetArena(); + } + static inline void Clear(::google::protobuf::MessageLite* value) { + value->Clear(); + } + static void Merge(const ::google::protobuf::MessageLite& from, + ::google::protobuf::MessageLite* to) { + to->CheckTypeAndMergeFrom(from); + } + static inline size_t SpaceUsedLong(const Type& value) { + return value.SpaceUsedLong(); + } +}; + extern ::google::protobuf::internal::ExplicitlyConstructed<ImplicitWeakMessage> implicit_weak_message_default_instance; |