protozero::pbf_message< T > Class Template Reference

`#include <pbf_message.hpp>`

Inheritance diagram for protozero::pbf_message< T >:
[legend]
Collaboration diagram for protozero::pbf_message< T >:
[legend]

## Public Types

using | enum_type = T
Public Types inherited from protozero::pbf_reader
typedef const_varint_iterator< int32_t > | const_bool_iterator
| Forward iterator for iterating over bool (int32 varint) values.
typedef const_varint_iterator< int32_t > | const_enum_iterator
| Forward iterator for iterating over enum (int32 varint) values.
typedef const_varint_iterator< int32_t > | const_int32_iterator
| Forward iterator for iterating over int32 (varint) values.
typedef const_svarint_iterator< int32_t > | const_sint32_iterator
| Forward iterator for iterating over sint32 (varint) values.
typedef const_varint_iterator< uint32_t > | const_uint32_iterator
| Forward iterator for iterating over uint32 (varint) values.
typedef const_varint_iterator< int64_t > | const_int64_iterator
| Forward iterator for iterating over int64 (varint) values.
typedef const_svarint_iterator< int64_t > | const_sint64_iterator
| Forward iterator for iterating over sint64 (varint) values.
typedef const_varint_iterator< uint64_t > | const_uint64_iterator
| Forward iterator for iterating over uint64 (varint) values.

## Public Member Functions

template<typename... Args>
| pbf_message (Args &&...args) noexcept
bool | next ()
bool | next (T tag)
T | tag () const noexcept
Public Member Functions inherited from protozero::pbf_reader
| pbf_reader (const char *data, size_t length) noexcept
| pbf_reader (std::pair< const char *, size_t > data) noexcept
| pbf_reader (const std::string &data) noexcept
| pbf_reader () noexcept=default
| pbf_reader (const pbf_reader &) noexcept=default
| pbf_reader messages can be copied trivially.
| pbf_reader (pbf_reader &&) noexcept=default
| pbf_reader messages can be moved trivially.
pbf_reader & | operator= (const pbf_reader &other) noexcept=default
| pbf_reader messages can be copied trivially.
pbf_reader & | operator= (pbf_reader &&other) noexcept=default
| pbf_reader messages can be moved trivially.
| operator bool () const noexcept
size_t | length () const noexcept
bool | next ()
bool | next (pbf_tag_type tag)
pbf_tag_type | tag () const noexcept
pbf_wire_type | wire_type () const noexcept
bool | has_wire_type (pbf_wire_type type) const noexcept
void | skip ()
bool | get_bool ()
int32_t | get_enum ()
int32_t | get_int32 ()
int32_t | get_sint32 ()
uint32_t | get_uint32 ()
int64_t | get_int64 ()
int64_t | get_sint64 ()
uint64_t | get_uint64 ()
uint32_t | get_fixed32 ()
int32_t | get_sfixed32 ()
uint64_t | get_fixed64 ()
int64_t | get_sfixed64 ()
float | get_float ()
double | get_double ()
std::pair< const char *, pbf_length_type > | get_data ()
std::string | get_bytes ()
std::string | get_string ()
pbf_reader | get_message ()
std::pair< pbf_reader::const_bool_iterator, pbf_reader::const_bool_iterator > | get_packed_bool ()
std::pair< pbf_reader::const_enum_iterator, pbf_reader::const_enum_iterator > | get_packed_enum ()
std::pair< pbf_reader::const_int32_iterator, pbf_reader::const_int32_iterator > | get_packed_int32 ()
std::pair< pbf_reader::const_sint32_iterator, pbf_reader::const_sint32_iterator > | get_packed_sint32 ()
std::pair< pbf_reader::const_uint32_iterator, pbf_reader::const_uint32_iterator > | get_packed_uint32 ()
std::pair< pbf_reader::const_int64_iterator, pbf_reader::const_int64_iterator > | get_packed_int64 ()
std::pair< pbf_reader::const_sint64_iterator, pbf_reader::const_sint64_iterator > | get_packed_sint64 ()
std::pair< pbf_reader::const_uint64_iterator, pbf_reader::const_uint64_iterator > | get_packed_uint64 ()
auto | get_packed_fixed32 () -> decltype(packed_fixed< uint32_t >())
auto | get_packed_sfixed32 () -> decltype(packed_fixed< int32_t >())
auto | get_packed_fixed64 () -> decltype(packed_fixed< uint64_t >())
auto | get_packed_sfixed64 () -> decltype(packed_fixed< int64_t >())
auto | get_packed_float () -> decltype(packed_fixed< float >())
auto | get_packed_double () -> decltype(packed_fixed< double >())

## Detailed Description

### template<typename T>
class protozero::pbf_message< T >

This class represents a protobuf message. Either a top-level message or a nested sub-message. Top-level messages can be created from any buffer with a pointer and length:

enum class Message : protozero::pbf_tag_type {
...
};
std::string buffer;
// fill buffer...
pbf_message<Message> message(buffer.data(), buffer.size());

Sub-messages are created using get_message():

enum class SubMessage : protozero::pbf_tag_type {
...
};
pbf_message<Message> message(...);
message.next();
pbf_message<SubMessage> submessage = message.get_message();

All methods of the pbf_message class except get_bytes() and get_string() provide the strong exception guarantee, ie they either succeed or do not change the pbf_message object they are called on. Use the get_data() method instead of get_bytes() or get_string(), if you need this guarantee.

This template class is based on the pbf_reader class and has all the same methods. The difference is that whereever the pbf_reader class takes an integer tag, this template class takes a tag of the template type T.

Read the tutorial to understand how this class is used.

The documentation for this class was generated from the following file:

- include/protozero/pbf_message.hpp