protozero: protozero::basic_pbf_builder< TBuffer, T > Class Template Reference

protozero 1.8.2 Minimalistic protocol buffer decoder and encoder in C++.

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
protozero::basic_pbf_builder< TBuffer, T > Class Template Reference

`#include <basic_pbf_builder.hpp>`

Inheritance diagram for protozero::basic_pbf_builder< TBuffer, T >:
[legend]
Collaboration diagram for protozero::basic_pbf_builder< TBuffer, T >:
[legend]

## Public Types
using | enum_type = T
| The type of messages this class will build.

## Public Member Functions
| basic_pbf_builder (TBuffer &data) noexcept
template<typename P>
| basic_pbf_builder (basic_pbf_writer< TBuffer > &parent_writer, P tag)
void | add_bytes (T tag, const char *value, std::size_t size)
void | add_bytes (T tag, const data_view &value)
void | add_bytes (T tag, const std::string &value)
void | add_bytes (T tag, const char *value)
template<typename... Ts>
void | add_bytes_vectored (T tag, Ts &&... values)
void | add_string (T tag, const char *value, std::size_t size)
void | add_string (T tag, const data_view &value)
void | add_string (T tag, const std::string &value)
void | add_string (T tag, const char *value)
void | add_message (T tag, const char *value, std::size_t size)
void | add_message (T tag, const data_view &value)
void | add_message (T tag, const std::string &value)
Public Member Functions inherited from protozero::basic_pbf_writer< TBuffer >
| basic_pbf_writer (TBuffer &buffer) noexcept
| basic_pbf_writer () noexcept=default
| basic_pbf_writer (basic_pbf_writer &parent_writer, pbf_tag_type tag, std::size_t size=0)
| basic_pbf_writer (const basic_pbf_writer &)=delete
| A basic_pbf_writer object can not be copied.
basic_pbf_writer & | operator= (const basic_pbf_writer &)=delete
| A basic_pbf_writer object can not be copied.
| basic_pbf_writer (basic_pbf_writer &&other) noexcept
basic_pbf_writer & | operator= (basic_pbf_writer &&other) noexcept
bool | valid () const noexcept
void | swap (basic_pbf_writer &other) noexcept
void | reserve (std::size_t size)
void | commit ()
void | rollback ()
void | add_bool (pbf_tag_type tag, bool value)
void | add_enum (pbf_tag_type tag, int32_t value)
void | add_int32 (pbf_tag_type tag, int32_t value)
void | add_sint32 (pbf_tag_type tag, int32_t value)
void | add_uint32 (pbf_tag_type tag, uint32_t value)
void | add_int64 (pbf_tag_type tag, int64_t value)
void | add_sint64 (pbf_tag_type tag, int64_t value)
void | add_uint64 (pbf_tag_type tag, uint64_t value)
void | add_fixed32 (pbf_tag_type tag, uint32_t value)
void | add_sfixed32 (pbf_tag_type tag, int32_t value)
void | add_fixed64 (pbf_tag_type tag, uint64_t value)
void | add_sfixed64 (pbf_tag_type tag, int64_t value)
void | add_float (pbf_tag_type tag, float value)
void | add_double (pbf_tag_type tag, double value)
void | add_bytes (pbf_tag_type tag, const char *value, std::size_t size)
void | add_bytes (pbf_tag_type tag, const data_view &value)
void | add_bytes (pbf_tag_type tag, const std::string &value)
void | add_bytes (pbf_tag_type tag, const char *value)
template<typename... Ts>
void | add_bytes_vectored (pbf_tag_type tag, Ts &&... values)
void | add_string (pbf_tag_type tag, const char *value, std::size_t size)
void | add_string (pbf_tag_type tag, const data_view &value)
void | add_string (pbf_tag_type tag, const std::string &value)
void | add_string (pbf_tag_type tag, const char *value)
void | add_message (pbf_tag_type tag, const char *value, std::size_t size)
void | add_message (pbf_tag_type tag, const data_view &value)
void | add_message (pbf_tag_type tag, const std::string &value)
template<typename InputIterator>
void | add_packed_bool (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_enum (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_int32 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_sint32 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_uint32 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_int64 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_sint64 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_uint64 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename ValueType, typename InputIterator>
void | add_packed_fixed (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_fixed32 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_sfixed32 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_fixed64 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_sfixed64 (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_float (pbf_tag_type tag, InputIterator first, InputIterator last)
template<typename InputIterator>
void | add_packed_double (pbf_tag_type tag, InputIterator first, InputIterator last)

## Detailed Description

template<typename TBuffer, typename T>
class protozero::basic_pbf_builder< TBuffer, T >

The basic_pbf_builder is used to write PBF formatted messages into a buffer. It is based on the basic_pbf_writer class and has all the same methods. The difference is that while the pbf_writer class takes an integer tag, this template class takes a tag of the template type T. The idea is that T will be an enumeration value and this helps reduce the possibility of programming errors.

Almost all methods in this class can throw an std::bad_alloc exception if the underlying buffer class wants to resize.

Read the tutorial to understand how this class is used. In most cases you want to use the pbf_builder class which uses a std::string as buffer type.

## Constructor & Destructor Documentation

## ◆ basic_pbf_builder() [1/2]

template<typename TBuffer, typename T>

protozero::basic_pbf_builder< TBuffer, T >::basic_pbf_builder | ( | TBuffer & | data | ) |
| inlineexplicitnoexcept

Create a builder using the given string as a data store. The object stores a reference to that string and adds all data to it. The string doesn't have to be empty. The pbf_message object will just append data.

## ◆ basic_pbf_builder() [2/2]

template<typename TBuffer, typename T>
template<typename P>

protozero::basic_pbf_builder< TBuffer, T >::basic_pbf_builder | ( | basic_pbf_writer< TBuffer > & | parent_writer,
|  | P | tag )
| inline

Construct a pbf_builder for a submessage from the pbf_message or pbf_writer of the parent message.

Parameters

  parent_writer | The parent pbf_message or pbf_writer
  tag | Tag of the field that will be written

## Member Function Documentation

## ◆ add_bytes() [1/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_bytes | ( | T | tag,
|  | const char * | value )
| inline

Add "bytes" field to data. Bytes from the value are written until a null byte is encountered. The null byte is not added.

Parameters

  tag | Tag of the field
  value | Pointer to zero-delimited value to be written

## ◆ add_bytes() [2/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_bytes | ( | T | tag,
|  | const char * | value,
|  | std::size_t | size )
| inline

Add "bytes" field to data.

Parameters

  tag | Tag of the field
  value | Pointer to value to be written
  size | Number of bytes to be written

## ◆ add_bytes() [3/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_bytes | ( | T | tag,
|  | const data_view & | value )
| inline

Add "bytes" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written

## ◆ add_bytes() [4/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_bytes | ( | T | tag,
|  | const std::string & | value )
| inline

Add "bytes" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written

## ◆ add_bytes_vectored()

template<typename TBuffer, typename T>
template<typename... Ts>

void protozero::basic_pbf_builder< TBuffer, T >::add_bytes_vectored | ( | T | tag,
|  | Ts &&... | values )
| inline

Add "bytes" field to data using vectored input. All the data in the 2nd and further arguments is "concatenated" with only a single copy into the final buffer.

This will work with objects of any type supporting the data() and size() methods like std::string or protozero::data_view.

Example:

std::string data1 = "abc";
std::string data2 = "xyz";
builder.add_bytes_vectored(1, data1, data2);

Template Parameters

  Ts | List of types supporting data() and size() methods.

Parameters

  tag | Tag of the field
  values | List of objects of types Ts with data to be appended.

## ◆ add_message() [1/3]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_message | ( | T | tag,
|  | const char * | value,
|  | std::size_t | size )
| inline

Add "message" field to data.

Parameters

  tag | Tag of the field
  value | Pointer to message to be written
  size | Length of the message

## ◆ add_message() [2/3]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_message | ( | T | tag,
|  | const data_view & | value )
| inline

Add "message" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written. The value must be a complete message.

## ◆ add_message() [3/3]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_message | ( | T | tag,
|  | const std::string & | value )
| inline

Add "message" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written. The value must be a complete message.

## ◆ add_string() [1/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_string | ( | T | tag,
|  | const char * | value )
| inline

Add "string" field to data. Bytes from the value are written until a null byte is encountered. The null byte is not added.

Parameters

  tag | Tag of the field
  value | Pointer to value to be written

## ◆ add_string() [2/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_string | ( | T | tag,
|  | const char * | value,
|  | std::size_t | size )
| inline

Add "string" field to data.

Parameters

  tag | Tag of the field
  value | Pointer to value to be written
  size | Number of bytes to be written

## ◆ add_string() [3/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_string | ( | T | tag,
|  | const data_view & | value )
| inline

Add "string" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written

## ◆ add_string() [4/4]

template<typename TBuffer, typename T>

void protozero::basic_pbf_builder< TBuffer, T >::add_string | ( | T | tag,
|  | const std::string & | value )
| inline

Add "string" field to data.

Parameters

  tag | Tag of the field
  value | Value to be written

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

- include/protozero/basic_pbf_builder.hpp