diff options
Diffstat (limited to 'src/google/protobuf/implicit_weak_message.h')
-rw-r--r-- | src/google/protobuf/implicit_weak_message.h | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 3279bd17..5d3b479a 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -31,10 +31,17 @@ #ifndef GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__ #define GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__ +#include <string> #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/arena.h> #include <google/protobuf/message_lite.h> +#include <google/protobuf/port_def.inc> + +#ifdef SWIG +#error "You cannot SWIG proto headers" +#endif + // This file is logically internal-only and should only be used by protobuf // generated code. @@ -45,45 +52,52 @@ 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 { +class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { public: ImplicitWeakMessage() : arena_(NULL) {} explicit ImplicitWeakMessage(Arena* arena) : arena_(arena) {} static const ImplicitWeakMessage* default_instance(); - string GetTypeName() const { return ""; } + std::string GetTypeName() const override { return ""; } - MessageLite* New() const { return new ImplicitWeakMessage; } - MessageLite* New(Arena* arena) const { + MessageLite* New() const override { return new ImplicitWeakMessage; } + MessageLite* New(Arena* arena) const override { return Arena::CreateMessage<ImplicitWeakMessage>(arena); } - Arena* GetArena() const { return arena_; } + Arena* GetArena() const override { return arena_; } - void Clear() { data_.clear(); } + void Clear() override { data_.clear(); } - bool IsInitialized() const { return true; } + bool IsInitialized() const override { return true; } - void CheckTypeAndMergeFrom(const MessageLite& other) { + void CheckTypeAndMergeFrom(const MessageLite& other) override { data_.append(static_cast<const ImplicitWeakMessage&>(other).data_); } - bool MergePartialFromCodedStream(io::CodedInputStream* input); + bool MergePartialFromCodedStream(io::CodedInputStream* input) override; + +#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER + ParseFunc _ParseFunc() const override { return _InternalParse; } + + static const char* _InternalParse(const char* begin, const char* end, + void* object, ParseContext* ctx); +#endif - size_t ByteSizeLong() const { return data_.size(); } + size_t ByteSizeLong() const override { return data_.size(); } - void SerializeWithCachedSizes(io::CodedOutputStream* output) const { + void SerializeWithCachedSizes(io::CodedOutputStream* output) const override { output->WriteString(data_); } - int GetCachedSize() const { return static_cast<int>(data_.size()); } + int GetCachedSize() const override { return static_cast<int>(data_.size()); } typedef void InternalArenaConstructable_; private: Arena* const arena_; - string data_; + std::string data_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage); }; @@ -92,7 +106,7 @@ template <typename ImplicitWeakType> class ImplicitWeakTypeHandler { public: typedef ImplicitWeakType Type; - typedef ::google::protobuf::MessageLite WeakType; + typedef MessageLite WeakType; static const bool Moveable = false; // With implicit weak fields, we need separate NewFromPrototype and @@ -100,27 +114,24 @@ class ImplicitWeakTypeHandler { // 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) { + static inline MessageLite* NewFromPrototype(const MessageLite* prototype, + Arena* arena = NULL) { return prototype->New(arena); } - static inline void Delete(::google::protobuf::MessageLite* value, Arena* arena) { + static inline void Delete(MessageLite* value, Arena* arena) { if (arena == NULL) { delete value; } } - static inline ::google::protobuf::Arena* GetArena(::google::protobuf::MessageLite* value) { + static inline Arena* GetArena(MessageLite* value) { return value->GetArena(); } - static inline void* GetMaybeArenaPointer(::google::protobuf::MessageLite* value) { + static inline void* GetMaybeArenaPointer(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) { + static inline void Clear(MessageLite* value) { value->Clear(); } + static void Merge(const MessageLite& from, MessageLite* to) { to->CheckTypeAndMergeFrom(from); } static inline size_t SpaceUsedLong(const Type& value) { @@ -130,6 +141,8 @@ class ImplicitWeakTypeHandler { } // namespace internal } // namespace protobuf - } // namespace google + +#include <google/protobuf/port_undef.inc> + #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__ |