userver: proto_structs Namespace Reference
Loading...
Searching...
No Matches
proto_structs Namespace Reference

Detailed Description

Top namespace for the proto-structs library.

Namespaces

namespace  io
 Namespace for conversion utilities and predefined proto-structs conversion hooks for well-known std/userver types.
 
namespace  traits
 Namespace contains types for obtaining meta information (traits, concepts, etc.).
 

Classes

class  Any
 Wrapper for google.protobuf.Any which provides interface to access stored message as compatible struct. More...
 
class  AnyPackError
 Error packing protobuf message to proto_structs::Any underlying storage. More...
 
class  AnyUnpackError
 Error unpacking protobuf message from proto_structs::Any underlying storage. More...
 
class  ConversionError
 Conversion error base class. More...
 
class  Date
 Type to represent google.type.Date in proto structs. More...
 
class  Duration
 Type to represent google.protobuf.Duration in proto structs. More...
 
class  Error
 Library basic exception type. All other proto-structs exceptions are derived from this type. More...
 
class  Oneof
 Wrapper for oneof protobuf message fields. More...
 
class  OneofAccessError
 Invalid attempt to access unset proto_structs::Oneof field. More...
 
class  ReadError
 Error reading proto struct from protobuf message or binary data. More...
 
class  TimeOfDay
 Type to represent google.type.TimeOfDay in proto structs. More...
 
class  Timestamp
 Type to represent google.protobuf.Timestamp in proto structs. More...
 
struct  UnbreakableDependencyCycle
 A type that is generated for a field that participates in an unbreakable dependency cycle. More...
 
class  ValueError
 Incorrect value error. More...
 
class  WriteError
 Error writing proto struct to protobuf message or binary data. More...
 

Typedefs

template<typename Key, typename Value>
using HashMap
 The hash map container used in userver proto structs by default.
 
template<std::size_t Index, traits::Oneof TOneof>
using OneofAlternativeTrait = impl::OneofAlternativeTrait<Index, typename TOneof::Base>
 Provides information about proto_structs::Oneof field type at position Index.
 
template<std::size_t Index, typename TOneof>
using OneofAlternativeType = OneofAlternativeTrait<Index, TOneof>::Type
 

Functions

template<traits::ProtoMessage TMessage, traits::ProtoStruct TStruct>
void MessageToStruct (const TMessage &msg, TStruct &obj)
 Converts protobuf message msg to proto struct obj.
 
template<traits::ProtoStruct TStruct, traits::ProtoMessage TMessage>
TStruct MessageToStruct (const TMessage &msg)
 Converts protobuf message msg to specified proto struct type.
 
template<typename TStruct, traits::ProtoMessage TMessage>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void StructToMessage (TStruct &&obj, TMessage &msg)
 Converts proto struct obj to protobuf message msg.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
traits::CompatibleMessageType< std::remove_cvref_t< TStruct > > StructToMessage (TStruct &&obj)
 Converts proto struct obj to it's compatible protobuf message type.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void BinaryToStruct (std::string_view binary_data, TStruct &obj)
 Converts binary data binary_data to proto struct obj.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct BinaryToStruct (std::string_view binary_data)
 Converts binary data binary_data to specified proto struct type.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
std::string StructToBinary (TStruct &&obj)
 Converts proto struct obj to it's compatible binary data.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
formats::json::Value StructToJson (TStruct &&obj, const protobuf::json::PrintOptions &options)
 Converts protobuf struct obj to formats::json::Value. Conversion is performed by converting the protobuf struct to an intermediate protobuf message and then converting the message to formats::json::Value.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
std::string StructToJsonString (TStruct &&obj, const protobuf::json::PrintOptions &options)
 Converts protobuf struct obj to an std::string, containing the JSON representation of the struct. Conversion is performed by converting the protobuf struct to an intermediate protobuf message, then converting the message to formats::json::Value, and finally converting the value to a string.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct JsonToStruct (const formats::json::Value &json, const protobuf::json::ParseOptions &options)
 Converts json to protobuf struct of type TStruct. Conversion is performed by converting the formats::json::Value to an intermediate protobuf message and then converting the message to a protobuf struct.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct JsonStringToStruct (std::string_view json_string, const protobuf::json::ParseOptions &options)
 Converts json_string to protobuf struct of type TStruct. Conversion is performed by first converting the string to formats::json::Value, then converting the value to an intermediate protobuf message, and finally converting the message to a protobuf struct.
 

Variables

constexpr std::size_t kOneofNpos = -1
 Special index value used to indicate oneof without any field set.
 

Typedef Documentation

◆ HashMap

template<typename Key, typename Value>
using proto_structs::HashMap
Initial value:
std::unordered_map<
Key,
Value,
std::conditional_t<std::is_convertible_v<Key, std::string_view>, utils::StrCaseHash, std::hash<Key>>>

The hash map container used in userver proto structs by default.

Currently implemented as just std::unordered_map. Please don't assume it! For example:

  • Don't pass the field to functions as std::unordered_map, use proto_structs::HashMap instead;
  • Don't use node and bucket APIs of std::unordered_map with these fields.

Definition at line 23 of file hash_map.hpp.

◆ OneofAlternativeTrait

template<std::size_t Index, traits::Oneof TOneof>
using proto_structs::OneofAlternativeTrait = impl::OneofAlternativeTrait<Index, typename TOneof::Base>

Provides information about proto_structs::Oneof field type at position Index.

Definition at line 134 of file type_mapping.hpp.

◆ OneofAlternativeType

template<std::size_t Index, typename TOneof>
using proto_structs::OneofAlternativeType = OneofAlternativeTrait<Index, TOneof>::Type

Definition at line 137 of file type_mapping.hpp.

Function Documentation

◆ BinaryToStruct() [1/2]

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct proto_structs::BinaryToStruct ( std::string_view binary_data)
nodiscard

Converts binary data binary_data to specified proto struct type.

Template Parameters
TStructproto struct type
Exceptions
ReadErrorif conversion has failed.

Definition at line 117 of file convert.hpp.

◆ BinaryToStruct() [2/2]

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void proto_structs::BinaryToStruct ( std::string_view binary_data,
TStruct & obj )

Converts binary data binary_data to proto struct obj.

Template Parameters
TStructproto struct type
Exceptions
ReadErrorif conversion has failed.

Definition at line 103 of file convert.hpp.

◆ JsonStringToStruct()

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct proto_structs::JsonStringToStruct ( std::string_view json_string,
const protobuf::json::ParseOptions & options )
nodiscard

Converts json_string to protobuf struct of type TStruct. Conversion is performed by first converting the string to formats::json::Value, then converting the value to an intermediate protobuf message, and finally converting the message to a protobuf struct.

Template Parameters
TStructprotobuf struct type
Exceptions
ParseErrorif JSON to message conversion has failed.
MemberMissingExceptionis json holds nothing.
ReadErrorif message to struct conversion has failed. The conversion is perfomed according to ProtoJSON specification.
Warning
Most of the legacy ProtoJSON behavior introduced for compatability with non-conformant implementations is not supported. This behavior may be disabled in the future versions of the protobuf library thus should not be relied upon.
The proto2 syntax is not fully supported and tested (at least extension fields are not supported).

Definition at line 74 of file json.hpp.

◆ JsonToStruct()

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TStruct proto_structs::JsonToStruct ( const formats::json::Value & json,
const protobuf::json::ParseOptions & options )
nodiscard

Converts json to protobuf struct of type TStruct. Conversion is performed by converting the formats::json::Value to an intermediate protobuf message and then converting the message to a protobuf struct.

Template Parameters
TStructprotobuf struct type
Exceptions
ParseErrorif JSON to message conversion has failed.
MemberMissingExceptionis json holds nothing.
ReadErrorif message to struct conversion has failed. The conversion is perfomed according to ProtoJSON specification.
Warning
Most of the legacy ProtoJSON behavior introduced for compatability with non-conformant implementations is not supported. This behavior may be disabled in the future versions of the protobuf library thus should not be relied upon.
The proto2 syntax is not fully supported and tested (at least extension fields are not supported).

Definition at line 53 of file json.hpp.

◆ MessageToStruct() [1/2]

template<traits::ProtoStruct TStruct, traits::ProtoMessage TMessage>
TStruct proto_structs::MessageToStruct ( const TMessage & msg)
nodiscard

Converts protobuf message msg to specified proto struct type.

Template Parameters
TStructproto struct type
TMessageprotobuf message type
Exceptions
ReadErrorif conversion has failed.

Definition at line 58 of file convert.hpp.

◆ MessageToStruct() [2/2]

template<traits::ProtoMessage TMessage, traits::ProtoStruct TStruct>
void proto_structs::MessageToStruct ( const TMessage & msg,
TStruct & obj )

Converts protobuf message msg to proto struct obj.

Template Parameters
TMessageprotobuf message type
TStructproto struct type
Exceptions
ReadErrorif conversion has failed.
Warning
If function throws an exception, obj is left in a valid but unspecified state.

Definition at line 38 of file convert.hpp.

◆ StructToBinary()

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
std::string proto_structs::StructToBinary ( TStruct && obj)
nodiscard

Converts proto struct obj to it's compatible binary data.

Template Parameters
TStructproto struct type
Exceptions
WriteErrorif conversion has failed.

Definition at line 128 of file convert.hpp.

◆ StructToJson()

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
formats::json::Value proto_structs::StructToJson ( TStruct && obj,
const protobuf::json::PrintOptions & options )
nodiscard

Converts protobuf struct obj to formats::json::Value. Conversion is performed by converting the protobuf struct to an intermediate protobuf message and then converting the message to formats::json::Value.

Template Parameters
TStructprotobuf struct type
Exceptions
WriteErrorif struct to message conversion has failed.
PrintErrorif message to JSON conversion has failed.

Definition at line 23 of file json.hpp.

◆ StructToJsonString()

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
std::string proto_structs::StructToJsonString ( TStruct && obj,
const protobuf::json::PrintOptions & options )
nodiscard

Converts protobuf struct obj to an std::string, containing the JSON representation of the struct. Conversion is performed by converting the protobuf struct to an intermediate protobuf message, then converting the message to formats::json::Value, and finally converting the value to a string.

Template Parameters
TStructprotobuf struct type
Exceptions
WriteErrorif struct to message conversion has failed.
PrintErrorif message to JSON conversion has failed.

Definition at line 35 of file json.hpp.

◆ StructToMessage() [1/2]

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
traits::CompatibleMessageType< std::remove_cvref_t< TStruct > > proto_structs::StructToMessage ( TStruct && obj)
nodiscard

Converts proto struct obj to it's compatible protobuf message type.

Template Parameters
TStructproto struct type
Exceptions
WriteErrorif conversion has failed.

Definition at line 91 of file convert.hpp.

◆ StructToMessage() [2/2]

template<typename TStruct, traits::ProtoMessage TMessage>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void proto_structs::StructToMessage ( TStruct && obj,
TMessage & msg )

Converts proto struct obj to protobuf message msg.

Template Parameters
TStructproto struct type
TMessageprotobuf message type
Exceptions
WriteErrorif conversion has failed.
Warning
If function throws an exception, msg is left in a valid but unspecified state.

Definition at line 71 of file convert.hpp.

Variable Documentation

◆ kOneofNpos

std::size_t proto_structs::kOneofNpos = -1
inlineconstexpr

Special index value used to indicate oneof without any field set.

Definition at line 130 of file type_mapping.hpp.