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

Detailed Description

Top namespace for the proto-structs library.

Namespaces

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
 Failed to pack struct's compatible message to proto_structs::Any underlying storage. More...
 
class  AnyUnpackError
 Failed to unpack struct's compatible message from proto_structs::Any underlying storage. More...
 
class  ConversionError
 Conversion error Exception is thrown if protobuf message field can't be converted to/from struct field. 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
 Trying to access unset proto_structs::Oneof field. More...
 
struct  To
 An ADL helper which allows locating functions to read structs from protobuf messages inside struct-specific namespaces. More...
 

Typedefs

template<std::size_t Index, typename T >
using OneofAlternativeTrait = impl::OneofAlternativeTrait< Index, std::remove_cv_t< T > >
 Provides information about proto_structs::Oneof field type at position Index
 
template<std::size_t Index, typename T >
using OneofAlternativeType = OneofAlternativeTrait< Index, T >::Type
 
template<typename Key , typename Value >
using HashMap = 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.
 

Functions

template<traits::ProtoMessage TMessage, traits::ProtoStruct TStruct>
void MessageToStruct (const TMessage &msg, TStruct &obj)
 Converts protobuf message msg to struct obj.
 
template<traits::ProtoStruct TStruct, traits::ProtoMessage TMessage>
TStruct MessageToStruct (const TMessage &msg)
 Converts protobuf message msg to specified structure type.
 
template<typename TStruct , traits::ProtoMessage TMessage>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void StructToMessage (TStruct &&obj, TMessage &msg)
 Converts struct instance obj to protobuf message msg.
 
template<traits::ProtoMessage TMessage, typename TStruct >
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
TMessage StructToMessage (TStruct &&obj)
 Converts struct instance obj to protobuf message msg of the specified type.
 
template<typename TStruct >
requires traits::CompatibleStruct<std::remove_cvref_t<TStruct>>
traits::CompatibleMessageType< std::remove_cvref_t< TStruct > > StructToMessage (TStruct &&obj)
 Converts struct instance obj to it's compatible protobuf message.
 

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 = typedef 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 22 of file hash_map.hpp.

◆ OneofAlternativeTrait

template<std::size_t Index, typename T >
using proto_structs::OneofAlternativeTrait = typedef impl::OneofAlternativeTrait<Index, std::remove_cv_t<T> >

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

Definition at line 58 of file oneof.hpp.

◆ OneofAlternativeType

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

Definition at line 61 of file oneof.hpp.

Function Documentation

◆ MessageToStruct() [1/2]

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

Converts protobuf message msg to specified structure type.

Template Parameters
TStructstruct type
TMessageprotobuf message type
Exceptions
ConversionErrorif conversion failed

Function calls ReadStruct(obj, msg) under the hood which should be foundable by argument-dependent lookup.

Definition at line 39 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 struct obj.

Template Parameters
TMessageprotobuf message type
TStructstruct type
Exceptions
ConversionErrorif conversion failed (in that case obj is not modified)
Note
If function throws an exception, obj is not modified

Function calls ReadStruct(obj, msg) under the hood which should be foundable by argument-dependent lookup.

Definition at line 26 of file convert.hpp.

◆ StructToMessage() [1/3]

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

Converts struct instance obj to protobuf message msg of the specified type.

Template Parameters
TStructstruct type
TMessageprotobuf message type
Exceptions
ConversionErrorif conversion failed

Function calls WriteStruct(std::forward<TStruct>(obj), msg) under the hood which should be foundable by argument-dependent lookup.

Definition at line 70 of file convert.hpp.

◆ StructToMessage() [2/3]

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

Converts struct instance obj to it's compatible protobuf message.

Template Parameters
TStructstruct type
Exceptions
ConversionErrorif conversion failed

Compatability information should be provided for TStruct with proto_structs::compatible_message, otherwise compilation will fail.

Function calls WriteStruct(std::forward<TStruct>(obj), msg) under the hood which should be foundable by argument-dependent lookup.

Definition at line 87 of file convert.hpp.

◆ StructToMessage() [3/3]

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

Converts struct instance obj to protobuf message msg.

Template Parameters
TStructstruct type
TMessageprotobuf message type
Exceptions
ConversionErrorif conversion failed (in that case msg is not modified)
Warning
If function throws an exception, msg is left in a valid but unspecified state

Function calls WriteStruct(std::forward<TStruct>(obj), msg) under the hood which should be foundable by argument-dependent lookup.

Definition at line 55 of file convert.hpp.

Variable Documentation

◆ kOneofNpos

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

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

Definition at line 64 of file oneof.hpp.