class InlinedStringField

Defined at line 86 of file ../../third_party/protobuf/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.

default_value parameters are taken for consistency with ArenaStringPtr, but

are not used for most methods. With inlining, these should be removed from

the generated binary.

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

void ClearToDefault (const LazyString & default_value, Arena * arena, bool donated)

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

void InlinedStringField ()

Defined at line 88 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void InlinedStringField (const InlinedStringField & )

Defined at line 89 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

InlinedStringField & operator= (const InlinedStringField & )

Defined at line 90 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void Init ()

No need to do dynamic initialization here.

Defined at line 93 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void InlinedStringField (const ExplicitlyConstructed<std::string> * , bool )

Add the dummy parameter just to make InlinedStringField(nullptr)

unambiguous.

Defined at line 96 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void ~InlinedStringField ()

Defined at line 113 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

const std::string & Get ()

Basic accessors.

Defined at line 166 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void Destroy (const std::string * default_value, Arena * arena)

Frees storage (if not on an arena).

Defined at line 322 of file ../../third_party/protobuf/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 333 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void ClearNonDefaultToEmpty ()

Defined at line 334 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

bool IsDefault ()

InlinedStringField doesn't have things like the `default_value` pointer in

ArenaStringPtr.

Defined at line 349 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

bool IsDefault (const std::string * )

Defined at line 350 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void InlinedStringField (const std::string & default_value)

Defined at line 383 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void InlinedStringField (Arena * arena)

Defined at line 402 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

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

Defined at line 404 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void Set (absl::string_view value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Lvalue Set. To save space, we pack the donating states of multiple

InlinedStringFields into an uint32_t `donating_states`. The `mask`

indicates the position of the bit for this InlinedStringField. `donated` is

whether this field is donated.

The caller should guarantee that:

`donated == ((donating_states

&

~mask) != 0)`

This method never changes the `donating_states`.

Defined at line 461 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void Set (std::string && value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Rvalue Set. If this field is donated, this method will undonate this field

by mutating the `donating_states` according to `mask`.

void Set (const char * str, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 469 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void Set (const char * str, size_t size, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 475 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

template <typename RefWrappedType>
void Set (std::reference_wrapper<RefWrappedType> const_string_ref, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 512 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetBytes (absl::string_view value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 482 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetBytes (std::string && value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

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

void SetBytes (const char * str, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 496 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetBytes (const void * p, size_t size, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 503 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

template <typename RefWrappedType>
void SetBytes (std::reference_wrapper<RefWrappedType> const_string_ref, ::google::protobuf::Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Defined at line 520 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetNoArena (absl::string_view value)

Defined at line 431 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetNoArena (std::string && value)

Defined at line 435 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

const std::string & GetNoArena ()

Defined at line 410 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

std::string * Mutable (Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

Mutable returns a std::string* instance that is heap-allocated. If this

field is donated, this method undonates this field by mutating the

`donating_states` according to `mask`, and copies the content of the

original string to the returning string.

std::string * Mutable (const LazyString & default_value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)
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 531 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

std::string * MutableNoCopy (std::nullptr_t )

Defined at line 535 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void SetAllocated (const std::string * default_value, std::string * value, Arena * arena, bool donated, uint32_t * donating_states, uint32_t mask, MessageLite * msg)

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 undonates this field by mutating the

`donating_states` according to `mask`.

void SetAllocatedNoArena (const std::string * default_value, std::string * value)

Defined at line 414 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

std::string * Release (Arena * arena, bool donated)

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 nullptr state. Used to

implement release_

<field

>() methods on generated classes.

std::string * Release ()
void InternalSwap (InlinedStringField * lhs, bool lhs_arena_dtor_registered, MessageLite * lhs_msg, InlinedStringField * rhs, bool rhs_arena_dtor_registered, MessageLite * rhs_msg, 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 439 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

void DestroyNoArena (const std::string * default_value)

Defined at line 425 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

std::string * UnsafeMutablePointer ()

Generated code / reflection only! Returns a mutable pointer to the string.

Defined at line 527 of file ../../third_party/protobuf/src/google/protobuf/inlined_string_field.h

Friends

class Arena