unknown_field_set.h

This section contains reference documentation for working with protocol buffer classes in C++.

#include <google/protobuf/unknown_field_set.h>
namespace google::protobuf

Contains classes used to keep track of unrecognized fields seen while parsing a protocol message.

Classes in this file

An UnknownFieldSet contains fields that were encountered while parsing a message but were not defined by its type.
Represents one field in an UnknownFieldSet.

class UnknownFieldSet

#include <google/protobuf/unknown_field_set.h>
namespace google::protobuf

An UnknownFieldSet contains fields that were encountered while parsing a message but were not defined by its type.

Keeping track of these can be useful, especially in that they may be written if the message is serialized again without being cleared in between. This means that software which simply receives messages and forwards them to other servers does not need to be updated every time a new field is added to the message definition.

To get the UnknownFieldSet attached to any message, call Reflection::GetUnknownFields().

This class is necessarily tied to the protocol buffer wire format, unlike the Reflection interface which is independent of any serialization scheme.

Members

UnknownFieldSet()
~UnknownFieldSet()
void
Clear()
Remove all fields.
void
ClearAndFreeMemory()
Remove all fields and deallocate internal data objects.
bool
empty() const
Is this set empty?
void
MergeFrom(const UnknownFieldSet & other)
Merge the contents of some other UnknownFieldSet with this one.
void
MergeFromAndDestroy(UnknownFieldSet * other)
Similar to above, but this function will destroy the contents of other.
void
Swap(UnknownFieldSet * x)
Swaps the contents of some other UnknownFieldSet with this one.
size_t
SpaceUsedExcludingSelfLong() const
Computes (an estimate of) the total number of bytes currently used for storing the unknown fields in memory. more...
int
SpaceUsedExcludingSelf() const
size_t
SpaceUsedLong() const
Version of SpaceUsed() including sizeof(*this).
int
SpaceUsed() const
int
field_count() const
Returns the number of fields present in the UnknownFieldSet.
const UnknownField &
field(int index) const
Get a field in the set, where 0 <= index < field_count(). more...
UnknownField *
mutable_field(int index)
Get a mutable pointer to a field in the set, where 0 <= index < field_count(). more...
static void
MergeToInternalMetadata(const UnknownFieldSet & other, internal::InternalMetadata * metadata)
Merge the contents an UnknownFieldSet with the UnknownFieldSet in *metadata, if there is one. more...

Adding fields

void
AddVarint(int number, uint64 value)
void
AddFixed32(int number, uint32 value)
void
AddFixed64(int number, uint64 value)
void
AddLengthDelimited(int number, const std::string & value)
std::string *
AddLengthDelimited(int number)
UnknownFieldSet *
AddGroup(int number)
void
AddField(const UnknownField & field)
Adds an unknown field from another set.
void
DeleteSubrange(int start, int num)
Delete fields with indices in the range [start . more...
void
DeleteByNumber(int number)
Delete all fields with a specific field number. more...

Parsing helpers

These work exactly like the similarly-named methods of Message.
bool
MergeFromCodedStream(io::CodedInputStream * input)
bool
ParseFromCodedStream(io::CodedInputStream * input)
bool
ParseFromZeroCopyStream(io::ZeroCopyInputStream * input)
bool
ParseFromArray(const void * data, int size)
bool
ParseFromString(const std::string & data)
template bool
MergeFromMessage(const MessageType & message)
Merges this message's unknown field data (if any). more...
static const UnknownFieldSet &
default_instance()

size_t UnknownFieldSet::SpaceUsedExcludingSelfLong() const

Computes (an estimate of) the total number of bytes currently used for storing the unknown fields in memory.

Does NOT include sizeof(*this) in the calculation.


const UnknownField &
    UnknownFieldSet::field(
        int index) const

Get a field in the set, where 0 <= index < field_count().

The fields appear in the order in which they were added.


UnknownField * UnknownFieldSet::mutable_field(
        int index)

Get a mutable pointer to a field in the set, where 0 <= index < field_count().

The fields appear in the order in which they were added.


static void UnknownFieldSet::MergeToInternalMetadata(
        const UnknownFieldSet & other,
        internal::InternalMetadata * metadata)

Merge the contents an UnknownFieldSet with the UnknownFieldSet in *metadata, if there is one.

If *metadata doesn't have an UnknownFieldSet then add one to it and make it be a copy of the first arg.


void UnknownFieldSet::DeleteSubrange(
        int start,
        int num)

Delete fields with indices in the range [start .

. start+num-1]. Caution: implementation moves all fields with indices [start+num .. ].


void UnknownFieldSet::DeleteByNumber(
        int number)

Delete all fields with a specific field number.

The order of left fields is preserved. Caution: implementation moves all fields after the first deleted field.


template bool UnknownFieldSet::MergeFromMessage(
        const MessageType & message)

Merges this message's unknown field data (if any).

This works whether the message is a lite or full proto (for legacy reasons, lite and full return different types for MessageType::unknown_fields()).

class UnknownField

#include <google/protobuf/unknown_field_set.h>
namespace google::protobuf

Represents one field in an UnknownFieldSet.

Members

enum
Type
uint64
varint_
uint32
fixed32_
uint64
fixed64_
union LengthDelimited
length_delimited_
UnknownFieldSet *
group_
int
number() const
The field's field number, as seen on the wire.
Type
type() const
The field type.

Accessors

Each method works only for UnknownFields of the corresponding type.
uint32
number_
uint32
type_
union google::protobuf::UnknownField::@35
data_
uint64
varint() const
uint32
fixed32() const
uint64
fixed64() const
const std::string &
length_delimited() const
const UnknownFieldSet &
group() const
void
set_varint(uint64 value)
void
set_fixed32(uint32 value)
void
set_fixed64(uint64 value)
void
set_length_delimited(const std::string & value)
std::string *
mutable_length_delimited()
UnknownFieldSet *
mutable_group()
void
SerializeLengthDelimitedNoTag(io::CodedOutputStream * output) const
Serialization API. more...
size_t
GetLengthDelimitedSize() const
uint8 *
InternalSerializeLengthDelimitedNoTag(uint8 * target, io::EpsCopyOutputStream * stream) const
void
Delete()
If this UnknownField contains a pointer, delete it.
void
DeepCopy(const UnknownField & other)
Make a deep copy of any pointers in this UnknownField.
void
SetType(Type type)
Set the wire type of this UnknownField. more...

enum UnknownField::Type {
  TYPE_VARINT,
  TYPE_FIXED32,
  TYPE_FIXED64,
  TYPE_LENGTH_DELIMITED,
  TYPE_GROUP
}

TYPE_VARINT
TYPE_FIXED32
TYPE_FIXED64
TYPE_LENGTH_DELIMITED
TYPE_GROUP

void UnknownField::SerializeLengthDelimitedNoTag(
        io::CodedOutputStream * output) const

Serialization API.

These methods can take advantage of the underlying implementation and may achieve a better performance than using getters to retrieve the data and do the serialization yourself.


void UnknownField::SetType(
        Type type)

Set the wire type of this UnknownField.

Should only be used when this UnknownField is being created.

union UnknownField::LengthDelimited

#include <google/protobuf/unknown_field_set.h>
namespace google::protobuf

Members

std::string *
string_value