protobuf/src/google/protobuf/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>
35 
36 #include <google/protobuf/io/coded_stream.h>
37 #include <google/protobuf/arena.h>
38 #include <google/protobuf/message_lite.h>
39 #include <google/protobuf/repeated_field.h>
40 
41 #ifdef SWIG
42 #error "You cannot SWIG proto headers"
43 #endif
44 
45 #include <google/protobuf/port_def.inc>
46 
47 // This file is logically internal-only and should only be used by protobuf
48 // generated code.
49 
50 namespace google {
51 namespace protobuf {
52 namespace internal {
53 
54 // An implementation of MessageLite that treats all data as unknown. This type
55 // acts as a placeholder for an implicit weak field in the case where the true
56 // message type does not get linked into the binary.
57 class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
58  public:
61 
62  static const ImplicitWeakMessage* default_instance();
63 
64  std::string GetTypeName() const override { return ""; }
65 
66  MessageLite* New(Arena* arena) const override {
67  return Arena::CreateMessage<ImplicitWeakMessage>(arena);
68  }
69 
70  void Clear() override { data_.clear(); }
71 
72  bool IsInitialized() const override { return true; }
73 
74  void CheckTypeAndMergeFrom(const MessageLite& other) override {
75  data_.append(static_cast<const ImplicitWeakMessage&>(other).data_);
76  }
77 
78  const char* _InternalParse(const char* ptr, ParseContext* ctx) final;
79 
80  size_t ByteSizeLong() const override { return data_.size(); }
81 
83  io::EpsCopyOutputStream* stream) const final {
84  return stream->WriteRaw(data_.data(), static_cast<int>(data_.size()),
85  target);
86  }
87 
88  int GetCachedSize() const override { return static_cast<int>(data_.size()); }
89 
91 
92  private:
95 };
96 
97 // A type handler for use with implicit weak repeated message fields.
98 template <typename ImplicitWeakType>
100  public:
101  typedef MessageLite Type;
102  static constexpr bool Moveable = false;
103 
104  static inline MessageLite* NewFromPrototype(const MessageLite* prototype,
105  Arena* arena = nullptr) {
106  return prototype->New(arena);
107  }
108 
109  static inline void Delete(MessageLite* value, Arena* arena) {
110  if (arena == nullptr) {
111  delete value;
112  }
113  }
114  static inline Arena* GetArena(MessageLite* value) {
115  return value->GetArena();
116  }
117  static inline void Clear(MessageLite* value) { value->Clear(); }
118  static void Merge(const MessageLite& from, MessageLite* to) {
119  to->CheckTypeAndMergeFrom(from);
120  }
121 };
122 
123 } // namespace internal
124 
125 template <typename T>
126 struct WeakRepeatedPtrField {
128  constexpr WeakRepeatedPtrField() : weak() {}
130  ~WeakRepeatedPtrField() { weak.template Destroy<TypeHandler>(); }
131 
137  const void* const>
139 
140  iterator begin() { return iterator(base().raw_data()); }
141  const_iterator begin() const { return iterator(base().raw_data()); }
142  const_iterator cbegin() const { return begin(); }
143  iterator end() { return begin() + base().size(); }
144  const_iterator end() const { return begin() + base().size(); }
145  const_iterator cend() const { return end(); }
147  return pointer_iterator(base().raw_mutable_data());
148  }
150  return const_pointer_iterator(base().raw_mutable_data());
151  }
153  return pointer_iterator(base().raw_mutable_data() + base().size());
154  }
156  return const_pointer_iterator(base().raw_mutable_data() + base().size());
157  }
158 
159  MessageLite* AddWeak(const MessageLite* prototype) {
160  return base().AddWeak(prototype);
161  }
162  T* Add() { return weak.Add(); }
163  void Clear() { base().template Clear<TypeHandler>(); }
164  void MergeFrom(const WeakRepeatedPtrField& other) {
165  base().template MergeFrom<TypeHandler>(other.base());
166  }
168  base().InternalSwap(&other->base());
169  }
170 
171  const internal::RepeatedPtrFieldBase& base() const { return weak; }
173  // Union disables running the destructor. Which would create a strong link.
174  // Instead we explicitly destroy the underlying base through the virtual
175  // destructor.
176  union {
178  };
179 };
180 
181 } // namespace protobuf
182 } // namespace google
183 
184 #include <google/protobuf/port_undef.inc>
185 
186 #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
google::protobuf::WeakRepeatedPtrField::Clear
void Clear()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:163
google::protobuf::WeakRepeatedPtrField::iterator
internal::RepeatedPtrIterator< MessageLite > iterator
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:132
google::protobuf::WeakRepeatedPtrField::end
iterator end()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:143
google::protobuf::WeakRepeatedPtrField
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:133
google::protobuf::WeakRepeatedPtrField::Add
T * Add()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:162
google::protobuf::RepeatedPtrField< T >
google::protobuf::RepeatedPtrField::Add
Element * Add()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2025
google::protobuf.internal::ImplicitWeakMessage::ByteSizeLong
size_t ByteSizeLong() const override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:80
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/macros.h:40
ctx
Definition: benchmark-async.c:30
google::protobuf.internal::ImplicitWeakMessage::GetCachedSize
int GetCachedSize() const override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:88
google::protobuf.internal::ImplicitWeakMessage::GetTypeName
std::string GetTypeName() const override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:64
google::protobuf.internal::ImplicitWeakTypeHandler::Type
MessageLite Type
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:101
google::protobuf.internal::ImplicitWeakTypeHandler::NewFromPrototype
static MessageLite * NewFromPrototype(const MessageLite *prototype, Arena *arena=nullptr)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:104
google::protobuf::WeakRepeatedPtrField::pointer_end
const_pointer_iterator pointer_end() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:155
google::protobuf::WeakRepeatedPtrField::WeakRepeatedPtrField
constexpr WeakRepeatedPtrField()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:128
Arena
Definition: arena.c:39
google::protobuf.internal::ImplicitWeakTypeHandler::Moveable
static const bool Moveable
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:106
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf.internal::ParseContext
Definition: bloaty/third_party/protobuf/src/google/protobuf/parse_context.h:336
google::protobuf::WeakRepeatedPtrField::~WeakRepeatedPtrField
~WeakRepeatedPtrField()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:130
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf.internal::ImplicitWeakTypeHandler::Merge
static void Merge(const MessageLite &from, MessageLite *to)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:118
google::protobuf::WeakRepeatedPtrField::begin
const_iterator begin() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:141
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
google::protobuf::MessageLite
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:184
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
google::protobuf.internal.python_message._InternalParse
_InternalParse
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1196
google::protobuf.internal::ImplicitWeakTypeHandler::Delete
static void Delete(MessageLite *value, Arena *arena)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:109
T
#define T(upbtypeconst, upbtype, ctype, default_value)
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
google::protobuf.internal::ImplicitWeakMessage::CheckTypeAndMergeFrom
void CheckTypeAndMergeFrom(const MessageLite &other) override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:74
google::protobuf::WeakRepeatedPtrField::cend
const_iterator cend() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:145
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
google::protobuf::io::EpsCopyOutputStream
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream.h:651
google::protobuf.internal::ImplicitWeakMessage::Clear
void Clear() override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:70
google::protobuf.internal::ImplicitWeakMessage::InternalArenaConstructable_
void InternalArenaConstructable_
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:90
google::protobuf::WeakRepeatedPtrField::const_iterator
internal::RepeatedPtrIterator< const MessageLite > const_iterator
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:133
google::protobuf.internal::RepeatedPtrFieldBase::AddWeak
MessageLite * AddWeak(const MessageLite *prototype)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.cc:108
google::protobuf::WeakRepeatedPtrField::weak
RepeatedPtrField< T > weak
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:184
grpc::protobuf::MessageLite
GRPC_CUSTOM_MESSAGELITE MessageLite
Definition: include/grpcpp/impl/codegen/config_protobuf.h:79
google::protobuf.internal::ImplicitWeakTypeHandler::GetArena
static Arena * GetArena(MessageLite *value)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:114
google::protobuf::WeakRepeatedPtrField::InternalSwap
void InternalSwap(WeakRepeatedPtrField *other)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:167
google::protobuf.internal::ImplicitWeakMessage::_InternalSerialize
uint8_t * _InternalSerialize(uint8_t *target, io::EpsCopyOutputStream *stream) const final
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:82
google::protobuf.internal::ImplicitWeakMessage
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:57
google::protobuf.internal::RepeatedPtrFieldBase::size
int size() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1533
google::protobuf.internal::RepeatedPtrIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:364
google::protobuf::WeakRepeatedPtrField::pointer_iterator
internal::RepeatedPtrOverPtrsIterator< MessageLite *, void * > pointer_iterator
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:135
google::protobuf::WeakRepeatedPtrField::base
const internal::RepeatedPtrFieldBase & base() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:178
google::protobuf::WeakRepeatedPtrField::pointer_begin
const_pointer_iterator pointer_begin() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:149
google::protobuf.internal::ImplicitWeakMessage::New
MessageLite * New(Arena *arena) const override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:66
google::protobuf::WeakRepeatedPtrField::const_pointer_iterator
internal::RepeatedPtrOverPtrsIterator< const MessageLite *const, const void *const > const_pointer_iterator
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:138
google::protobuf::WeakRepeatedPtrField::base
internal::RepeatedPtrFieldBase & base()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:172
google::protobuf::WeakRepeatedPtrField::WeakRepeatedPtrField
WeakRepeatedPtrField(Arena *arena)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:129
google::protobuf.internal::ImplicitWeakTypeHandler
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:103
google::protobuf::WeakRepeatedPtrField::begin
iterator begin()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:140
google::protobuf.internal::ImplicitWeakTypeHandler::Clear
static void Clear(MessageLite *value)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:117
google::protobuf.internal::ImplicitWeakMessage::IsInitialized
bool IsInitialized() const override
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:72
data_
std::string data_
Definition: cord_rep_btree_navigator_test.cc:84
google::protobuf::WeakRepeatedPtrField::end
const_iterator end() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:144
google::protobuf.internal::ImplicitWeakMessage::ImplicitWeakMessage
ImplicitWeakMessage(Arena *arena)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:60
google::protobuf.internal::RepeatedPtrFieldBase
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:451
google::protobuf::WeakRepeatedPtrField::pointer_end
pointer_iterator pointer_end()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:152
google::protobuf.internal::ImplicitWeakMessage::ImplicitWeakMessage
ImplicitWeakMessage()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:59
google::protobuf::WeakRepeatedPtrField::pointer_begin
pointer_iterator pointer_begin()
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:146
internal
Definition: benchmark/test/output_test_helper.cc:20
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf::WeakRepeatedPtrField::AddWeak
MessageLite * AddWeak(const MessageLite *prototype)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:159
google::protobuf::WeakRepeatedPtrField::MergeFrom
void MergeFrom(const WeakRepeatedPtrField &other)
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:164
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::WeakRepeatedPtrField::cbegin
const_iterator cbegin() const
Definition: protobuf/src/google/protobuf/implicit_weak_message.h:142
google::protobuf.internal::RepeatedPtrOverPtrsIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:366
google::protobuf::MessageLite::New
virtual MessageLite * New() const =0
google::protobuf.internal::RepeatedPtrFieldBase::InternalSwap
void InternalSwap(RepeatedPtrFieldBase *other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2421
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:02