protobuf/src/google/protobuf/map_entry.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_MAP_ENTRY_H__
32 #define GOOGLE_PROTOBUF_MAP_ENTRY_H__
33 
34 #include <google/protobuf/generated_message_reflection.h>
35 #include <google/protobuf/map_entry_lite.h>
36 #include <google/protobuf/map_type_handler.h>
37 #include <google/protobuf/port.h>
38 #include <google/protobuf/reflection_ops.h>
39 #include <google/protobuf/unknown_field_set.h>
40 #include <google/protobuf/wire_format_lite.h>
41 
42 #include <google/protobuf/port_def.inc>
43 
44 #ifdef SWIG
45 #error "You cannot SWIG proto headers"
46 #endif
47 
48 namespace google {
49 namespace protobuf {
50 class Arena;
51 namespace internal {
52 template <typename Derived, typename Key, typename Value,
53  WireFormatLite::FieldType kKeyFieldType,
54  WireFormatLite::FieldType kValueFieldType>
55 class MapField;
56 }
57 } // namespace protobuf
58 } // namespace google
59 
60 namespace google {
61 namespace protobuf {
62 namespace internal {
63 
64 // MapEntry is the returned google::protobuf::Message when calling AddMessage of
65 // google::protobuf::Reflection. In order to let it work with generated message
66 // reflection, its in-memory type is the same as generated message with the same
67 // fields. However, in order to decide the in-memory type of key/value, we need
68 // to know both their cpp type in generated api and proto type. In
69 // implementation, all in-memory types have related wire format functions to
70 // support except ArenaStringPtr. Therefore, we need to define another type with
71 // supporting wire format functions. Since this type is only used as return type
72 // of MapEntry accessors, it's named MapEntry accessor type.
73 //
74 // cpp type: the type visible to users in public API.
75 // proto type: WireFormatLite::FieldType of the field.
76 // in-memory type: type of the data member used to stored this field.
77 // MapEntry accessor type: type used in MapEntry getters/mutators to access the
78 // field.
79 //
80 // cpp type | proto type | in-memory type | MapEntry accessor type
81 // int32_t TYPE_INT32 int32_t int32_t
82 // int32_t TYPE_FIXED32 int32_t int32_t
83 // string TYPE_STRING ArenaStringPtr string
84 // FooEnum TYPE_ENUM int int
85 // FooMessage TYPE_MESSAGE FooMessage* FooMessage
86 //
87 // The in-memory types of primitive types can be inferred from its proto type,
88 // while we need to explicitly specify the cpp type if proto type is
89 // TYPE_MESSAGE to infer the in-memory type.
90 template <typename Derived, typename Key, typename Value,
91  WireFormatLite::FieldType kKeyFieldType,
92  WireFormatLite::FieldType kValueFieldType>
93 class MapEntry : public MapEntryImpl<Derived, Message, Key, Value,
94  kKeyFieldType, kValueFieldType> {
95  public:
96  constexpr MapEntry() : _internal_metadata_() {}
97  explicit MapEntry(Arena* arena)
98  : MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
99  kValueFieldType>(arena),
102  Message::_internal_metadata_.template Delete<UnknownFieldSet>();
104  }
106  typedef void DestructorSkippable_;
107 
108  typedef typename MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
110  typedef
111  typename MapEntryImpl<Derived, Message, Key, Value, kKeyFieldType,
113  size_t SpaceUsedLong() const override {
114  size_t size = sizeof(Derived);
115  size += KeyTypeHandler::SpaceUsedInMapEntryLong(this->key_);
116  size += ValueTypeHandler::SpaceUsedInMapEntryLong(this->value_);
117  return size;
118  }
119 
121 
122  private:
124  template <typename C, typename K, typename V,
126  friend class internal::MapField;
127 
129 };
130 
131 // Specialization for the full runtime
132 template <typename Derived, typename Key, typename Value,
133  WireFormatLite::FieldType kKeyFieldType,
134  WireFormatLite::FieldType kValueFieldType>
136  MapEntry<Derived, Key, Value, kKeyFieldType, kValueFieldType> >
137  : MapEntryHelper<
138  MapEntryLite<Derived, Key, Value, kKeyFieldType, kValueFieldType> > {
139  explicit MapEntryHelper(const MapPair<Key, Value>& map_pair)
140  : MapEntryHelper<
141  MapEntryLite<Derived, Key, Value, kKeyFieldType, kValueFieldType> >(
142  map_pair) {}
143 };
144 
145 template <typename Derived, typename K, typename V,
147 struct DeconstructMapEntry<MapEntry<Derived, K, V, key, value> > {
148  typedef K Key;
149  typedef V Value;
150  static constexpr WireFormatLite::FieldType kKeyFieldType = key;
151  static constexpr WireFormatLite::FieldType kValueFieldType = value;
152 };
153 
154 } // namespace internal
155 } // namespace protobuf
156 } // namespace google
157 
158 #include <google/protobuf/port_undef.inc>
159 
160 #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__
Arena
struct Arena Arena
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:189
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
google::protobuf.internal::MapEntry::GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry)
google::protobuf.internal::MapEntry::SpaceUsedLong
size_t SpaceUsedLong() const override
Definition: protobuf/src/google/protobuf/map_entry.h:113
C
#define C(x)
Definition: abseil-cpp/absl/hash/internal/city_test.cc:49
google::protobuf.internal::MapField
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/map.h:78
google::protobuf.internal::MapEntryImpl
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:147
google::protobuf.internal::MapEntry::InternalArenaConstructable_
void InternalArenaConstructable_
Definition: protobuf/src/google/protobuf/map_entry.h:105
Arena
Definition: arena.c:39
google::protobuf.internal::MapEntry::ValueTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::ValueTypeHandler ValueTypeHandler
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry.h:113
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf.internal::MapEntryLite
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:541
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
google::protobuf.internal::DeconstructMapEntry< MapEntry< Derived, K, V, key, value > >::Value
V Value
Definition: protobuf/src/google/protobuf/map_entry.h:149
google::protobuf.internal::MapEntryHelper< MapEntry< Derived, Key, Value, kKeyFieldType, kValueFieldType > >::MapEntryHelper
MapEntryHelper(const MapPair< Key, Value > &map_pair)
Definition: protobuf/src/google/protobuf/map_entry.h:139
google::protobuf.internal::InternalMetadata
Definition: protobuf/src/google/protobuf/metadata_lite.h:62
google::protobuf.internal::MapEntry::KeyTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::KeyTypeHandler KeyTypeHandler
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry.h:110
google::protobuf.internal::DeconstructMapEntry< MapEntry< Derived, K, V, key, value > >::Key
K Key
Definition: protobuf/src/google/protobuf/map_entry.h:148
google::protobuf.internal::WireFormatLite::FieldType
FieldType
Definition: bloaty/third_party/protobuf/src/google/protobuf/wire_format_lite.h:111
google::protobuf.internal::MapEntry::KeyTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType >::KeyTypeHandler KeyTypeHandler
Definition: protobuf/src/google/protobuf/map_entry.h:109
google::protobuf.internal::MapEntry::ValueTypeHandler
MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType >::ValueTypeHandler ValueTypeHandler
Definition: protobuf/src/google/protobuf/map_entry.h:112
MapField
Definition: protobuf/php/ext/google/protobuf/map.c:50
google::protobuf.internal::MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::value_
ValueOnMemory value_
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:520
google::protobuf.internal::MapEntry
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry.h:95
google::protobuf.internal::MapEntry::MapEntry
MapEntry(Arena *arena)
Definition: protobuf/src/google/protobuf/map_entry.h:97
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
key
const char * key
Definition: hpack_parser_table.cc:164
google::protobuf.internal::MapEntry::~MapEntry
~MapEntry()
Definition: protobuf/src/google/protobuf/map_entry.h:101
testing::Key
internal::KeyMatcher< M > Key(M inner_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9141
google::protobuf::UnknownFieldSet
Definition: bloaty/third_party/protobuf/src/google/protobuf/unknown_field_set.h:81
google::protobuf.internal::MapEntry::MapEntry
constexpr MapEntry()
Definition: protobuf/src/google/protobuf/map_entry.h:96
google::protobuf.internal::MapEntryHelper
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:635
google::protobuf::MessageLite::_internal_metadata_
internal::InternalMetadata _internal_metadata_
Definition: protobuf/src/google/protobuf/message_lite.h:445
internal
Definition: benchmark/test/output_test_helper.cc:20
Value
struct Value Value
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:676
google::protobuf.internal::MapEntry::DestructorSkippable_
void DestructorSkippable_
Definition: protobuf/src/google/protobuf/map_entry.h:106
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf.internal::MapEntryImpl< Derived, Message, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value >::key_
KeyOnMemory key_
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:519
google::protobuf.internal::MapEntry::_internal_metadata_
InternalMetadata _internal_metadata_
Definition: protobuf/src/google/protobuf/map_entry.h:120
google::protobuf::Message::Message
Message()
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:207
google::protobuf.internal::DeconstructMapEntry
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:559
google::protobuf.internal::MapEntry::_internal_metadata_
InternalMetadataWithArena _internal_metadata_
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_entry.h:121
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf::MapPair
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/map.h:92


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