class InlinedStringField
Defined at line 84 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
InlinedStringField wraps a std::string instance and exposes an API similar to
ArenaStringPtr's wrapping of a std::string* instance.
InlinedStringField has a donating mechanism that allows string buffer
allocated on arena. A string is donated means both the string container and
the data buffer are on arena. The donating mechanism here is similar to the
one in ArenaStringPtr with some differences:
When an InlinedStringField is constructed, the donating state is true. This
is because the string container is directly stored in the message on the
arena:
Construction: donated=true
Arena:
+-----------------------+
|Message foo: |
| +-------------------+ |
| |InlinedStringField:| |
| | +-----+ | |
| | | | | | | |
| | +-----+ | |
| +-------------------+ |
+-----------------------+
When lvalue Set is called, the donating state is still true. String data will
be allocated on the arena:
Lvalue Set: donated=true
Arena:
+-----------------------+
|Message foo: |
| +-------------------+ |
| |InlinedStringField:| |
| | +-----+ | |
| | | | | | | |
| | +|----+ | |
| +--|----------------+ |
| V |
| +----------------+ |
| |'f','o','o',... | |
| +----------------+ |
+-----------------------+
Some operations will undonate a donated string, including: Mutable,
SetAllocated, Rvalue Set, and Swap with a non-donated string.
For more details of the donating states transitions, go/pd-inlined-string.
Public Methods
size_t Capacity ()
The existing capacity of the backing string.
It might be donated capacity.
template <typename = void>
void InlinedStringField ()
OSS may use C++17 which would fail on constexpr constructor with
std::string. As no actual OSS code refers to this constructor, templating
it avoids ifdef'ing.
Defined at line 90 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void InlinedStringField (const InlinedStringField & )
Defined at line 91 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
InlinedStringField & operator= (const InlinedStringField & )
Defined at line 92 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void ~InlinedStringField ()
Defined at line 96 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
const std::string & Get ()
Basic accessors.
Defined at line 132 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void Destroy (Arena * arena)
Frees storage (if not on an arena).
Defined at line 170 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void ClearToEmpty ()
Clears content, but keeps allocated std::string, to avoid the overhead of
heap operations. After this returns, the content (as seen by the user) will
always be the empty std::string.
Defined at line 180 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void ClearNonDefaultToEmpty ()
Defined at line 181 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
bool IsDefault ()
InlinedStringField doesn't have things like the `default_value` pointer in
ArenaStringPtr.
Defined at line 196 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
bool IsDefault (const std::string * )
Defined at line 197 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void InlinedStringField (const std::string & default_value)
Defined at line 259 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void InlinedStringField (Arena * arena)
Defined at line 265 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void InlinedStringField (Arena * arena, const InlinedStringField & rhs)
Defined at line 267 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void Set (absl::string_view value, Arena * arena)
Lvalue Set.
Defined at line 317 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void Set (std::string && value, Arena * arena)
Rvalue Set. If this field is donated, this method might undonate this
field.
void Set (const char * str, Arena * arena)
Defined at line 322 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void Set (const char *str,size_tsize,Arena *arena)
Defined at line 326 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
template <typename RefWrappedType>
void Set (std::reference_wrapper<RefWrappedType> const_string_ref, Arena * arena)
Defined at line 350 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetBytes (absl::string_view value, Arena * arena)
Defined at line 331 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetBytes (std::string && value, Arena * arena)
Defined at line 336 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetBytes (const char * str, Arena * arena)
Defined at line 340 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetBytes (const void *p,size_tsize,Arena *arena)
Defined at line 344 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
template <typename RefWrappedType>
void SetBytes (std::reference_wrapper<RefWrappedType> const_string_ref, Arena * arena)
Defined at line 356 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetNoArena (absl::string_view value)
Defined at line 293 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetNoArena (std::string && value)
Defined at line 297 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
const std::string & GetNoArena ()
Defined at line 273 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
std::string * Mutable (Arena * arena)
Mutable returns a std::string* instance that is heap-allocated. If this
field is donated, this method undonates this field and copies the content
of the original string to the returning string.
std::string * Mutable (std::nullptr_t )
Mutable(nullptr_t) is an overload to explicitly support Mutable(nullptr)
calls used by the internal parser logic. This provides API equivalence with
ArenaStringPtr, while still protecting against calls with arena pointers.
Defined at line 365 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
std::string * MutableNoCopy (std::nullptr_t )
Defined at line 369 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void SetAllocated (std::string * value, Arena * arena)
Takes a std::string that is heap-allocated, and takes ownership. The
std::string's destructor is registered with the arena. Used to implement
set_allocated_
<field
> in generated classes.
If this field is donated, this method might undonate this field.
void SetAllocatedNoArena (std::string * value)
Defined at line 277 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
std::string * Release (Arena * arena)
Release returns a std::string* instance that is heap-allocated and is not
Own()'d by any arena. The caller retains ownership. Clears this field back
to nullptr state. Used to implement release_
<field
>() methods on generated
classes.
std::string * Release ()
void InternalSwap (InlinedStringField *lhs,InlinedStringField *rhs,Arena *arena)
Arena-safety semantics: this is guarded by the logic in
Swap()/UnsafeArenaSwap() at the message level, so this method is
'unsafe' if called directly.
Defined at line 301 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void DestroyNoArena ()
Defined at line 287 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
void ClearToDefault (const LazyString &default_value,Arena *arena,booldonated)
Clears content, but keeps allocated std::string if arena != nullptr, to
avoid the overhead of heap operations. After this returns, the content (as
seen by the user) will always be equal to |default_value|.
std::string * UnsafeMutablePointer ()
Generated code / reflection only! Returns a mutable pointer to the string.
Defined at line 361 of file ../../third_party/protobuf/src/src/google/protobuf/inlined_string_field.h
bool IsDonated ()
Whether the string is in donated mode.
size_t SpaceUsedExcludingSelfLong ()
Friends
class Arena