struct ArenaStringPtr

Defined at line 229 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

This class encapsulates a pointer to a std::string with or without arena

owned contents, tagged by the bottom bits of the string pointer. It is a

high-level wrapper that almost directly corresponds to the interface required

by string fields in generated code. It replaces the old std::string* pointer

in such cases.

The string pointer is tagged to be either a default, externally owned value,

a mutable heap allocated value, or an arena allocated value. The object uses

a single global instance of an empty string that is used as the initial

default value. Fields that have empty default values directly use this global

default. Fields that have non empty default values are supported through

lazily initialized default values managed by the LazyString class.

Generated code and reflection code both ensure that ptr_ is never null.

Because ArenaStringPtr is used in oneof unions, its constructor is a NOP and

the field is always manually initialized via method calls.

See TaggedStringPtr for more information about the types of string values

being held, and the mutable and ownership invariants for each type.

Public Methods

void ArenaStringPtr ()

Default constructor, leaves current instance uninitialized (does nothing)

Defined at line 231 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ArenaStringPtr (ExplicitlyConstructedArenaString * default_value, ConstantInitialized )

Constexpr constructor, initializes to a constexpr, empty string value.

Defined at line 234 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ArenaStringPtr (Arena * arena)

Arena enabled constructor for strings without a default value.

Initializes this instance to a constexpr, empty string value, unless debug

hardening is enabled, in which case this instance will hold a forced copy.

Defined at line 241 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ArenaStringPtr (Arena * arena, const LazyString & default_value)

Arena enabled constructor for strings with a non-empty default value.

Initializes this instance to a constexpr, empty string value, unless debug

hardening is enabled, in which case this instance will be forced to hold a

forced copy of the value in `default_value`.

Defined at line 252 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ArenaStringPtr (Arena * arena, const ArenaStringPtr & rhs)

Arena enabled copy constructor for strings without a default value.

This instance will be initialized with a copy of the value in `rhs`.

If `rhs` holds a default (empty) value, then this instance will also be

initialized with the default empty value, unless debug hardening is

enabled, in which case this instance will be forced to hold a copy of

an empty default value.

Defined at line 265 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ArenaStringPtr (Arena * arena, const ArenaStringPtr & rhs, const LazyString & default_value)

Arena enabled copy constructor for strings with a non-empty default value.

This instance will be initialized with a copy of the value in `rhs`.

If `rhs` holds a default (empty) value, then this instance will also be

initialized with the default empty value, unless debug hardening is

enabled, in which case this instance will be forced to hold forced copy

of the value in `default_value`.

Defined at line 274 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void InitDefault ()

Called from generated code / reflection runtime only. Resets value to point

to a default string pointer, with the semantics that this ArenaStringPtr

does not own the pointed-to memory. Disregards initial value of ptr_ (so

this is the *ONLY* safe method to call after construction or when

reinitializing after becoming the active field in a oneof union).

Defined at line 451 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void InitExternal (const std::string * str)

Similar to `InitDefault` except that it allows the default value to be

initialized to an externally owned string. This method is called from

parsing code. `str` must not be null and outlive this instance.

Defined at line 455 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void InitAllocated (std::string * str, Arena * arena)

Called from generated code / reflection runtime only. Resets the value of

this instances to the heap allocated value in `str`. `str` must not be

null. Invokes `arena->Own(str)` to transfer ownership into the arena if

`arena` is not null, else, `str` will be owned by ArenaStringPtr. This

function should only be used to initialize a ArenaStringPtr or on an

instance known to not carry any heap allocated value.

Defined at line 459 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void Set (absl::string_view value, Arena * arena)
void Set (std::string && value, Arena * arena)
template <typename... OverloadDisambiguator>
void Set (const std::string & value, Arena * arena)
void Set (const char * s, Arena * arena)

Defined at line 468 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void Set (const char * s, size_t n, Arena * arena)

Defined at line 472 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void SetBytes (absl::string_view value, Arena * arena)

Defined at line 476 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

std::string * Mutable (Arena * arena)

Returns a mutable std::string reference.

The version accepting a `LazyString` value is used in the generated code to

initialize mutable copies for fields with a non-empty default where the

default value is lazily initialized.

std::string * Mutable (const LazyString & default_value, Arena * arena)
std::string * MutableNoCopy (Arena * arena)

Gets a mutable pointer with unspecified contents.

This function is identical to Mutable(), except it is optimized for the

case where the caller is not interested in the current contents. For

example, if the current field is not mutable, it will re-initialize the

value with an empty string rather than a (non-empty) default value.

Likewise, if the current value is a fixed size arena string with contents,

it will be initialized into an empty mutable arena string.

std::string * Release ()

Release returns a std::string* instance that is heap-allocated and is not

Own()'d by any arena. If the field is not set, this returns nullptr. The

caller retains ownership. Clears this field back to the default state.

Used to implement release_

<field

>() methods on generated classes.

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.

void Destroy ()

Frees storage (if not on an arena).

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. Assumes that |default_value| is an empty

std::string.

void ClearToDefault (const LazyString & default_value, ::google::protobuf::Arena * arena)

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|.

template <typename RefWrappedType>
void Set (std::reference_wrapper<RefWrappedType> const_string_ref, ::google::protobuf::Arena * arena)

Defined at line 313 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

const std::string & Get ()

Basic accessors.

Defined at line 335 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

const std::string * UnsafeGetPointer ()

Returns a pointer to the stored contents for this instance.

This method is for internal debugging and tracking purposes only.

Defined at line 342 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void UnsafeSetTaggedPointer (TaggedStringPtr value)

Internal setter used only at parse time to directly set a donated string

value.

Defined at line 385 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

bool IsDefault ()

Returns true if this instances holds an immutable default value.

Defined at line 392 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

template <>
void Set<<>> (const std::string & value, Arena * arena)
template <>
void SetBytes<<>> (const std::string & value, Arena * arena)

Defined at line 484 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void SetBytes (std::string && value, Arena * arena)

Defined at line 489 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

template <typename... OverloadDisambiguator>
void SetBytes (const std::string & value, Arena * arena)
void SetBytes (const char * s, Arena * arena)

Defined at line 493 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void SetBytes (const void * p, size_t n, Arena * arena)

Defined at line 497 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void ClearNonDefaultToEmpty ()

Clears content, assuming that the current value is not the empty

string default.

Defined at line 524 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

void InternalSwap (ArenaStringPtr * rhs, ArenaStringPtr * lhs, Arena * arena)

Swaps internal pointers. 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 501 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

std::string * UnsafeMutablePointer ()

Generated code only! An optimization, in certain cases the generated

code is certain we can obtain a std::string with no default checks and

tag tests.

Defined at line 529 of file ../../third_party/protobuf/src/google/protobuf/arenastring.h

Friends

class EpsCopyInputStream
class TcParser
class SwapFieldHelper