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 utlities 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. 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. 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.
 

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 133 of file type_mapping.hpp.

◆ OneofAlternativeType

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

Definition at line 136 of file type_mapping.hpp.

Function Documentation

◆ 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 56 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 36 of file convert.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 89 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 69 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 129 of file type_mapping.hpp.