• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
9 #define GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
10 
11 #include <string>
12 #include <utility>
13 
14 #include "absl/log/absl_check.h"
15 #include "absl/strings/string_view.h"
16 #include "google/protobuf/arenastring.h"
17 #include "google/protobuf/explicitly_constructed.h"
18 #include "google/protobuf/message_lite.h"
19 #include "google/protobuf/port.h"
20 
21 // Must be included last.
22 #include "google/protobuf/port_def.inc"
23 
24 #ifdef SWIG
25 #error "You cannot SWIG proto headers"
26 #endif
27 
28 namespace google {
29 namespace protobuf {
30 
31 class Arena;
32 
33 namespace internal {
34 
35 // InlinedStringField wraps a std::string instance and exposes an API similar to
36 // ArenaStringPtr's wrapping of a std::string* instance.
37 //
38 // default_value parameters are taken for consistency with ArenaStringPtr, but
39 // are not used for most methods. With inlining, these should be removed from
40 // the generated binary.
41 //
42 // InlinedStringField has a donating mechanism that allows string buffer
43 // allocated on arena. A string is donated means both the string container and
44 // the data buffer are on arena. The donating mechanism here is similar to the
45 // one in ArenaStringPtr with some differences:
46 //
47 // When an InlinedStringField is constructed, the donating state is true. This
48 // is because the string container is directly stored in the message on the
49 // arena:
50 //
51 //   Construction: donated=true
52 //   Arena:
53 //   +-----------------------+
54 //   |Message foo:           |
55 //   | +-------------------+ |
56 //   | |InlinedStringField:| |
57 //   | | +-----+           | |
58 //   | | | | | |           | |
59 //   | | +-----+           | |
60 //   | +-------------------+ |
61 //   +-----------------------+
62 //
63 // When lvalue Set is called, the donating state is still true. String data will
64 // be allocated on the arena:
65 //
66 //   Lvalue Set: donated=true
67 //   Arena:
68 //   +-----------------------+
69 //   |Message foo:           |
70 //   | +-------------------+ |
71 //   | |InlinedStringField:| |
72 //   | | +-----+           | |
73 //   | | | | | |           | |
74 //   | | +|----+           | |
75 //   | +--|----------------+ |
76 //   |    V                  |
77 //   |  +----------------+   |
78 //   |  |'f','o','o',... |   |
79 //   |  +----------------+   |
80 //   +-----------------------+
81 //
82 // Some operations will undonate a donated string, including: Mutable,
83 // SetAllocated, Rvalue Set, and Swap with a non-donated string.
84 //
85 // For more details of the donating states transitions, go/pd-inlined-string.
86 class PROTOBUF_EXPORT InlinedStringField {
87  public:
InlinedStringField()88   InlinedStringField() : str_() {}
89   InlinedStringField(const InlinedStringField&) = delete;
90   InlinedStringField& operator=(const InlinedStringField&) = delete;
91 #if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L
92   // No need to do dynamic initialization here.
Init()93   constexpr void Init() {}
94   // Add the dummy parameter just to make InlinedStringField(nullptr)
95   // unambiguous.
InlinedStringField(const ExplicitlyConstructed<std::string> *,bool)96   constexpr InlinedStringField(
97       const ExplicitlyConstructed<std::string>* /*default_value*/,
98       bool /*dummy*/)
99       : str_{} {}
100 #else
Init()101   inline void Init() { ::new (static_cast<void*>(&str_)) std::string(); }
102   // Add the dummy parameter just to make InlinedStringField(nullptr)
103   // unambiguous.
InlinedStringField(const ExplicitlyConstructed<std::string> *,bool)104   constexpr InlinedStringField(
105       const ExplicitlyConstructed<std::string>* /*default_value*/,
106       bool /*dummy*/)
107       : dummy_{} {}
108 #endif
109 
110   explicit InlinedStringField(const std::string& default_value);
111   explicit InlinedStringField(Arena* arena);
112   InlinedStringField(Arena* arena, const InlinedStringField& rhs);
~InlinedStringField()113   ~InlinedStringField() { Destruct(); }
114 
115   // Lvalue Set. To save space, we pack the donating states of multiple
116   // InlinedStringFields into an uint32_t `donating_states`. The `mask`
117   // indicates the position of the bit for this InlinedStringField. `donated` is
118   // whether this field is donated.
119   //
120   // The caller should guarantee that:
121   //
122   //   `donated == ((donating_states & ~mask) != 0)`
123   //
124   // This method never changes the `donating_states`.
125   void Set(absl::string_view value, Arena* arena, bool donated,
126            uint32_t* donating_states, uint32_t mask, MessageLite* msg);
127 
128   // Rvalue Set. If this field is donated, this method will undonate this field
129   // by mutating the `donating_states` according to `mask`.
130   void Set(std::string&& value, Arena* arena, bool donated,
131            uint32_t* donating_states, uint32_t mask, MessageLite* msg);
132 
133   void Set(const char* str, ::google::protobuf::Arena* arena, bool donated,
134            uint32_t* donating_states, uint32_t mask, MessageLite* msg);
135 
136   void Set(const char* str, size_t size, ::google::protobuf::Arena* arena, bool donated,
137            uint32_t* donating_states, uint32_t mask, MessageLite* msg);
138 
139   template <typename RefWrappedType>
140   void Set(std::reference_wrapper<RefWrappedType> const_string_ref,
141            ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
142            uint32_t mask, MessageLite* msg);
143 
144   void SetBytes(absl::string_view value, Arena* arena, bool donated,
145                 uint32_t* donating_states, uint32_t mask, MessageLite* msg);
146 
147   void SetBytes(std::string&& value, Arena* arena, bool donated,
148                 uint32_t* donating_states, uint32_t mask, MessageLite* msg);
149 
150   void SetBytes(const char* str, ::google::protobuf::Arena* arena, bool donated,
151                 uint32_t* donating_states, uint32_t mask, MessageLite* msg);
152 
153   void SetBytes(const void* p, size_t size, ::google::protobuf::Arena* arena,
154                 bool donated, uint32_t* donating_states, uint32_t mask,
155                 MessageLite* msg);
156 
157   template <typename RefWrappedType>
158   void SetBytes(std::reference_wrapper<RefWrappedType> const_string_ref,
159                 ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
160                 uint32_t mask, MessageLite* msg);
161 
162   PROTOBUF_NDEBUG_INLINE void SetNoArena(absl::string_view value);
163   PROTOBUF_NDEBUG_INLINE void SetNoArena(std::string&& value);
164 
165   // Basic accessors.
Get()166   PROTOBUF_NDEBUG_INLINE const std::string& Get() const { return GetNoArena(); }
167   PROTOBUF_NDEBUG_INLINE const std::string& GetNoArena() const;
168 
169   // Mutable returns a std::string* instance that is heap-allocated. If this
170   // field is donated, this method undonates this field by mutating the
171   // `donating_states` according to `mask`, and copies the content of the
172   // original string to the returning string.
173   std::string* Mutable(Arena* arena, bool donated, uint32_t* donating_states,
174                        uint32_t mask, MessageLite* msg);
175   std::string* Mutable(const LazyString& default_value, Arena* arena,
176                        bool donated, uint32_t* donating_states, uint32_t mask,
177                        MessageLite* msg);
178 
179   // Mutable(nullptr_t) is an overload to explicitly support Mutable(nullptr)
180   // calls used by the internal parser logic. This provides API equivalence with
181   // ArenaStringPtr, while still protecting against calls with arena pointers.
182   std::string* Mutable(std::nullptr_t);
183   std::string* MutableNoCopy(std::nullptr_t);
184 
185   // Takes a std::string that is heap-allocated, and takes ownership. The
186   // std::string's destructor is registered with the arena. Used to implement
187   // set_allocated_<field> in generated classes.
188   //
189   // If this field is donated, this method undonates this field by mutating the
190   // `donating_states` according to `mask`.
191   void SetAllocated(const std::string* default_value, std::string* value,
192                     Arena* arena, bool donated, uint32_t* donating_states,
193                     uint32_t mask, MessageLite* msg);
194 
195   void SetAllocatedNoArena(const std::string* default_value,
196                            std::string* value);
197 
198   // Release returns a std::string* instance that is heap-allocated and is not
199   // Own()'d by any arena. If the field is not set, this returns nullptr. The
200   // caller retains ownership. Clears this field back to nullptr state. Used to
201   // implement release_<field>() methods on generated classes.
202   PROTOBUF_NODISCARD std::string* Release(Arena* arena, bool donated);
203   PROTOBUF_NODISCARD std::string* Release();
204 
205   // --------------------------------------------------------
206   // Below functions will be removed in subsequent code change
207   // --------------------------------------------------------
208 #ifdef DEPRECATED_METHODS_TO_BE_DELETED
Release(const std::string *,Arena * arena,bool donated)209   PROTOBUF_NODISCARD std::string* Release(const std::string*, Arena* arena,
210                                           bool donated) {
211     return Release(arena, donated);
212   }
213 
ReleaseNonDefault(const std::string *,Arena * arena)214   PROTOBUF_NODISCARD std::string* ReleaseNonDefault(const std::string*,
215                                                     Arena* arena) {
216     return Release();
217   }
218 
ReleaseNonDefaultNoArena(const std::string * default_value)219   std::string* ReleaseNonDefaultNoArena(const std::string* default_value) {
220     return Release();
221   }
222 
Set(const std::string *,absl::string_view value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)223   void Set(const std::string*, absl::string_view value, Arena* arena,
224            bool donated, uint32_t* donating_states, uint32_t mask,
225            MessageLite* msg) {
226     Set(value, arena, donated, donating_states, mask, msg);
227   }
228 
Set(const std::string *,std::string && value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)229   void Set(const std::string*, std::string&& value, Arena* arena, bool donated,
230            uint32_t* donating_states, uint32_t mask, MessageLite* msg) {
231     Set(std::move(value), arena, donated, donating_states, mask, msg);
232   }
233 
234 
235   template <typename FirstParam>
Set(FirstParam,const char * str,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)236   void Set(FirstParam, const char* str, ::google::protobuf::Arena* arena, bool donated,
237            uint32_t* donating_states, uint32_t mask, MessageLite* msg) {
238     Set(str, arena, donated, donating_states, mask, msg);
239   }
240 
241   template <typename FirstParam>
Set(FirstParam p1,const char * str,size_t size,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)242   void Set(FirstParam p1, const char* str, size_t size, ::google::protobuf::Arena* arena,
243            bool donated, uint32_t* donating_states, uint32_t mask,
244            MessageLite* msg) {
245     Set(str, size, arena, donated, donating_states, mask, msg);
246   }
247 
248   template <typename FirstParam, typename RefWrappedType>
Set(FirstParam p1,std::reference_wrapper<RefWrappedType> const_string_ref,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)249   void Set(FirstParam p1,
250            std::reference_wrapper<RefWrappedType> const_string_ref,
251            ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
252            uint32_t mask, MessageLite* msg) {
253     Set(const_string_ref, arena, donated, donating_states, mask, msg);
254   }
255 
SetBytes(const std::string *,absl::string_view value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)256   void SetBytes(const std::string*, absl::string_view value, Arena* arena,
257                 bool donated, uint32_t* donating_states, uint32_t mask,
258                 MessageLite* msg) {
259     Set(value, arena, donated, donating_states, mask, msg);
260   }
261 
262 
SetBytes(const std::string *,std::string && value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)263   void SetBytes(const std::string*, std::string&& value, Arena* arena,
264                 bool donated, uint32_t* donating_states, uint32_t mask,
265                 MessageLite* msg) {
266     Set(std::move(value), arena, donated, donating_states, mask, msg);
267   }
268 
269   template <typename FirstParam>
SetBytes(FirstParam p1,const char * str,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)270   void SetBytes(FirstParam p1, const char* str, ::google::protobuf::Arena* arena,
271                 bool donated, uint32_t* donating_states, uint32_t mask,
272                 MessageLite* msg) {
273     SetBytes(str, arena, donated, donating_states, mask, msg);
274   }
275 
276   template <typename FirstParam>
SetBytes(FirstParam p1,const void * p,size_t size,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)277   void SetBytes(FirstParam p1, const void* p, size_t size,
278                 ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
279                 uint32_t mask, MessageLite* msg) {
280     SetBytes(p, size, arena, donated, donating_states, mask, msg);
281   }
282 
283   template <typename FirstParam, typename RefWrappedType>
SetBytes(FirstParam p1,std::reference_wrapper<RefWrappedType> const_string_ref,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)284   void SetBytes(FirstParam p1,
285                 std::reference_wrapper<RefWrappedType> const_string_ref,
286                 ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
287                 uint32_t mask, MessageLite* msg) {
288     SetBytes(const_string_ref.get(), arena, donated, donating_states, mask,
289              msg);
290   }
291 
SetNoArena(const std::string *,absl::string_view value)292   void SetNoArena(const std::string*, absl::string_view value) {
293     SetNoArena(value);
294   }
SetNoArena(const std::string *,std::string && value)295   void SetNoArena(const std::string*, std::string&& value) {
296     SetNoArena(std::move(value));
297   }
298 
Mutable(ArenaStringPtr::EmptyDefault,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)299   std::string* Mutable(ArenaStringPtr::EmptyDefault, Arena* arena, bool donated,
300                        uint32_t* donating_states, uint32_t mask,
301                        MessageLite* msg) {
302     return Mutable(arena, donated, donating_states, mask, msg);
303   }
304 
MutableNoArenaNoDefault(const std::string *)305   PROTOBUF_NDEBUG_INLINE std::string* MutableNoArenaNoDefault(
306       const std::string* /*default_value*/) {
307     return MutableNoCopy(nullptr);
308   }
309 
310 #endif  // DEPRECATED_METHODS_TO_BE_DELETED
311 
312   // Arena-safety semantics: this is guarded by the logic in
313   // Swap()/UnsafeArenaSwap() at the message level, so this method is
314   // 'unsafe' if called directly.
315   inline PROTOBUF_NDEBUG_INLINE static void InternalSwap(
316       InlinedStringField* lhs, bool lhs_arena_dtor_registered,
317       MessageLite* lhs_msg,  //
318       InlinedStringField* rhs, bool rhs_arena_dtor_registered,
319       MessageLite* rhs_msg, Arena* arena);
320 
321   // Frees storage (if not on an arena).
Destroy(const std::string * default_value,Arena * arena)322   PROTOBUF_NDEBUG_INLINE void Destroy(const std::string* default_value,
323                                       Arena* arena) {
324     if (arena == nullptr) {
325       DestroyNoArena(default_value);
326     }
327   }
328   PROTOBUF_NDEBUG_INLINE void DestroyNoArena(const std::string* default_value);
329 
330   // Clears content, but keeps allocated std::string, to avoid the overhead of
331   // heap operations. After this returns, the content (as seen by the user) will
332   // always be the empty std::string.
ClearToEmpty()333   PROTOBUF_NDEBUG_INLINE void ClearToEmpty() { ClearNonDefaultToEmpty(); }
ClearNonDefaultToEmpty()334   PROTOBUF_NDEBUG_INLINE void ClearNonDefaultToEmpty() {
335     get_mutable()->clear();
336   }
337 
338   // Clears content, but keeps allocated std::string if arena != nullptr, to
339   // avoid the overhead of heap operations. After this returns, the content (as
340   // seen by the user) will always be equal to |default_value|.
341   void ClearToDefault(const LazyString& default_value, Arena* arena,
342                       bool donated);
343 
344   // Generated code / reflection only! Returns a mutable pointer to the string.
345   PROTOBUF_NDEBUG_INLINE std::string* UnsafeMutablePointer();
346 
347   // InlinedStringField doesn't have things like the `default_value` pointer in
348   // ArenaStringPtr.
IsDefault()349   static constexpr bool IsDefault() { return false; }
IsDefault(const std::string *)350   static constexpr bool IsDefault(const std::string*) { return false; }
351 
352  private:
353   // ScopedCheckInvariants checks all string in-variants at destruction.
354   class ScopedCheckInvariants;
355 
Destruct()356   void Destruct() { get_mutable()->~basic_string(); }
357 
358   PROTOBUF_NDEBUG_INLINE std::string* get_mutable();
359   PROTOBUF_NDEBUG_INLINE const std::string* get_const() const;
360 
361   union {
362     std::string str_;
363     char dummy_;
364   };
365 
366   std::string* MutableSlow(::google::protobuf::Arena* arena, bool donated,
367                            uint32_t* donating_states, uint32_t mask,
368                            MessageLite* msg);
369 
370 
371   // When constructed in an Arena, we want our destructor to be skipped.
372   friend class ::google::protobuf::Arena;
373   typedef void InternalArenaConstructable_;
374   typedef void DestructorSkippable_;
375 };
376 
get_mutable()377 inline std::string* InlinedStringField::get_mutable() { return &str_; }
378 
get_const()379 inline const std::string* InlinedStringField::get_const() const {
380   return &str_;
381 }
382 
InlinedStringField(const std::string & default_value)383 inline InlinedStringField::InlinedStringField(
384     const std::string& default_value) {
385   new (get_mutable()) std::string(default_value);
386 }
387 
388 
389 #ifdef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE
InitDonatingStates()390 constexpr uint32_t InitDonatingStates() { return ~0u; }
InternalRegisterArenaDtor(Arena *,void *,void (*)(void *))391 inline void InternalRegisterArenaDtor(Arena*, void*, void (*)(void*)) {}
392 #else   // !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE
InitDonatingStates()393 constexpr uint32_t InitDonatingStates() { return 0u; }
InternalRegisterArenaDtor(Arena * arena,void * object,void (* destruct)(void *))394 inline void InternalRegisterArenaDtor(Arena* arena, void* object,
395                                       void (*destruct)(void*)) {
396   if (arena != nullptr) {
397     arena->OwnCustomDestructor(object, destruct);
398   }
399 }
400 #endif  // GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE
401 
InlinedStringField(Arena *)402 inline InlinedStringField::InlinedStringField(Arena* /*arena*/) : str_() {}
403 
InlinedStringField(Arena * arena,const InlinedStringField & rhs)404 inline InlinedStringField::InlinedStringField(Arena* arena,
405                                               const InlinedStringField& rhs) {
406   const std::string& src = *rhs.get_const();
407   ::new (static_cast<void*>(&str_)) std::string(src);
408 }
409 
GetNoArena()410 inline const std::string& InlinedStringField::GetNoArena() const {
411   return *get_const();
412 }
413 
SetAllocatedNoArena(const std::string *,std::string * value)414 inline void InlinedStringField::SetAllocatedNoArena(
415     const std::string* /*default_value*/, std::string* value) {
416   if (value == nullptr) {
417     // Currently, inlined string field can't have non empty default.
418     get_mutable()->clear();
419   } else {
420     get_mutable()->assign(std::move(*value));
421     delete value;
422   }
423 }
424 
DestroyNoArena(const std::string *)425 inline void InlinedStringField::DestroyNoArena(const std::string*) {
426   // This is invoked from the generated message's ArenaDtor, which is used to
427   // clean up objects not allocated on the Arena.
428   this->~InlinedStringField();
429 }
430 
SetNoArena(absl::string_view value)431 inline void InlinedStringField::SetNoArena(absl::string_view value) {
432   get_mutable()->assign(value.data(), value.length());
433 }
434 
SetNoArena(std::string && value)435 inline void InlinedStringField::SetNoArena(std::string&& value) {
436   get_mutable()->assign(std::move(value));
437 }
438 
InternalSwap(InlinedStringField * lhs,bool lhs_arena_dtor_registered,MessageLite * lhs_msg,InlinedStringField * rhs,bool rhs_arena_dtor_registered,MessageLite * rhs_msg,Arena * arena)439 inline PROTOBUF_NDEBUG_INLINE void InlinedStringField::InternalSwap(
440     InlinedStringField* lhs, bool lhs_arena_dtor_registered,
441     MessageLite* lhs_msg,  //
442     InlinedStringField* rhs, bool rhs_arena_dtor_registered,
443     MessageLite* rhs_msg, Arena* arena) {
444 #ifdef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE
445   lhs->get_mutable()->swap(*rhs->get_mutable());
446   if (!lhs_arena_dtor_registered && rhs_arena_dtor_registered) {
447     lhs_msg->OnDemandRegisterArenaDtor(arena);
448   } else if (lhs_arena_dtor_registered && !rhs_arena_dtor_registered) {
449     rhs_msg->OnDemandRegisterArenaDtor(arena);
450   }
451 #else
452   (void)arena;
453   (void)lhs_arena_dtor_registered;
454   (void)rhs_arena_dtor_registered;
455   (void)lhs_msg;
456   (void)rhs_msg;
457   lhs->get_mutable()->swap(*rhs->get_mutable());
458 #endif
459 }
460 
Set(absl::string_view value,Arena * arena,bool donated,uint32_t *,uint32_t,MessageLite *)461 inline void InlinedStringField::Set(absl::string_view value, Arena* arena,
462                                     bool donated, uint32_t* /*donating_states*/,
463                                     uint32_t /*mask*/, MessageLite* /*msg*/) {
464   (void)arena;
465   (void)donated;
466   SetNoArena(value);
467 }
468 
Set(const char * str,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)469 inline void InlinedStringField::Set(const char* str, ::google::protobuf::Arena* arena,
470                                     bool donated, uint32_t* donating_states,
471                                     uint32_t mask, MessageLite* msg) {
472   Set(absl::string_view(str), arena, donated, donating_states, mask, msg);
473 }
474 
Set(const char * str,size_t size,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)475 inline void InlinedStringField::Set(const char* str, size_t size,
476                                     ::google::protobuf::Arena* arena, bool donated,
477                                     uint32_t* donating_states, uint32_t mask,
478                                     MessageLite* msg) {
479   Set(absl::string_view{str, size}, arena, donated, donating_states, mask, msg);
480 }
481 
SetBytes(absl::string_view value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)482 inline void InlinedStringField::SetBytes(absl::string_view value, Arena* arena,
483                                          bool donated,
484                                          uint32_t* donating_states,
485                                          uint32_t mask, MessageLite* msg) {
486   Set(value, arena, donated, donating_states, mask, msg);
487 }
488 
SetBytes(std::string && value,Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)489 inline void InlinedStringField::SetBytes(std::string&& value, Arena* arena,
490                                          bool donated,
491                                          uint32_t* donating_states,
492                                          uint32_t mask, MessageLite* msg) {
493   Set(std::move(value), arena, donated, donating_states, mask, msg);
494 }
495 
SetBytes(const char * str,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)496 inline void InlinedStringField::SetBytes(const char* str,
497                                          ::google::protobuf::Arena* arena, bool donated,
498                                          uint32_t* donating_states,
499                                          uint32_t mask, MessageLite* msg) {
500   Set(str, arena, donated, donating_states, mask, msg);
501 }
502 
SetBytes(const void * p,size_t size,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)503 inline void InlinedStringField::SetBytes(const void* p, size_t size,
504                                          ::google::protobuf::Arena* arena, bool donated,
505                                          uint32_t* donating_states,
506                                          uint32_t mask, MessageLite* msg) {
507   Set(static_cast<const char*>(p), size, arena, donated, donating_states, mask,
508       msg);
509 }
510 
511 template <typename RefWrappedType>
Set(std::reference_wrapper<RefWrappedType> const_string_ref,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)512 inline void InlinedStringField::Set(
513     std::reference_wrapper<RefWrappedType> const_string_ref,
514     ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
515     uint32_t mask, MessageLite* msg) {
516   Set(const_string_ref.get(), arena, donated, donating_states, mask, msg);
517 }
518 
519 template <typename RefWrappedType>
SetBytes(std::reference_wrapper<RefWrappedType> const_string_ref,::google::protobuf::Arena * arena,bool donated,uint32_t * donating_states,uint32_t mask,MessageLite * msg)520 inline void InlinedStringField::SetBytes(
521     std::reference_wrapper<RefWrappedType> const_string_ref,
522     ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states,
523     uint32_t mask, MessageLite* msg) {
524   Set(const_string_ref.get(), arena, donated, donating_states, mask, msg);
525 }
526 
UnsafeMutablePointer()527 inline std::string* InlinedStringField::UnsafeMutablePointer() {
528   return get_mutable();
529 }
530 
Mutable(std::nullptr_t)531 inline std::string* InlinedStringField::Mutable(std::nullptr_t) {
532   return get_mutable();
533 }
534 
MutableNoCopy(std::nullptr_t)535 inline std::string* InlinedStringField::MutableNoCopy(std::nullptr_t) {
536   return get_mutable();
537 }
538 
539 }  // namespace internal
540 }  // namespace protobuf
541 }  // namespace google
542 
543 #include "google/protobuf/port_undef.inc"
544 
545 #endif  // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
546