userver: proto_structs::Any Class Reference
Loading...
Searching...
No Matches
proto_structs::Any Class Referencefinal

#include </data/code/userver/libraries/proto-structs/include/userver/proto-structs/any.hpp>

Detailed Description

Wrapper for google.protobuf.Any which provides interface to access stored message as compatible struct.

Definition at line 19 of file any.hpp.

Public Types

using ProtobufMessage = ::google::protobuf::Any
 

Public Member Functions

 Any () noexcept=default
 Creates empty Any.
 
 Any (google::protobuf::Any proto_any)
 Creates wrapper initializing its underlying storage with proto_any.
 
template<typename TStruct>
requires (!std::is_same_v<std::remove_cvref_t<TStruct>, ::google::protobuf::Any>) && (!std::is_same_v<std::remove_cvref_t<TStruct>, Any>) && traits::ProtoStruct<std::remove_cvref_t<TStruct>>
 Any (TStruct &&obj)
 Creates Any holding obj.
 
template<typename TStruct>
requires (!std::is_same_v<std::remove_cvref_t<TStruct>, ::google::protobuf::Any>) && (!std::is_same_v<std::remove_cvref_t<TStruct>, Any>) && traits::ProtoStruct<std::remove_cvref_t<TStruct>>
Anyoperator= (TStruct &&obj)
 Packs obj in Any.
 
template<traits::ProtoStruct TStruct>
bool Is () const noexcept
 Returns true if Any contains TStruct.
 
template<traits::ProtoMessage TMessage>
bool Is () const noexcept
 Returns true if underlying google.protobuf.Any contains TMessage.
 
template<traits::ProtoStruct TStruct>
TStruct Unpack ()
 Unpacks Any to TStruct struct.
 
template<traits::ProtoMessage TMessage>
TMessage Unpack ()
 Unpacks underlying google.protobuf.Any to TMessage message.
 
template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void Pack (TStruct &&obj)
 Packs obj to Any.
 
template<traits::ProtoMessage TMessage>
void Pack (const TMessage &message)
 Packs message to underlying google.protobuf.Any.
 
const ::google::protobuf::Any & GetProtobufAny () const &noexcept
 Returns underlying google.protobuf.Any.
 
::google::protobuf::Any && GetProtobufAny () &&noexcept
 Returns underlying google.protobuf.Any.
 

Member Typedef Documentation

◆ ProtobufMessage

using proto_structs::Any::ProtobufMessage = ::google::protobuf::Any

Definition at line 21 of file any.hpp.

Constructor & Destructor Documentation

◆ Any() [1/2]

proto_structs::Any::Any ( google::protobuf::Any proto_any)
inline

Creates wrapper initializing its underlying storage with proto_any.

Definition at line 27 of file any.hpp.

◆ Any() [2/2]

template<typename TStruct>
requires (!std::is_same_v<std::remove_cvref_t<TStruct>, ::google::protobuf::Any>) && (!std::is_same_v<std::remove_cvref_t<TStruct>, Any>) && traits::ProtoStruct<std::remove_cvref_t<TStruct>>
proto_structs::Any::Any ( TStruct && obj)
inline

Creates Any holding obj.

Template Parameters
TStructproto struct type
Exceptions
WriteErrorif conversion of obj to its compatible message has failed.
AnyPackErrorif compatible protobuf message can not be packed to google.protobuf.Any.

Definition at line 36 of file any.hpp.

Member Function Documentation

◆ GetProtobufAny() [1/2]

::google::protobuf::Any && proto_structs::Any::GetProtobufAny ( ) &&
inlinenodiscardnoexcept

Returns underlying google.protobuf.Any.

Definition at line 116 of file any.hpp.

◆ GetProtobufAny() [2/2]

const ::google::protobuf::Any & proto_structs::Any::GetProtobufAny ( ) const &
inlinenodiscardnoexcept

Returns underlying google.protobuf.Any.

Definition at line 113 of file any.hpp.

◆ Is() [1/2]

template<traits::ProtoStruct TStruct>
bool proto_structs::Any::Is ( ) const
inlinenodiscardnoexcept

Returns true if Any contains TStruct.

Template Parameters
TStructproto struct type

Definition at line 55 of file any.hpp.

◆ Is() [2/2]

template<traits::ProtoMessage TMessage>
bool proto_structs::Any::Is ( ) const
inlinenodiscardnoexcept

Returns true if underlying google.protobuf.Any contains TMessage.

Template Parameters
TMessageprotobuf message type

Definition at line 63 of file any.hpp.

◆ operator=()

template<typename TStruct>
requires (!std::is_same_v<std::remove_cvref_t<TStruct>, ::google::protobuf::Any>) && (!std::is_same_v<std::remove_cvref_t<TStruct>, Any>) && traits::ProtoStruct<std::remove_cvref_t<TStruct>>
Any & proto_structs::Any::operator= ( TStruct && obj)
inline

Packs obj in Any.

Template Parameters
TStructproto struct type
Exceptions
WriteErrorif conversion of obj to its compatible message has failed.
AnyPackErrorif compatible protobuf message can not be packed to google.protobuf.Any.

Definition at line 47 of file any.hpp.

◆ Pack() [1/2]

template<traits::ProtoMessage TMessage>
void proto_structs::Any::Pack ( const TMessage & message)
inline

Packs message to underlying google.protobuf.Any.

Template Parameters
TMessageprotobuf message type
Exceptions
AnyPackErrorif packing of protobuf message to google.protobuf.Any has failed.

Definition at line 106 of file any.hpp.

◆ Pack() [2/2]

template<typename TStruct>
requires traits::ProtoStruct<std::remove_cvref_t<TStruct>>
void proto_structs::Any::Pack ( TStruct && obj)
inline

Packs obj to Any.

Template Parameters
TStructproto struct type
Exceptions
WriteErrorif conversion of obj to its compatible message has failed.
AnyPackErrorif packing of compatible protobuf message to google.protobuf.Any has failed.

Definition at line 97 of file any.hpp.

◆ Unpack() [1/2]

template<traits::ProtoStruct TStruct>
TStruct proto_structs::Any::Unpack ( )
inlinenodiscard

Unpacks Any to TStruct struct.

Template Parameters
TStructproto struct type
Exceptions
AnyUnpackErrorif underlying google.protobuf.Any does not contain message compatible to TStruct.
ReadErrorif conversion of unpacked protobuf message to proto struct has failed.

Definition at line 72 of file any.hpp.

◆ Unpack() [2/2]

template<traits::ProtoMessage TMessage>
TMessage proto_structs::Any::Unpack ( )
inlinenodiscard

Unpacks underlying google.protobuf.Any to TMessage message.

Template Parameters
TMessageprotobuf message type
Exceptions
AnyUnpackErrorif underlying google.protobuf.Any does not contain TMessage type message.

Definition at line 81 of file any.hpp.


The documentation for this class was generated from the following file: