implicit_weak_message.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
32 #define GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
33 
34 #include <string>
36 #include <google/protobuf/arena.h>
38 
39 #include <google/protobuf/port_def.inc>
40 
41 #ifdef SWIG
42 #error "You cannot SWIG proto headers"
43 #endif
44 
45 // This file is logically internal-only and should only be used by protobuf
46 // generated code.
47 
48 namespace google {
49 namespace protobuf {
50 namespace internal {
51 
52 // An implementation of MessageLite that treats all data as unknown. This type
53 // acts as a placeholder for an implicit weak field in the case where the true
54 // message type does not get linked into the binary.
55 class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
56  public:
58  explicit ImplicitWeakMessage(Arena* arena) : arena_(arena) {}
59 
60  static const ImplicitWeakMessage* default_instance();
61 
62  std::string GetTypeName() const override { return ""; }
63 
64  MessageLite* New() const override { return new ImplicitWeakMessage; }
65  MessageLite* New(Arena* arena) const override {
66  return Arena::CreateMessage<ImplicitWeakMessage>(arena);
67  }
68 
69  Arena* GetArena() const override { return arena_; }
70 
71  void Clear() override { data_.clear(); }
72 
73  bool IsInitialized() const override { return true; }
74 
75  void CheckTypeAndMergeFrom(const MessageLite& other) override {
76  data_.append(static_cast<const ImplicitWeakMessage&>(other).data_);
77  }
78 
79 #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER
80  const char* _InternalParse(const char* ptr, ParseContext* ctx) final;
81 #else
83 #endif
84 
85  size_t ByteSizeLong() const override { return data_.size(); }
86 
88  output->WriteString(data_);
89  }
90 
91  int GetCachedSize() const override { return static_cast<int>(data_.size()); }
92 
94 
95  private:
96  Arena* const arena_;
99 };
100 
101 // A type handler for use with implicit weak repeated message fields.
102 template <typename ImplicitWeakType>
104  public:
105  typedef ImplicitWeakType Type;
107  static const bool Moveable = false;
108 
109  // With implicit weak fields, we need separate NewFromPrototype and
110  // NewFromPrototypeWeak functions. The former is used when we want to create a
111  // strong dependency on the message type, and it just delegates to the
112  // GenericTypeHandler. The latter avoids creating a strong dependency, by
113  // simply calling MessageLite::New.
114  static inline MessageLite* NewFromPrototype(const MessageLite* prototype,
115  Arena* arena = NULL) {
116  return prototype->New(arena);
117  }
118 
119  static inline void Delete(MessageLite* value, Arena* arena) {
120  if (arena == NULL) {
121  delete value;
122  }
123  }
124  static inline Arena* GetArena(MessageLite* value) {
125  return value->GetArena();
126  }
127  static inline void* GetMaybeArenaPointer(MessageLite* value) {
128  return value->GetArena();
129  }
130  static inline void Clear(MessageLite* value) { value->Clear(); }
131  static void Merge(const MessageLite& from, MessageLite* to) {
132  to->CheckTypeAndMergeFrom(from);
133  }
134  static inline size_t SpaceUsedLong(const Type& value) {
135  return value.SpaceUsedLong();
136  }
137 };
138 
139 } // namespace internal
140 } // namespace protobuf
141 } // namespace google
142 
143 #include <google/protobuf/port_undef.inc>
144 
145 #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
data_
StringPiece data_
Definition: bytestream_unittest.cc:60
google::protobuf.internal::ImplicitWeakMessage::ByteSizeLong
size_t ByteSizeLong() const override
Definition: implicit_weak_message.h:85
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
google::protobuf.internal::ImplicitWeakTypeHandler::GetMaybeArenaPointer
static void * GetMaybeArenaPointer(MessageLite *value)
Definition: implicit_weak_message.h:127
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: macros.h:40
google::protobuf.internal::ImplicitWeakMessage::GetCachedSize
int GetCachedSize() const override
Definition: implicit_weak_message.h:91
google::protobuf.internal::ImplicitWeakMessage::GetTypeName
std::string GetTypeName() const override
Definition: implicit_weak_message.h:62
NULL
NULL
Definition: test_security_zap.cpp:405
input
std::string input
Definition: tokenizer_unittest.cc:197
google::protobuf.internal::ImplicitWeakTypeHandler::NewFromPrototype
static MessageLite * NewFromPrototype(const MessageLite *prototype, Arena *arena=NULL)
Definition: implicit_weak_message.h:114
arena_
std::unique_ptr< Arena > arena_
Definition: lite_arena_unittest.cc:51
google::protobuf.internal::ImplicitWeakTypeHandler::Moveable
static const bool Moveable
Definition: implicit_weak_message.h:107
google::protobuf.internal::ParseContext
Definition: parse_context.h:322
google::protobuf.internal::ImplicitWeakTypeHandler::Merge
static void Merge(const MessageLite &from, MessageLite *to)
Definition: implicit_weak_message.h:131
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::MessageLite
Definition: message_lite.h:183
google::protobuf.internal::ImplicitWeakMessage::arena_
Arena *const arena_
Definition: implicit_weak_message.h:96
google::protobuf.internal.python_message._InternalParse
_InternalParse
Definition: python_message.py:1197
google::protobuf.internal::ImplicitWeakTypeHandler::Delete
static void Delete(MessageLite *value, Arena *arena)
Definition: implicit_weak_message.h:119
google::protobuf.internal::ImplicitWeakMessage::CheckTypeAndMergeFrom
void CheckTypeAndMergeFrom(const MessageLite &other) override
Definition: implicit_weak_message.h:75
google::protobuf.internal::ImplicitWeakMessage::Clear
void Clear() override
Definition: implicit_weak_message.h:71
google::protobuf.internal::ImplicitWeakMessage::InternalArenaConstructable_
void InternalArenaConstructable_
Definition: implicit_weak_message.h:93
google::protobuf.internal::MergePartialFromCodedStream
bool MergePartialFromCodedStream(MessageLite *msg, const ParseTable &table, io::CodedInputStream *input)
Definition: generated_message_table_driven.cc:96
Type
Definition: type.pb.h:182
coded_stream.h
google::protobuf.internal::ImplicitWeakTypeHandler::GetArena
static Arena * GetArena(MessageLite *value)
Definition: implicit_weak_message.h:124
google::protobuf.internal::ImplicitWeakMessage
Definition: implicit_weak_message.h:55
google::protobuf.internal::ImplicitWeakMessage::data_
std::string data_
Definition: implicit_weak_message.h:97
google::protobuf.internal::ImplicitWeakMessage::New
MessageLite * New(Arena *arena) const override
Definition: implicit_weak_message.h:65
google::protobuf::io::CodedOutputStream
Definition: coded_stream.h:693
google::protobuf.internal::ImplicitWeakTypeHandler::Type
ImplicitWeakType Type
Definition: implicit_weak_message.h:105
google::protobuf.internal::ImplicitWeakTypeHandler
Definition: implicit_weak_message.h:103
google::protobuf.internal::ImplicitWeakTypeHandler::WeakType
MessageLite WeakType
Definition: implicit_weak_message.h:106
arena.h
google::protobuf.internal::ImplicitWeakTypeHandler::Clear
static void Clear(MessageLite *value)
Definition: implicit_weak_message.h:130
message_lite.h
google::protobuf::io::CodedInputStream
Definition: coded_stream.h:173
google::protobuf.internal::ImplicitWeakMessage::IsInitialized
bool IsInitialized() const override
Definition: implicit_weak_message.h:73
google::protobuf.internal::ImplicitWeakMessage::ImplicitWeakMessage
ImplicitWeakMessage(Arena *arena)
Definition: implicit_weak_message.h:58
google::protobuf.internal::ImplicitWeakMessage::ImplicitWeakMessage
ImplicitWeakMessage()
Definition: implicit_weak_message.h:57
internal
Definition: any.pb.h:40
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf.internal::ImplicitWeakMessage::GetArena
Arena * GetArena() const override
Definition: implicit_weak_message.h:69
output
const upb_json_parsermethod const upb_symtab upb_sink * output
Definition: ruby/ext/google/protobuf_c/upb.h:10503
google::protobuf.internal::ImplicitWeakTypeHandler::SpaceUsedLong
static size_t SpaceUsedLong(const Type &value)
Definition: implicit_weak_message.h:134
google::protobuf::MessageLite::CheckTypeAndMergeFrom
virtual void CheckTypeAndMergeFrom(const MessageLite &other)=0
google::protobuf.internal::ImplicitWeakMessage::New
MessageLite * New() const override
Definition: implicit_weak_message.h:64
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf.internal::ImplicitWeakMessage::SerializeWithCachedSizes
void SerializeWithCachedSizes(io::CodedOutputStream *output) const override
Definition: implicit_weak_message.h:87
google::protobuf::MessageLite::New
virtual MessageLite * New() const =0


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54