grpc
third_party
protobuf
src
google
protobuf
protobuf/src/google/protobuf/map_field_lite.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_FIELD_LITE_H__
32
#define GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__
33
34
#include <type_traits>
35
#include <google/protobuf/parse_context.h>
36
#include <google/protobuf/io/coded_stream.h>
37
#include <google/protobuf/map.h>
38
#include <google/protobuf/map_entry_lite.h>
39
#include <google/protobuf/port.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
namespace
internal
{
51
52
// This class provides access to map field using generated api. It is used for
53
// internal generated message implementation only. Users should never use this
54
// directly.
55
template
<
typename
Derived,
typename
Key
,
typename
T
,
56
WireFormatLite::FieldType
key_wire_type,
57
WireFormatLite::FieldType
value_wire_type>
58
class
MapFieldLite {
59
// Define message type for internal repeated field.
60
typedef
Derived
EntryType
;
61
62
public
:
63
typedef
Map<Key, T>
MapType
;
64
typedef
EntryType
EntryTypeTrait
;
65
66
constexpr
MapFieldLite
() {}
67
68
explicit
MapFieldLite
(
Arena
*
arena
) :
map_
(
arena
) {}
69
70
// Accessors
71
const
Map<Key, T>
&
GetMap
()
const
{
return
map_
; }
72
Map<Key, T>
*
MutableMap
() {
return
&
map_
; }
73
74
// Convenient methods for generated message implementation.
75
int
size
()
const
{
return
static_cast<
int
>
(
map_
.size()); }
76
void
Clear
() {
return
map_
.clear(); }
77
void
MergeFrom
(
const
MapFieldLite
& other) {
78
for
(
typename
Map<Key, T>::const_iterator
it
= other.map_.begin();
79
it
!= other.map_.end(); ++
it
) {
80
map_
[
it
->first] =
it
->second;
81
}
82
}
83
void
Swap
(
MapFieldLite
* other) {
map_
.swap(other->map_); }
84
void
InternalSwap
(
MapFieldLite
* other) {
map_
.InternalSwap(other->map_); }
85
86
// Used in the implementation of parsing. Caller should take the ownership iff
87
// arena_ is nullptr.
88
EntryType
*
NewEntry
()
const
{
89
return
Arena::CreateMessage<EntryType>(
map_
.arena());
90
}
91
// Used in the implementation of serializing enum value type. Caller should
92
// take the ownership iff arena_ is nullptr.
93
EntryType
*
NewEnumEntryWrapper
(
const
Key
&
key
,
const
T
t)
const
{
94
return
EntryType::EnumWrap(
key
, t,
map_
.arena_);
95
}
96
// Used in the implementation of serializing other value types. Caller should
97
// take the ownership iff arena_ is nullptr.
98
EntryType
*
NewEntryWrapper
(
const
Key
&
key
,
const
T
& t)
const
{
99
return
EntryType::Wrap(
key
, t,
map_
.arena_);
100
}
101
102
const
char
*
_InternalParse
(
const
char
*
ptr
,
ParseContext
*
ctx
) {
103
typename
Derived::template
Parser<MapFieldLite, Map<Key, T>>
parser
(
this
);
104
return
parser
._InternalParse(
ptr
,
ctx
);
105
}
106
107
template
<
typename
UnknownType>
108
const
char
*
ParseWithEnumValidation
(
const
char
*
ptr
,
ParseContext
*
ctx
,
109
bool
(*is_valid)(
int
),
uint32_t
field_num,
110
InternalMetadata
*
metadata
) {
111
typename
Derived::template
Parser<MapFieldLite, Map<Key, T>>
parser
(
this
);
112
return
parser
.template ParseWithEnumValidation<UnknownType>(
113
ptr
,
ctx
, is_valid, field_num,
metadata
);
114
}
115
116
private
:
117
typedef
void
DestructorSkippable_
;
118
119
Map<Key, T>
map_
;
120
121
friend
class ::PROTOBUF_NAMESPACE_ID::Arena
;
122
};
123
124
template
<
typename
UnknownType,
typename
T>
125
struct
EnumParseWrapper
{
126
const
char
*
_InternalParse
(
const
char
*
ptr
,
ParseContext
*
ctx
) {
127
return
map_field
->template ParseWithEnumValidation<UnknownType>(
128
ptr
,
ctx
,
is_valid
,
field_num
,
metadata
);
129
}
130
T
*
map_field
;
131
bool
(*
is_valid
)(
int
);
132
uint32_t
field_num
;
133
InternalMetadata
*
metadata
;
134
};
135
136
// Helper function because the typenames of maps are horrendous to print. This
137
// leverages compiler type deduction, to keep all type data out of the
138
// generated code
139
template
<
typename
UnknownType,
typename
T>
140
EnumParseWrapper<UnknownType, T>
InitEnumParseWrapper
(
141
T
* map_field,
bool
(*is_valid)(
int
),
uint32_t
field_num,
142
InternalMetadata
*
metadata
) {
143
return
EnumParseWrapper<UnknownType, T>
{map_field, is_valid, field_num,
144
metadata
};
145
}
146
147
// True if IsInitialized() is true for value field in all elements of t. T is
148
// expected to be message. It's useful to have this helper here to keep the
149
// protobuf compiler from ever having to emit loops in IsInitialized() methods.
150
// We want the C++ compiler to inline this or not as it sees fit.
151
template
<
typename
Derived,
typename
Key
,
typename
T
,
152
WireFormatLite::FieldType
key_wire_type,
153
WireFormatLite::FieldType
value_wire_type>
154
bool
AllAreInitialized
(
const
MapFieldLite
<Derived,
Key
,
T
, key_wire_type,
155
value_wire_type>&
field
) {
156
const
auto
& t =
field
.GetMap();
157
for
(
typename
Map<Key, T>::const_iterator
it
= t.begin();
it
!= t.end();
158
++
it
) {
159
if
(!
it
->second.IsInitialized())
return
false
;
160
}
161
return
true
;
162
}
163
164
template
<
typename
MEntry>
165
struct
MapEntryToMapField : MapEntryToMapField<typename MEntry::SuperType> {};
166
167
template
<
typename
T
,
typename
Key
,
typename
Value
,
168
WireFormatLite::FieldType
kKeyFieldType,
169
WireFormatLite::FieldType
kValueFieldType>
170
struct
MapEntryToMapField
<
171
MapEntryLite
<
T
,
Key
,
Value
, kKeyFieldType, kValueFieldType>> {
172
typedef
MapFieldLite
<
173
MapEntryLite<T, Key, Value, kKeyFieldType, kValueFieldType>
,
Key
,
Value
,
174
kKeyFieldType, kValueFieldType>
175
MapFieldType
;
176
};
177
178
}
// namespace internal
179
}
// namespace protobuf
180
}
// namespace google
181
182
#include <google/protobuf/port_undef.inc>
183
184
#endif // GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__
google::protobuf.internal::MapFieldLite::MapFieldLite
constexpr MapFieldLite()
Definition:
protobuf/src/google/protobuf/map_field_lite.h:66
ptr
char * ptr
Definition:
abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
google::protobuf.internal::MapFieldLite::InternalSwap
void InternalSwap(MapFieldLite *other)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:84
Arena
struct Arena Arena
Definition:
third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:189
regen-readme.it
it
Definition:
regen-readme.py:15
google::protobuf.internal::MapFieldLite::MutableMap
Map< Key, T > * MutableMap()
Definition:
protobuf/src/google/protobuf/map_field_lite.h:72
ctx
Definition:
benchmark-async.c:30
bool
bool
Definition:
setup_once.h:312
metadata
Definition:
cq_verifier.cc:48
google::protobuf.internal::MapFieldLite
Definition:
third_party/bloaty/third_party/protobuf/src/google/protobuf/map.h:73
google::protobuf.internal::EnumParseWrapper::metadata
InternalMetadata * metadata
Definition:
protobuf/src/google/protobuf/map_field_lite.h:133
google::protobuf.internal::EnumParseWrapper::field_num
uint32_t field_num
Definition:
protobuf/src/google/protobuf/map_field_lite.h:132
google::protobuf.internal::MapFieldLite::map_
Map< Key, T > map_
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:123
google::protobuf.internal::MapFieldLite::size
int size() const
Definition:
protobuf/src/google/protobuf/map_field_lite.h:75
Arena
Definition:
arena.c:39
google::protobuf.internal::EnumParseWrapper::_InternalParse
const char * _InternalParse(const char *ptr, ParseContext *ctx)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:126
google::protobuf.internal::MapFieldLite::MapFieldLite
MapFieldLite(Arena *arena)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:68
google::protobuf.internal::ParseContext
Definition:
bloaty/third_party/protobuf/src/google/protobuf/parse_context.h:336
google::protobuf
Definition:
bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf.internal::MapEntryToMapField< MapEntryLite< T, Key, Value, kKeyFieldType, kValueFieldType > >::MapFieldType
MapFieldLite< MapEntryLite< T, Key, Value, kKeyFieldType, kValueFieldType >, Key, Value, kKeyFieldType, kValueFieldType > MapFieldType
Definition:
protobuf/src/google/protobuf/map_field_lite.h:175
google::protobuf.internal::AllAreInitialized
bool AllAreInitialized(const Type &t)
Definition:
bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.h:99
google::protobuf.internal::MapFieldLite::EntryType
Derived EntryType
Definition:
protobuf/src/google/protobuf/map_field_lite.h:60
google::protobuf.internal::MapEntryLite
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_entry_lite.h:541
T
#define T(upbtypeconst, upbtype, ctype, default_value)
google::protobuf.internal::MapFieldLite::NewEnumEntryWrapper
EntryType * NewEnumEntryWrapper(const Key &key, const T t) const
Definition:
protobuf/src/google/protobuf/map_field_lite.h:93
arena
grpc_core::ScopedArenaPtr arena
Definition:
binder_transport_test.cc:237
uint32_t
unsigned int uint32_t
Definition:
stdint-msvc2008.h:80
google::protobuf.internal::MapFieldLite::_InternalParse
const char * _InternalParse(const char *ptr, ParseContext *ctx)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:102
asyncio_get_stats.parser
parser
Definition:
asyncio_get_stats.py:34
xds_interop_client.int
int
Definition:
xds_interop_client.py:113
google::protobuf.internal::MapFieldLite::NewEntryWrapper
EntryType * NewEntryWrapper(const Key &key, const T &t) const
Definition:
protobuf/src/google/protobuf/map_field_lite.h:98
google::protobuf.internal::MapFieldLite::MapType
Map< Key, T > MapType
Definition:
protobuf/src/google/protobuf/map_field_lite.h:63
google::protobuf.internal::InternalMetadata
Definition:
protobuf/src/google/protobuf/metadata_lite.h:62
google::protobuf.internal::MapFieldLite::NewEntry
EntryType * NewEntry() const
Definition:
protobuf/src/google/protobuf/map_field_lite.h:88
google::protobuf.internal::MapFieldLite::Clear
void Clear()
Definition:
protobuf/src/google/protobuf/map_field_lite.h:76
google::protobuf.internal::WireFormatLite::FieldType
FieldType
Definition:
bloaty/third_party/protobuf/src/google/protobuf/wire_format_lite.h:111
google::protobuf.internal::MapEntryToMapField
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:166
google::protobuf.internal::MapFieldLite::Swap
void Swap(MapFieldLite *other)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:83
google::protobuf.internal::MapFieldLite::ParseWithEnumValidation
const char * ParseWithEnumValidation(const char *ptr, ParseContext *ctx, bool(*is_valid)(int), uint32_t field_num, InternalMetadata *metadata)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:108
field
const FieldDescriptor * field
Definition:
bloaty/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc:2692
key
const char * key
Definition:
hpack_parser_table.cc:164
google::protobuf.internal::InitEnumParseWrapper
EnumParseWrapper< T, Metadata > InitEnumParseWrapper(T *map_field, bool(*is_valid)(int), uint32 field_num, Metadata *metadata)
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:144
google::protobuf.internal::EnumParseWrapper::field_num
uint32 field_num
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:136
google::protobuf.internal::MapFieldLite::EntryTypeTrait
EntryType EntryTypeTrait
Definition:
protobuf/src/google/protobuf/map_field_lite.h:64
google::protobuf.internal::MapFieldLite::GetMap
const Map< Key, T > & GetMap() const
Definition:
protobuf/src/google/protobuf/map_field_lite.h:71
testing::Key
internal::KeyMatcher< M > Key(M inner_matcher)
Definition:
cares/cares/test/gmock-1.8.0/gmock/gmock.h:9141
google::protobuf.internal::EnumParseWrapper
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:129
google::protobuf.internal::MapFieldLite::MergeFrom
void MergeFrom(const MapFieldLite &other)
Definition:
protobuf/src/google/protobuf/map_field_lite.h:77
google::protobuf::Map
Definition:
third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:79
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
setup.template
template
Definition:
setup.py:47
google::protobuf.internal::EnumParseWrapper::map_field
T * map_field
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:134
google
Definition:
bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf.internal::MapFieldLite::DestructorSkippable_
void DestructorSkippable_
Definition:
protobuf/src/google/protobuf/map_field_lite.h:117
google::protobuf.internal::EnumParseWrapper::is_valid
bool(* is_valid)(int)
Definition:
bloaty/third_party/protobuf/src/google/protobuf/map_field_lite.h:135
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:19