class InternalMetadataOffset
Defined at line 23 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
A wrapper around the offset to internal metadata from the address of another
field in the same class/struct. This is used to reduce the size of fields
that need access to an Arena which can be found in the containing object.
Public Methods
void InternalMetadataOffset ()
A sentinel `InternalMetadataOffset`, which does not point to any metadata.
Defined at line 29 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
template <typename T, size_t kFieldOffset>
InternalMetadataOffset Build ()
Constructs an `InternalMetadataOffset` which can recover the
`InternalMetadata` from a containing type `T` given the starting address of
the field at offset `FieldOffset` within `T`.
This method expects to find a field with name `_internal_metadata_` in `T`,
and the type of that field should be `InternalMetadata`.
Defined at line 38 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
template <typename T>
InternalMetadataOffset BuildFromDynamicOffset (size_t field_offset)
Builds an `InternalMetadataOffset` from a dynamic offset from the start of
`T`. This is used by `DynamicMessage` to build an `InternalMetadataOffset`
for a field at a given runtime-derived offset from the start of the
message.
This function performs runtime checks to ensure that the offset from
`_internal_metadata_` to the field is within the range of an int32_t. This
is necessary to prevent integer overflow when calculating the offset.
Defined at line 71 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
template <size_t kMemberOffset>
InternalMetadataOffset TranslateForMember ()
Translates an offset relative to some class `T` to an offset relative to
the member at offset `kMemberOffset` within `T`. This is used when passing
`InternalMetadataOffset`s to members of a class where the offset was
constructed relative to the start of `T`.
For example, here is how you would pass an `InternalMetadataOffset` to a
member `Baz` of a class `Bar`, which itself is a member of `Foo`.
```cc
struct Baz {
int some_value;
InternalMetadataResolver resolver;
Baz(int value, InternalMetadataOffset offset)
: some_value(value), resolver(offset) {}
};
struct Bar {
int some_value;
Baz baz;
Bar(int value, InternalMetadataOffset offset)
: some_value(value),
baz(2 * value, offset.TranslateForMember
<offsetof
(Bar, baz)>()) {}
};
struct Foo {
InternalMetadata _internal_metadata_;
Bar field1;
explicit Foo(Arena* arena)
: _internal_metadata_(arena),
field1(123,
InternalMetadataOffset::Build
<Foo
, PROTOBUF_FIELD_OFFSET(
Foo, field1)>()) {}
};
```
Defined at line 134 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
bool IsSentinel ()
If true, this `InternalMetadataOffset` does not point to any metadata.
Defined at line 143 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h
int32_t Offset ()
The offset from the start of the field to the internal metadata of the
containing type (either a `MessageLite` or some other internal class, like
`RepeatedPtrFieldWithArena`).
Defined at line 150 of file ../../third_party/protobuf/src/src/google/protobuf/internal_metadata_locator.h