|
37 | 37 | #include "absl/types/variant.h" |
38 | 38 | #include "absl/utility/utility.h" |
39 | 39 | #include "base/attribute.h" |
40 | | -#include "common/allocator.h" |
41 | 40 | #include "common/arena.h" |
42 | | -#include "common/memory.h" |
43 | 41 | #include "common/native_type.h" |
44 | 42 | #include "common/optional_ref.h" |
45 | 43 | #include "common/type.h" |
@@ -117,78 +115,111 @@ class Value final : private common_internal::ValueMixin<Value> { |
117 | 115 | // Returns an appropriate `Value` for the dynamic protobuf message. If |
118 | 116 | // `message` is the well known type `google.protobuf.Any`, `descriptor_pool` |
119 | 117 | // and `message_factory` will be used to unpack the value. Both must outlive |
120 | | - // the resulting value and any of its shallow copies. |
121 | | - static Value Message(Allocator<> allocator, const google::protobuf::Message& message, |
122 | | - absl::Nonnull<const google::protobuf::DescriptorPool*> |
123 | | - descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND, |
124 | | - absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
125 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND); |
126 | | - static Value Message(Allocator<> allocator, google::protobuf::Message&& message, |
127 | | - absl::Nonnull<const google::protobuf::DescriptorPool*> |
128 | | - descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND, |
129 | | - absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
130 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND); |
131 | | - static Value Message(Borrowed<const google::protobuf::Message> message, |
132 | | - absl::Nonnull<const google::protobuf::DescriptorPool*> |
133 | | - descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND, |
134 | | - absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
135 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 118 | + // the resulting value and any of its shallow copies. Otherwise the message is |
| 119 | + // copied using `arena`. |
| 120 | + static Value FromMessage( |
| 121 | + const google::protobuf::Message& message, |
| 122 | + absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
| 123 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 124 | + absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
| 125 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 126 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 127 | + static Value FromMessage( |
| 128 | + google::protobuf::Message&& message, |
| 129 | + absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
| 130 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 131 | + absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
| 132 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 133 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 134 | + |
| 135 | + // Returns an appropriate `Value` for the dynamic protobuf message. If |
| 136 | + // `message` is the well known type `google.protobuf.Any`, `descriptor_pool` |
| 137 | + // and `message_factory` will be used to unpack the value. Both must outlive |
| 138 | + // the resulting value and any of its shallow copies. Otherwise the message is |
| 139 | + // borrowed (no copying). If the message is on an arena, that arena will be |
| 140 | + // attributed as the owner. Otherwise `arena` is used. |
| 141 | + static Value WrapMessage( |
| 142 | + absl::Nonnull<const google::protobuf::Message*> message |
| 143 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 144 | + absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
| 145 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 146 | + absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
| 147 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 148 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
136 | 149 |
|
137 | 150 | // Returns an appropriate `Value` for the dynamic protobuf message field. If |
138 | 151 | // `field` in `message` is the well known type `google.protobuf.Any`, |
139 | 152 | // `descriptor_pool` and `message_factory` will be used to unpack the value. |
140 | 153 | // Both must outlive the resulting value and any of its shallow copies. |
141 | | - static Value Field(Borrowed<const google::protobuf::Message> message, |
142 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, |
143 | | - ProtoWrapperTypeOptions wrapper_type_options = |
144 | | - ProtoWrapperTypeOptions::kUnsetNull); |
145 | | - static Value Field(Borrowed<const google::protobuf::Message> message, |
146 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, |
147 | | - absl::Nonnull<const google::protobuf::DescriptorPool*> |
148 | | - descriptor_pool ABSL_ATTRIBUTE_LIFETIME_BOUND, |
149 | | - absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
150 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND, |
151 | | - ProtoWrapperTypeOptions wrapper_type_options = |
152 | | - ProtoWrapperTypeOptions::kUnsetNull); |
| 154 | + // Otherwise the field is borrowed (no copying). If the message is on an |
| 155 | + // arena, that arena will be attributed as the owner. Otherwise `arena` is |
| 156 | + // used. |
| 157 | + static Value WrapField( |
| 158 | + ProtoWrapperTypeOptions wrapper_type_options, |
| 159 | + absl::Nonnull<const google::protobuf::Message*> message |
| 160 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 161 | + absl::Nonnull<const google::protobuf::FieldDescriptor*> field |
| 162 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 163 | + absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
| 164 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 165 | + absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
| 166 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 167 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 168 | + static Value WrapField( |
| 169 | + absl::Nonnull<const google::protobuf::Message*> message |
| 170 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 171 | + absl::Nonnull<const google::protobuf::FieldDescriptor*> field |
| 172 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 173 | + absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
| 174 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 175 | + absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
| 176 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 177 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
| 178 | + return WrapField(ProtoWrapperTypeOptions::kUnsetNull, message, field, |
| 179 | + descriptor_pool, message_factory, arena); |
| 180 | + } |
153 | 181 |
|
154 | 182 | // Returns an appropriate `Value` for the dynamic protobuf message repeated |
155 | 183 | // field. If `field` in `message` is the well known type |
156 | 184 | // `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be used |
157 | 185 | // to unpack the value. Both must outlive the resulting value and any of its |
158 | 186 | // shallow copies. |
159 | | - static Value RepeatedField( |
160 | | - Borrowed<const google::protobuf::Message> message, |
161 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, int index); |
162 | | - static Value RepeatedField( |
163 | | - Borrowed<const google::protobuf::Message> message, |
164 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, int index, |
| 187 | + static Value WrapRepeatedField( |
| 188 | + int index, |
| 189 | + absl::Nonnull<const google::protobuf::Message*> message |
| 190 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 191 | + absl::Nonnull<const google::protobuf::FieldDescriptor*> field |
| 192 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
165 | 193 | absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
166 | 194 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
167 | 195 | absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
168 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 196 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 197 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
169 | 198 |
|
170 | 199 | // Returns an appropriate `StringValue` for the dynamic protobuf message map |
171 | 200 | // field key. The map field key must be a string or the behavior is undefined. |
172 | | - static StringValue MapFieldKeyString(Borrowed<const google::protobuf::Message> message, |
173 | | - const google::protobuf::MapKey& key); |
| 201 | + static StringValue WrapMapFieldKeyString( |
| 202 | + const google::protobuf::MapKey& key, |
| 203 | + absl::Nonnull<const google::protobuf::Message*> message |
| 204 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 205 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
174 | 206 |
|
175 | 207 | // Returns an appropriate `Value` for the dynamic protobuf message map |
176 | 208 | // field value. If `field` in `message`, which is `value`, is the well known |
177 | 209 | // type `google.protobuf.Any`, `descriptor_pool` and `message_factory` will be |
178 | 210 | // used to unpack the value. Both must outlive the resulting value and any of |
179 | 211 | // its shallow copies. |
180 | | - static Value MapFieldValue( |
181 | | - Borrowed<const google::protobuf::Message> message, |
182 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, |
183 | | - const google::protobuf::MapValueConstRef& value); |
184 | | - static Value MapFieldValue( |
185 | | - Borrowed<const google::protobuf::Message> message, |
186 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*> field, |
| 212 | + static Value WrapMapFieldValue( |
187 | 213 | const google::protobuf::MapValueConstRef& value, |
| 214 | + absl::Nonnull<const google::protobuf::Message*> message |
| 215 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 216 | + absl::Nonnull<const google::protobuf::FieldDescriptor*> field |
| 217 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
188 | 218 | absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool |
189 | 219 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
190 | 220 | absl::Nonnull<google::protobuf::MessageFactory*> message_factory |
191 | | - ABSL_ATTRIBUTE_LIFETIME_BOUND); |
| 221 | + ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 222 | + absl::Nonnull<google::protobuf::Arena*> arena ABSL_ATTRIBUTE_LIFETIME_BOUND); |
192 | 223 |
|
193 | 224 | Value() = default; |
194 | 225 | Value(const Value&) = default; |
@@ -2898,27 +2929,31 @@ using StructValueBuilderInterface = StructValueBuilder; |
2898 | 2929 |
|
2899 | 2930 | namespace common_internal { |
2900 | 2931 |
|
2901 | | -using MapFieldKeyAccessor = void (*)(Allocator<>, Borrower, |
2902 | | - const google::protobuf::MapKey&, Value&); |
| 2932 | +using MapFieldKeyAccessor = void (*)(const google::protobuf::MapKey&, |
| 2933 | + absl::Nonnull<const google::protobuf::Message*>, |
| 2934 | + absl::Nonnull<google::protobuf::Arena*>, |
| 2935 | + absl::Nonnull<Value*>); |
2903 | 2936 |
|
2904 | 2937 | absl::StatusOr<MapFieldKeyAccessor> MapFieldKeyAccessorFor( |
2905 | 2938 | absl::Nonnull<const google::protobuf::FieldDescriptor*> field); |
2906 | 2939 |
|
2907 | | -using MapFieldValueAccessor = |
2908 | | - void (*)(Borrower, const google::protobuf::MapValueConstRef&, |
2909 | | - absl::Nonnull<const google::protobuf::FieldDescriptor*>, |
2910 | | - absl::Nonnull<const google::protobuf::DescriptorPool*>, |
2911 | | - absl::Nonnull<google::protobuf::MessageFactory*>, Value&); |
| 2940 | +using MapFieldValueAccessor = void (*)( |
| 2941 | + const google::protobuf::MapValueConstRef&, absl::Nonnull<const google::protobuf::Message*>, |
| 2942 | + absl::Nonnull<const google::protobuf::FieldDescriptor*>, |
| 2943 | + absl::Nonnull<const google::protobuf::DescriptorPool*>, |
| 2944 | + absl::Nonnull<google::protobuf::MessageFactory*>, absl::Nonnull<google::protobuf::Arena*>, |
| 2945 | + absl::Nonnull<Value*>); |
2912 | 2946 |
|
2913 | 2947 | absl::StatusOr<MapFieldValueAccessor> MapFieldValueAccessorFor( |
2914 | 2948 | absl::Nonnull<const google::protobuf::FieldDescriptor*> field); |
2915 | 2949 |
|
2916 | 2950 | using RepeatedFieldAccessor = |
2917 | | - void (*)(Allocator<>, Borrowed<const google::protobuf::Message>, |
| 2951 | + void (*)(int, absl::Nonnull<const google::protobuf::Message*>, |
2918 | 2952 | absl::Nonnull<const google::protobuf::FieldDescriptor*>, |
2919 | | - absl::Nonnull<const google::protobuf::Reflection*>, int, |
| 2953 | + absl::Nonnull<const google::protobuf::Reflection*>, |
2920 | 2954 | absl::Nonnull<const google::protobuf::DescriptorPool*>, |
2921 | | - absl::Nonnull<google::protobuf::MessageFactory*>, Value&); |
| 2955 | + absl::Nonnull<google::protobuf::MessageFactory*>, |
| 2956 | + absl::Nonnull<google::protobuf::Arena*>, absl::Nonnull<Value*>); |
2922 | 2957 |
|
2923 | 2958 | absl::StatusOr<RepeatedFieldAccessor> RepeatedFieldAccessorFor( |
2924 | 2959 | absl::Nonnull<const google::protobuf::FieldDescriptor*> field); |
|
0 commit comments