protozero
Minimalistic protocol buffer decoder and encoder in C++.
Classes | Typedefs | Enumerations | Functions | Variables
protozero Namespace Reference

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

Classes

class  const_fixed_iterator
 
class  const_svarint_iterator
 
class  const_varint_iterator
 
class  data_view
 
struct  end_of_buffer_exception
 
struct  exception
 
class  iterator_range
 
class  pbf_builder
 
class  pbf_message
 
class  pbf_reader
 
class  pbf_writer
 
struct  unknown_pbf_wire_type_exception
 
struct  varint_too_long_exception
 

Typedefs

using packed_field_bool = detail::packed_field_varint< bool >
 Class for generating packed repeated bool fields.
 
using packed_field_enum = detail::packed_field_varint< int32_t >
 Class for generating packed repeated enum fields.
 
using packed_field_int32 = detail::packed_field_varint< int32_t >
 Class for generating packed repeated int32 fields.
 
using packed_field_sint32 = detail::packed_field_svarint< int32_t >
 Class for generating packed repeated sint32 fields.
 
using packed_field_uint32 = detail::packed_field_varint< uint32_t >
 Class for generating packed repeated uint32 fields.
 
using packed_field_int64 = detail::packed_field_varint< int64_t >
 Class for generating packed repeated int64 fields.
 
using packed_field_sint64 = detail::packed_field_svarint< int64_t >
 Class for generating packed repeated sint64 fields.
 
using packed_field_uint64 = detail::packed_field_varint< uint64_t >
 Class for generating packed repeated uint64 fields.
 
using packed_field_fixed32 = detail::packed_field_fixed< uint32_t >
 Class for generating packed repeated fixed32 fields.
 
using packed_field_sfixed32 = detail::packed_field_fixed< int32_t >
 Class for generating packed repeated sfixed32 fields.
 
using packed_field_fixed64 = detail::packed_field_fixed< uint64_t >
 Class for generating packed repeated fixed64 fields.
 
using packed_field_sfixed64 = detail::packed_field_fixed< int64_t >
 Class for generating packed repeated sfixed64 fields.
 
using packed_field_float = detail::packed_field_fixed< float >
 Class for generating packed repeated float fields.
 
using packed_field_double = detail::packed_field_fixed< double >
 Class for generating packed repeated double fields.
 
using pbf_tag_type = uint32_t
 
using pbf_length_type = uint32_t
 

Enumerations

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

Functions

template<int N>
void byteswap (const char *, char *) noexcept
 
template<>
void byteswap< 4 > (const char *data, char *result) noexcept
 
template<>
void byteswap< 8 > (const char *data, char *result) noexcept
 
template<typename T >
void swap (iterator_range< T > &lhs, iterator_range< T > &rhs) noexcept
 
template<typename T >
iterator_range< const_fixed_iterator< T > > create_fixed_iterator_range (const char *first, const char *last)
 
void swap (pbf_reader &lhs, pbf_reader &rhs) noexcept
 
void swap (pbf_writer &lhs, pbf_writer &rhs) noexcept
 
void swap (data_view &lhs, data_view &rhs) noexcept
 
bool operator== (data_view &lhs, data_view &rhs) noexcept
 
bool operator!= (data_view &lhs, data_view &rhs) 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)
 
uint32_t encode_zigzag32 (int32_t value) noexcept
 
uint64_t encode_zigzag64 (int64_t value) noexcept
 
int32_t decode_zigzag32 (uint32_t value) noexcept
 
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 = typedef uint32_t

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

§ pbf_tag_type

using protozero::pbf_tag_type = typedef uint32_t

The type used for field tags (field numbers).

Enumeration Type Documentation

§ pbf_wire_type

enum 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

§ byteswap()

template<int N>
void protozero::byteswap ( const char *  ,
char *   
)
inlinenoexcept

Swap N byte value between endianness formats. This template function must be specialized to actually work.

§ byteswap< 4 >()

template<>
void protozero::byteswap< 4 > ( const char *  data,
char *  result 
)
inlinenoexcept

Swap 4 byte value (int32_t, uint32_t, float) between endianness formats.

§ byteswap< 8 >()

template<>
void protozero::byteswap< 8 > ( const char *  data,
char *  result 
)
inlinenoexcept

Swap 8 byte value (int64_t, uint64_t, double) between endianness formats.

§ create_fixed_iterator_range()

template<typename T >
iterator_range<const_fixed_iterator<T> > protozero::create_fixed_iterator_range ( const char *  first,
const char *  last 
)
inline

Create iterator_range from char pointers to beginning and end of range.

Parameters
firstBeginning of range.
lastEnd of range.

§ 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]dataPointer to pointer to the input data. After the function returns this will point to the next data to be read.
[in]endPointer one past the end of the input data.
Returns
The decoded integer
Exceptions
varint_too_long_exceptionif 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_exceptionif the end of the buffer was reached before the end of the varint.

§ decode_zigzag32()

int32_t protozero::decode_zigzag32 ( uint32_t  value)
inlinenoexcept

Decodes a 32 bit ZigZag-encoded integer.

§ decode_zigzag64()

int64_t protozero::decode_zigzag64 ( uint64_t  value)
inlinenoexcept

Decodes a 64 bit ZigZag-encoded integer.

§ encode_zigzag32()

uint32_t protozero::encode_zigzag32 ( int32_t  value)
inlinenoexcept

ZigZag encodes a 32 bit integer.

§ encode_zigzag64()

uint64_t protozero::encode_zigzag64 ( int64_t  value)
inlinenoexcept

ZigZag encodes a 64 bit integer.

§ operator!=()

bool protozero::operator!= ( data_view lhs,
data_view rhs 
)
inlinenoexcept

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

Parameters
lhsFirst object.
rhsSecond object.

§ operator==()

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

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

Parameters
lhsFirst object.
rhsSecond 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]dataPointer to pointer to the input data. After the function returns this will point to the next data to be read.
[in]endPointer one past the end of the input data.
Exceptions
end_of_buffer_exceptionif the end of the buffer was reached before the end of the varint.

§ swap() [1/4]

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

Swap two iterator_ranges.

Parameters
lhsFirst range.
rhsSecond range.

§ swap() [2/4]

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

Swap two data_view objects.

Parameters
lhsFirst object.
rhsSecond object.

§ swap() [3/4]

void protozero::swap ( pbf_writer lhs,
pbf_writer rhs 
)
inlinenoexcept

Swap two pbf_writer objects.

Parameters
lhsFirst object.
rhsSecond object.

§ swap() [4/4]

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

Swap two pbf_reader objects.

Parameters
lhsFirst object.
rhsSecond object.

§ write_varint()

template<typename T >
int protozero::write_varint ( data,
uint64_t  value 
)
inline

Varint encode a 64 bit integer.

Template Parameters
TAn output iterator type.
Parameters
dataOutput iterator the varint encoded value will be written to byte by byte.
valueThe integer that will be encoded.
Exceptions
Anyexception thrown by increment or dereference operator on data.

Variable Documentation

§ max_varint_length

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

The maximum length of a 64 bit varint.