userver: formats::serialize Namespace Reference
Loading...
Searching...
No Matches
formats::serialize Namespace Reference

Detailed Description

Common serializers.

Classes

struct  SaxStream
struct  To

Functions

template<impl::RangeNotMap T, typename Value>
Value Serialize (const T &value, To< Value >)
 Common containers serialization (vector/set).
template<meta::IsUniqueMap T, typename Value>
Value Serialize (const T &value, To< Value >)
 Mappings serialization.
template<typename T, typename Value>
Value Serialize (const std::optional< T > &value, To< Value >)
 std::optional serialization
json::Value Serialize (const google::protobuf::Message &message, To< json::Value >)
 Conversion from any google::protobuf::Message to formats::json::Value. Uses the ProtoJSON format in the same way as protobuf::MessageToJson called with a default options.
template<typename TStruct>
requires proto_structs::traits::ProtoStruct<std::remove_cvref_t<TStruct>>
json::Value Serialize (const TStruct &obj, To< json::Value >)
 Converts protobuf struct obj to formats::json::Value. Conversion is performed by applying proto_structs::StructToJson to obj with default protobuf::json::PrintOptions.
template<class Rep, class Period>
static json::Value Serialize (std::chrono::duration< Rep, Period > duration, To< formats::json::Value >)
template<class Rep, class Period>
static void WriteToStream (std::chrono::duration< Rep, Period > duration, formats::json::StringBuilder &sw)
template<typename T, typename Value>
Value Serialize (const boost::optional< T > &value, To< Value >)
template<typename Value>
Value Serialize (const boost::uuids::uuid &value, To< Value >)
 Outputs UUID in format: 12345678-1234-1234-1234-123412345678.
template<typename StringBuilder>
void WriteToStream (const boost::uuids::uuid &value, StringBuilder &sw)
template<typename Value, typename Duration>
Value Serialize (const utils::datetime::TimeOfDay< Duration > &value, To< Value >)
template<typename Value, typename Duration, typename StringBuilder>
void WriteToStream (const utils::datetime::TimeOfDay< Duration > &value, StringBuilder &sw)
template<typename Value, typename... Types>
Value Serialize (const std::variant< Types... > &value, To< Value >)
template<typename... Types, typename StringBuilder>
void WriteToStream (const std::variant< Types... > &value, StringBuilder &sw)
 Variant serialization.
template<typename T, typename StringBuilder>
void WriteToStream (const std::optional< T > &value, StringBuilder &sw)
 std::optional serialization
template<typename T, typename StringBuilder>
requires (!std::is_arithmetic_v<T> && !std::is_convertible_v<T&, utils::impl::strong_typedef::StrongTypedefTag&>)
void WriteToStream (const T &value, StringBuilder &sw)
template<class Rep, class Period>
static bson::Value Serialize (std::chrono::duration< Rep, Period > duration, To< formats::bson::Value >)
formats::json::Value Serialize (const google::protobuf::Timestamp &value, formats::serialize::To< formats::json::Value >)
formats::json::Value Serialize (const google::type::Date &value, formats::serialize::To< formats::json::Value >)
formats::json::Value Serialize (const grpc::StatusCode &value, formats::serialize::To< formats::json::Value >)

Function Documentation

◆ Serialize() [1/11]

template<typename T, typename Value>
Value formats::serialize::Serialize ( const boost::optional< T > & value,
To< Value >  )

Definition at line 18 of file boost_optional.hpp.

◆ Serialize() [2/11]

template<typename Value>
Value formats::serialize::Serialize ( const boost::uuids::uuid & value,
To< Value >  )

Outputs UUID in format: 12345678-1234-1234-1234-123412345678.

Definition at line 24 of file boost_uuid.hpp.

◆ Serialize() [3/11]

json::Value formats::serialize::Serialize ( const google::protobuf::Message & message,
To< json::Value >  )

Conversion from any google::protobuf::Message to formats::json::Value. Uses the ProtoJSON format in the same way as protobuf::MessageToJson called with a default options.

Use as:

Definition at line 49 of file convert.cpp.

◆ Serialize() [4/11]

template<typename T, typename Value>
Value formats::serialize::Serialize ( const std::optional< T > & value,
To< Value >  )
inline

std::optional serialization

Definition at line 76 of file common_containers.hpp.

◆ Serialize() [5/11]

template<typename Value, typename... Types>
Value formats::serialize::Serialize ( const std::variant< Types... > & value,
To< Value >  )

Definition at line 16 of file variant.hpp.

◆ Serialize() [6/11]

template<meta::IsUniqueMap T, typename Value>
Value formats::serialize::Serialize ( const T & value,
To< Value >  )

Mappings serialization.

Definition at line 56 of file common_containers.hpp.

◆ Serialize() [7/11]

template<impl::RangeNotMap T, typename Value>
Value formats::serialize::Serialize ( const T & value,
To< Value >  )

Common containers serialization (vector/set).

Definition at line 42 of file common_containers.hpp.

◆ Serialize() [8/11]

template<typename TStruct>
requires proto_structs::traits::ProtoStruct<std::remove_cvref_t<TStruct>>
json::Value formats::serialize::Serialize ( const TStruct & obj,
To< json::Value >  )

Converts protobuf struct obj to formats::json::Value. Conversion is performed by applying proto_structs::StructToJson to obj with default protobuf::json::PrintOptions.

Definition at line 89 of file json.hpp.

◆ Serialize() [9/11]

template<typename Value, typename Duration>
Value formats::serialize::Serialize ( const utils::datetime::TimeOfDay< Duration > & value,
To< Value >  )

Definition at line 18 of file time_of_day.hpp.

◆ Serialize() [10/11]

template<class Rep, class Period>
bson::Value formats::serialize::Serialize ( std::chrono::duration< Rep, Period > duration,
To< formats::bson::Value >  )
static

Definition at line 18 of file serialize_duration.hpp.

◆ Serialize() [11/11]

template<class Rep, class Period>
json::Value formats::serialize::Serialize ( std::chrono::duration< Rep, Period > duration,
To< formats::json::Value >  )
static

Definition at line 19 of file serialize_duration.hpp.

◆ WriteToStream() [1/6]

template<typename StringBuilder>
void formats::serialize::WriteToStream ( const boost::uuids::uuid & value,
StringBuilder & sw )

Definition at line 29 of file boost_uuid.hpp.

◆ WriteToStream() [2/6]

template<typename T, typename StringBuilder>
void formats::serialize::WriteToStream ( const std::optional< T > & value,
StringBuilder & sw )

std::optional serialization

Definition at line 41 of file write_to_stream.hpp.

◆ WriteToStream() [3/6]

template<typename... Types, typename StringBuilder>
void formats::serialize::WriteToStream ( const std::variant< Types... > & value,
StringBuilder & sw )

Variant serialization.

Definition at line 35 of file write_to_stream.hpp.

◆ WriteToStream() [4/6]

template<typename T, typename StringBuilder>
requires (!std::is_arithmetic_v<T> && !std::is_convertible_v<T&, utils::impl::strong_typedef::StrongTypedefTag&>)
void formats::serialize::WriteToStream ( const T & value,
StringBuilder & sw )

Handle ranges, fall back to using formats::*::Serialize

The signature of this WriteToStream must remain the less specialized one, so that it is not preferred over other functions.

Definition at line 86 of file write_to_stream.hpp.

◆ WriteToStream() [5/6]

template<typename Value, typename Duration, typename StringBuilder>
void formats::serialize::WriteToStream ( const utils::datetime::TimeOfDay< Duration > & value,
StringBuilder & sw )

Definition at line 23 of file time_of_day.hpp.

◆ WriteToStream() [6/6]

template<class Rep, class Period>
void formats::serialize::WriteToStream ( std::chrono::duration< Rep, Period > duration,
formats::json::StringBuilder & sw )
static

Definition at line 26 of file serialize_duration.hpp.