protozero: protozero Namespace Reference

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

Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
protozero Namespace Reference

All parts of the protozero header-only library are in this namespace. More...

## Classes
class | basic_pbf_builder
class | basic_pbf_writer
class | const_fixed_iterator
class | const_svarint_iterator
class | const_varint_iterator
class | data_view
struct | end_of_buffer_exception
struct | exception
class | fixed_size_buffer_adaptor
struct | invalid_length_exception
struct | invalid_tag_exception
class | iterator_range
class | pbf_message
class | pbf_reader
struct | unknown_pbf_wire_type_exception
struct | varint_too_long_exception

## Typedefs
template<typename T>
using | pbf_builder = basic_pbf_builder<std::string, T>
| Specialization of basic_pbf_builder using std::string as buffer type.
using | pbf_writer = basic_pbf_writer<std::string>
using | packed_field_bool = detail::packed_field_varint<std::string, bool>
| Class for generating packed repeated bool fields.
using | packed_field_enum = detail::packed_field_varint<std::string, int32_t>
| Class for generating packed repeated enum fields.
using | packed_field_int32 = detail::packed_field_varint<std::string, int32_t>
| Class for generating packed repeated int32 fields.
using | packed_field_sint32 = detail::packed_field_svarint<std::string, int32_t>
| Class for generating packed repeated sint32 fields.
using | packed_field_uint32 = detail::packed_field_varint<std::string, uint32_t>
| Class for generating packed repeated uint32 fields.
using | packed_field_int64 = detail::packed_field_varint<std::string, int64_t>
| Class for generating packed repeated int64 fields.
using | packed_field_sint64 = detail::packed_field_svarint<std::string, int64_t>
| Class for generating packed repeated sint64 fields.
using | packed_field_uint64 = detail::packed_field_varint<std::string, uint64_t>
| Class for generating packed repeated uint64 fields.
using | packed_field_fixed32 = detail::packed_field_fixed<std::string, uint32_t>
| Class for generating packed repeated fixed32 fields.
using | packed_field_sfixed32 = detail::packed_field_fixed<std::string, int32_t>
| Class for generating packed repeated sfixed32 fields.
using | packed_field_fixed64 = detail::packed_field_fixed<std::string, uint64_t>
| Class for generating packed repeated fixed64 fields.
using | packed_field_sfixed64 = detail::packed_field_fixed<std::string, int64_t>
| Class for generating packed repeated sfixed64 fields.
using | packed_field_float = detail::packed_field_fixed<std::string, float>
| Class for generating packed repeated float fields.
using | packed_field_double = detail::packed_field_fixed<std::string, double>
| Class for generating packed repeated double fields.
using | pbf_tag_type = uint32_t
using | pbf_length_type = uint32_t

## Enumerations
enum class | pbf_wire_type : uint32_t { varint = 0 , fixed64 = 1 , length_delimited = 2 , fixed32 = 5 , unknown = 99 }

## Functions
template<typename TBuffer>
void | swap (basic_pbf_writer< TBuffer > &lhs, basic_pbf_writer< TBuffer > &rhs) noexcept
void | byteswap_inplace (uint32_t *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | byteswap_inplace (uint64_t *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | byteswap_inplace (int32_t *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | byteswap_inplace (int64_t *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | byteswap_inplace (float *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | byteswap_inplace (double *ptr) noexcept
| byteswap the data pointed to by ptr in-place.
void | swap (data_view &lhs, data_view &rhs) noexcept
constexpr bool | operator== (const data_view lhs, const data_view rhs) noexcept
constexpr bool | operator!= (const data_view lhs, const data_view rhs) noexcept
bool | operator< (const data_view lhs, const data_view rhs) noexcept
bool | operator<= (const data_view lhs, const data_view rhs) noexcept
bool | operator> (const data_view lhs, const data_view rhs) noexcept
bool | operator>= (const data_view lhs, const data_view rhs) noexcept
template<typename T>
void | swap (iterator_range< T > &lhs, iterator_range< T > &rhs) noexcept
void | swap (pbf_reader &lhs, pbf_reader &rhs) noexcept
template<typename T>
constexpr uint32_t | tag_and_type (T tag, pbf_wire_type wire_type) noexcept
uint64_t | decode_varint (const char **data, const char *end)
void | skip_varint (const char **data, const char *end)
template<typename T>
int | write_varint (T data, uint64_t value)
template<typename TBuffer>
void | add_varint_to_buffer (TBuffer *buffer, uint64_t value)
int | add_varint_to_buffer (char *data, uint64_t value) noexcept
int | length_of_varint (uint64_t value) noexcept
constexpr uint32_t | encode_zigzag32 (int32_t value) noexcept
constexpr uint64_t | encode_zigzag64 (int64_t value) noexcept
constexpr int32_t | decode_zigzag32 (uint32_t value) noexcept
constexpr int64_t | decode_zigzag64 (uint64_t value) noexcept

## Variables
constexpr const int8_t | max_varint_length = (sizeof(uint64_t) * 8 / 7) + 1

## Detailed Description

All parts of the protozero header-only library are in this namespace.

## Typedef Documentation

## ◆ pbf_length_type

using protozero::pbf_length_type = uint32_t

The type used for length values, such as the length of a field.

## ◆ pbf_tag_type

using protozero::pbf_tag_type = uint32_t

The type used for field tags (field numbers).

## ◆ pbf_writer

using protozero::pbf_writer = basic_pbf_writer<std::string>

Specialization of basic_pbf_writer using std::string as buffer type.

## Enumeration Type Documentation

## ◆ pbf_wire_type

enum class protozero::pbf_wire_type : uint32_t
| strong

The type used to encode type information. See the table on https://developers.google.com/protocol-buffers/docs/encoding

## Function Documentation

## ◆ add_varint_to_buffer() [1/2]

int protozero::add_varint_to_buffer | ( | char * | data,
|  | uint64_t | value )
| inlinenoexcept

Varint encode a 64 bit integer.

Parameters

  data | Where to add the varint. There must be enough space available!
  value | The integer that will be encoded.

Returns
  the number of bytes written

## ◆ add_varint_to_buffer() [2/2]

template<typename TBuffer>

void protozero::add_varint_to_buffer | ( | TBuffer * | buffer,
|  | uint64_t | value )
| inline

Varint encode a 64 bit integer.

Template Parameters

  TBuffer | A buffer type.

Parameters

  buffer | Output buffer the varint will be written to.
  value | The integer that will be encoded.

Exceptions

  Any | exception thrown by calling the buffer_push_back() function.

## ◆ decode_varint()

uint64_t protozero::decode_varint | ( | const char ** | data,
|  | const char * | end )
| inline

Decode a 64 bit varint.

Strong exception guarantee: if there is an exception the data pointer will not be changed.

Parameters

  [in,out] | data | Pointer to pointer to the input data. After the function returns this will point to the next data to be read.
  [in] | end | Pointer one past the end of the input data.

Returns
  The decoded integer

Exceptions

  varint_too_long_exception | if the varint is longer then the maximum length that would fit in a 64 bit int. Usually this means your data is corrupted or you are trying to read something as a varint that isn't.
  end_of_buffer_exception | if the end of the buffer was reached before the end of the varint.

## ◆ decode_zigzag32()

int32_t protozero::decode_zigzag32 | ( | uint32_t | value | ) |
| constexprnoexcept

Decodes a 32 bit ZigZag-encoded integer.

## ◆ decode_zigzag64()

int64_t protozero::decode_zigzag64 | ( | uint64_t | value | ) |
| constexprnoexcept

Decodes a 64 bit ZigZag-encoded integer.

## ◆ encode_zigzag32()

uint32_t protozero::encode_zigzag32 | ( | int32_t | value | ) |
| constexprnoexcept

ZigZag encodes a 32 bit integer.

## ◆ encode_zigzag64()

uint64_t protozero::encode_zigzag64 | ( | int64_t | value | ) |
| constexprnoexcept

ZigZag encodes a 64 bit integer.

## ◆ length_of_varint()

int protozero::length_of_varint | ( | uint64_t | value | ) |
| inlinenoexcept

Get the length of the varint the specified value would produce.

Parameters

  value | The integer to be encoded.

Returns
  the number of bytes the varint would have if we created it.

## ◆ operator!=()

bool protozero::operator!= | ( | const data_view | lhs,
|  | const data_view | rhs )
| constexprnoexcept

Two data_view instances are not equal if they have different sizes or the content differs.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ operator<()

bool protozero::operator< | ( | const data_view | lhs,
|  | const data_view | rhs )
| inlinenoexcept

Returns true if lhs.compare(rhs) < 0.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ operator<=()

bool protozero::operator<= | ( | const data_view | lhs,
|  | const data_view | rhs )
| inlinenoexcept

Returns true if lhs.compare(rhs) <= 0.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ operator==()

bool protozero::operator== | ( | const data_view | lhs,
|  | const data_view | rhs )
| constexprnoexcept

Two data_view instances are equal if they have the same size and the same content.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ operator>()

bool protozero::operator> | ( | const data_view | lhs,
|  | const data_view | rhs )
| inlinenoexcept

Returns true if lhs.compare(rhs) > 0.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ operator>=()

bool protozero::operator>= | ( | const data_view | lhs,
|  | const data_view | rhs )
| inlinenoexcept

Returns true if lhs.compare(rhs) >= 0.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ skip_varint()

void protozero::skip_varint | ( | const char ** | data,
|  | const char * | end )
| inline

Skip over a varint.

Strong exception guarantee: if there is an exception the data pointer will not be changed.

Parameters

  [in,out] | data | Pointer to pointer to the input data. After the function returns this will point to the next data to be read.
  [in] | end | Pointer one past the end of the input data.

Exceptions

  end_of_buffer_exception | if the end of the buffer was reached before the end of the varint.

## ◆ swap() [1/4]

template<typename TBuffer>

void protozero::swap | ( | basic_pbf_writer< TBuffer > & | lhs,
|  | basic_pbf_writer< TBuffer > & | rhs )
| inlinenoexcept

Swap two basic_pbf_writer objects.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ swap() [2/4]

void protozero::swap | ( | data_view & | lhs,
|  | data_view & | rhs )
| inlinenoexcept

Swap two data_view objects.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ swap() [3/4]

template<typename T>

void protozero::swap | ( | iterator_range< T > & | lhs,
|  | iterator_range< T > & | rhs )
| inlinenoexcept

Swap two iterator_ranges.

Parameters

  lhs | First range.
  rhs | Second range.

## ◆ swap() [4/4]

void protozero::swap | ( | pbf_reader & | lhs,
|  | pbf_reader & | rhs )
| inlinenoexcept

Swap two pbf_reader objects.

Parameters

  lhs | First object.
  rhs | Second object.

## ◆ tag_and_type()

template<typename T>

uint32_t protozero::tag_and_type | ( | T | tag,
|  | pbf_wire_type | wire_type )
| constexprnoexcept

Get the tag and wire type of the current field in one integer suitable for comparison with a switch statement.

See pbf_reader.tag_and_type() for an example how to use this.

## ◆ write_varint()

template<typename T>

int protozero::write_varint | ( | T | data,
|  | uint64_t | value )
| inline

Varint encode a 64 bit integer.

Template Parameters

  T | An output iterator type.

Parameters

  data | Output iterator the varint encoded value will be written to byte by byte.
  value | The integer that will be encoded.

Returns
  the number of bytes written

Exceptions

  Any | exception thrown by increment or dereference operator on data.

Deprecated
  Use add_varint_to_buffer() instead.

## Variable Documentation

## ◆ max_varint_length

const int8_t protozero::max_varint_length = (sizeof(uint64_t) * 8 / 7) + 1
| constexpr

The maximum length of a 64 bit varint.