userver: /data/code/userver/libraries/proto-structs/include/userver/proto-structs/convert.hpp File Reference
Loading...
Searching...
No Matches
convert.hpp File Reference

Detailed Description

Functions for protobuf message to/from struct conversion.

Conversion functions rely on user-defined functions with the following signatures:

  1. StructType ReadProtoStruct(proto_structs::io::ReadContext&, proto_structs::io::To<StructType>, const MessageType&)
  2. void WriteProtoStruct(proto_structs::io::WriteContext&, const StructType&, MessageType&)

This functions should be foundable by ADL lookup (just place them in the namespace where StructType is defined).

It is recommended to define WriteProtoStruct function as template with a StructType parameter and use universal reference StructType&& as a second parameter to enable perfect forwarding for conversions.

Definition in file convert.hpp.

Go to the source code of this file.

This graph shows which files directly or indirectly include this file:

Namespaces

namespace  proto_structs
 Top namespace for the proto-structs library.

Functions

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<traits::ProtoStruct TStruct, traits::ProtoMessage TMessage>
TStruct proto_structs::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 proto_structs::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 > > proto_structs::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 proto_structs::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 proto_structs::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 proto_structs::StructToBinary (TStruct &&obj)
 Converts proto struct obj to it's compatible binary data.