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

Detailed Description

Generic parsers and converters.

Classes

struct  To
 

Functions

template<typename T, typename Value>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsRange< T > &&!meta::kIsMap< T > &&!std::is_same_v< T, boost::uuids::uuid > &&!std::is_convertible_v< T &, utils::impl::strong_typedef::StrongTypedefTag & >, T > Parse (const Value &value, To< T >)
 
template<typename T, typename Value>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsMap< T >, T > Parse (const Value &value, To< T >)
 
template<typename T, typename Value>
std::optional< decltype(Parse(std::declval< Value >(), To< T >{}))> Parse (const Value &value, To< std::optional< T > >)
 
template<class Value>
std::optional< std::nullptr_t > Parse (const Value &, To< std::optional< std::nullptr_t > >)
 
template<typename T, typename Value>
std::enable_if_t< meta::kIsRange< T > &&!meta::kIsMap< T > &&!std::is_same_v< T, boost::uuids::uuid > &&!std::is_convertible_v< T &, utils::impl::strong_typedef::StrongTypedefTag & >, T > Convert (const Value &value, To< T >)
 
template<typename T, typename Value>
std::enable_if_t< meta::kIsMap< T >, T > Convert (const Value &value, To< T >)
 
template<typename T, typename Value>
std::optional< T > Convert (const Value &value, To< std::optional< T > >)
 
template<class Value>
std::optional< std::nullptr_t > Convert (const Value &, To< std::optional< std::nullptr_t > >)
 
template<typename Value>
float Parse (const Value &value, To< float >)
 
template<typename Value, typename T>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsInteger< T >, T > Parse (const Value &value, To< T >)
 
template<typename Value, typename Period>
std::enable_if_t< common::kIsFormatValue< Value >, std::chrono::duration< double, Period > > Parse (const Value &n, To< std::chrono::duration< double, Period > >)
 
template<typename Value>
std::enable_if_t< common::kIsFormatValue< Value >, std::chrono::seconds > Parse (const Value &n, To< std::chrono::seconds >)
 
template<class Value, class Duration>
std::chrono::time_point< std::chrono::system_clock, Duration > Parse (const Value &n, To< std::chrono::time_point< std::chrono::system_clock, Duration > >)
 
template<class Value>
float Convert (const Value &value, To< float >)
 
template<typename Value, typename T>
std::enable_if_t< meta::kIsInteger< T >, T > Convert (const Value &value, To< T >)
 
template<typename Value>
std::chrono::seconds Convert (const Value &n, To< std::chrono::seconds >)
 
template<class Value, typename T>
boost::optional< T > Parse (const Value &value, To< boost::optional< T > >)
 
template<class Value>
boost::optional< std::nullptr_t > Parse (const Value &, To< boost::optional< std::nullptr_t > >)
 
template<class Value, typename T>
boost::optional< T > Convert (const Value &value, To< boost::optional< T > >)
 
template<class Value>
boost::optional< std::nullptr_t > Convert (const Value &, To< boost::optional< std::nullptr_t > >)
 
template<typename Value>
std::enable_if_t< common::kIsFormatValue< Value >, boost::uuids::uuid > Parse (const Value &value, To< boost::uuids::uuid >)
 
template<class Value, typename... Types>
boost::variant< Types... > Parse (const Value &value, formats::parse::To< boost::variant< Types... > >)
 
template<typename Value, typename Duration>
std::enable_if_t< common::kIsFormatValue< Value >, utils::datetime::TimeOfDay< Duration > > Parse (const Value &value, To< utils::datetime::TimeOfDay< Duration > >)
 
template<typename ParseException, typename Variant, typename TypeA>
void ThrowVariantAmbiguousParse (std::string_view path, std::type_index type_b)
 
template<class ParseException, typename Variant>
void ThrowVariantParseException (std::string_view path)
 
template<class Value, typename... Types>
std::variant< decltype(Parse(std::declval< Value >(), To< Types >{}))... > Parse (const Value &value, formats::parse::To< std::variant< Types... > >)
 
formats::json::Value Parse (const formats::yaml::Value &yaml, formats::parse::To< formats::json::Value >)
 Converts a YAML value to JSON format.
 
formats::yaml::Value Parse (const formats::json::Value &json, formats::parse::To< formats::yaml::Value >)
 Converts a JSON value to YAML format.
 
formats::json::Value Convert (const formats::bson::Value &bson, formats::parse::To< formats::json::Value >)
 Converts a BSON value to JSON format with type conversions.
 
formats::bson::Value Convert (const formats::json::Value &json, formats::parse::To< formats::bson::Value >)
 Converts a JSON value to BSON format.
 
formats::json::Value Parse (const formats::bson::Value &bson, formats::parse::To< formats::json::Value >)
 Converts a BSON value to JSON format (minimal conversion)
 
formats::bson::Value Parse (const formats::json::Value &json, formats::parse::To< formats::bson::Value >)
 Converts a JSON value to BSON format (minimal conversion)
 
google::protobuf::Timestamp Parse (const formats::json::Value &json, formats::parse::To< google::protobuf::Timestamp >)
 
google::type::Date Parse (const formats::json::Value &json, formats::parse::To< google::type::Date >)
 
template<typename Message, typename = std::enable_if_t<std::is_base_of_v<google::protobuf::Message, Message>>>
Message Parse (const json::Value &value, To< Message >)
 Conversion from formats::json::Value to google::protobuf::Message. Uses the same format as ugrpc::JsonToMessage with its default options.
 
grpc::StatusCode Parse (const yaml_config::YamlConfig &value, To< grpc::StatusCode >)
 yaml_config::YamlConfig parsing support for grpc::StatusCode.
 
grpc::StatusCode Parse (std::string_view value, To< grpc::StatusCode >)
 Support for parsing grpc::StatusCode from string. Used for headers and map keys.
 
ydb::DistLockSettings Parse (const yaml_config::YamlConfig &config, To< ydb::DistLockSettings >)
 
ydb::OperationSettings Parse (const yaml_config::YamlConfig &config, To< ydb::OperationSettings >)
 

Function Documentation

◆ Convert() [1/11]

formats::json::Value formats::parse::Convert ( const formats::bson::Value & bson,
formats::parse::To< formats::json::Value >  )

Converts a BSON value to JSON format with type conversions.

Performs format conversion with special handling for BSON-specific types:

  • BSON Timestamp → int64 (milliseconds since epoch)
  • BSON Decimal128 → string representation
  • BSON Oid → string representation
  • BSON Binary → string representation
  • BSON MinKey → JSON object {"$minKey": 1}
  • BSON MaxKey → JSON object {"$maxKey": 1}
  • Basic types (bool, int32, int64, double, string, datetime) are preserved
  • Arrays and objects are recursively converted
Exceptions
formats::bson::ConversionExceptionif the BSON value contains an unknown type that cannot be converted to JSON

◆ Convert() [2/11]

formats::bson::Value formats::parse::Convert ( const formats::json::Value & json,
formats::parse::To< formats::bson::Value >  )

Converts a JSON value to BSON format.

Performs a minimal format conversion that preserves basic types (bool, int, int64, uint64, double, string, null, arrays, objects). Missing JSON values are converted to BSON null.

◆ Convert() [3/11]

template<class Value>
boost::optional< std::nullptr_t > formats::parse::Convert ( const Value & ,
To< boost::optional< std::nullptr_t > >  )

Definition at line 38 of file boost_optional.hpp.

◆ Convert() [4/11]

template<class Value>
std::optional< std::nullptr_t > formats::parse::Convert ( const Value & ,
To< std::optional< std::nullptr_t > >  )

Definition at line 132 of file common_containers.hpp.

◆ Convert() [5/11]

template<typename Value>
std::chrono::seconds formats::parse::Convert ( const Value & n,
To< std::chrono::seconds >  )

Definition at line 135 of file common.hpp.

◆ Convert() [6/11]

template<class Value, typename T>
boost::optional< T > formats::parse::Convert ( const Value & value,
To< boost::optional< T > >  )

Definition at line 30 of file boost_optional.hpp.

◆ Convert() [7/11]

template<class Value>
float formats::parse::Convert ( const Value & value,
To< float >  )

Definition at line 124 of file common.hpp.

◆ Convert() [8/11]

template<typename T, typename Value>
std::optional< T > formats::parse::Convert ( const Value & value,
To< std::optional< T > >  )

Definition at line 124 of file common_containers.hpp.

◆ Convert() [9/11]

template<typename Value, typename T>
std::enable_if_t< meta::kIsInteger< T >, T > formats::parse::Convert ( const Value & value,
To< T >  )

Definition at line 129 of file common.hpp.

◆ Convert() [10/11]

template<typename T, typename Value>
std::enable_if_t< meta::kIsRange< T > &&!meta::kIsMap< T > &&!std::is_same_v< T, boost::uuids::uuid > &&!std::is_convertible_v< T &, utils::impl::strong_typedef::StrongTypedefTag & >, T > formats::parse::Convert ( const Value & value,
To< T >  )

Definition at line 108 of file common_containers.hpp.

◆ Convert() [11/11]

template<typename T, typename Value>
std::enable_if_t< meta::kIsMap< T >, T > formats::parse::Convert ( const Value & value,
To< T >  )

Definition at line 116 of file common_containers.hpp.

◆ Parse() [1/20]

Converts a BSON value to JSON format (minimal conversion)

Performs a minimal format conversion that only handles basic types common to both BSON and JSON (bool, int, int64, uint64, double, string, null, arrays, objects).

Warning
BSON-specific types (Timestamp, Decimal128, Oid, Binary, MinKey, MaxKey, etc.) are NOT supported by this function. For converting BSON documents with these types, use Convert() instead, which provides proper type conversions.
Exceptions
formats::bson::Exceptionif the BSON value is missing or contains an unknown/unsupported node type (e.g., BSON-specific types like Timestamp, Oid, Binary, etc.)

◆ Parse() [2/20]

Converts a JSON value to BSON format (minimal conversion)

Performs a minimal format conversion that preserves the structure and basic types (bool, int, int64, uint64, double, string, null, arrays, objects).

Exceptions
formats::json::Exceptionif the JSON value is missing or contains an unknown node type that cannot be converted to BSON

◆ Parse() [3/20]

Converts a JSON value to YAML format.

Exceptions
formats::json::Exceptionif the JSON value is missing or contains an unknown node type that cannot be converted to YAML

◆ Parse() [4/20]

Converts a YAML value to JSON format.

Exceptions
formats::yaml::Exceptionif the YAML value is missing or contains an unknown node type that cannot be converted to JSON

◆ Parse() [5/20]

template<typename Message, typename = std::enable_if_t<std::is_base_of_v<google::protobuf::Message, Message>>>
Message formats::parse::Parse ( const json::Value & value,
To< Message >  )

Conversion from formats::json::Value to google::protobuf::Message. Uses the same format as ugrpc::JsonToMessage with its default options.

Works for google::protobuf::Value, google::protobuf::Struct, google::protobuf::ListValue (top-level and nested) as well, converts them without extra objects in JSON representation.

Use as:

auto value = json.As<google::protobuf::Value>();

Definition at line 123 of file proto_json.hpp.

◆ Parse() [6/20]

template<class Value>
boost::optional< std::nullptr_t > formats::parse::Parse ( const Value & ,
To< boost::optional< std::nullptr_t > >  )

Definition at line 24 of file boost_optional.hpp.

◆ Parse() [7/20]

template<class Value>
std::optional< std::nullptr_t > formats::parse::Parse ( const Value & ,
To< std::optional< std::nullptr_t > >  )

Definition at line 98 of file common_containers.hpp.

◆ Parse() [8/20]

template<typename Value, typename Period>
std::enable_if_t< common::kIsFormatValue< Value >, std::chrono::duration< double, Period > > formats::parse::Parse ( const Value & n,
To< std::chrono::duration< double, Period > >  )

Definition at line 107 of file common.hpp.

◆ Parse() [9/20]

template<typename Value>
std::enable_if_t< common::kIsFormatValue< Value >, std::chrono::seconds > formats::parse::Parse ( const Value & n,
To< std::chrono::seconds >  )

Definition at line 112 of file common.hpp.

◆ Parse() [10/20]

template<class Value, class Duration>
std::chrono::time_point< std::chrono::system_clock, Duration > formats::parse::Parse ( const Value & n,
To< std::chrono::time_point< std::chrono::system_clock, Duration > >  )

Definition at line 119 of file common.hpp.

◆ Parse() [11/20]

template<class Value, typename... Types>
boost::variant< Types... > formats::parse::Parse ( const Value & value,
formats::parse::To< boost::variant< Types... > >  )

Definition at line 44 of file boost_variant.hpp.

◆ Parse() [12/20]

template<class Value, typename... Types>
std::variant< decltype(Parse(std::declval< Value >(), To< Types >{}))... > formats::parse::Parse ( const Value & value,
formats::parse::To< std::variant< Types... > >  )

Definition at line 69 of file variant.hpp.

◆ Parse() [13/20]

template<class Value, typename T>
boost::optional< T > formats::parse::Parse ( const Value & value,
To< boost::optional< T > >  )

Definition at line 16 of file boost_optional.hpp.

◆ Parse() [14/20]

template<typename Value>
std::enable_if_t< common::kIsFormatValue< Value >, boost::uuids::uuid > formats::parse::Parse ( const Value & value,
To< boost::uuids::uuid >  )

Valid uuid strings: 0123456789abcdef0123456789abcdef 01234567-89ab-cdef-0123-456789abcdef {01234567-89ab-cdef-0123-456789abcdef} {0123456789abcdef0123456789abcdef}

Definition at line 28 of file boost_uuid.hpp.

◆ Parse() [15/20]

template<typename Value>
float formats::parse::Parse ( const Value & value,
To< float >  )

Definition at line 95 of file common.hpp.

◆ Parse() [16/20]

template<typename T, typename Value>
std::optional< decltype(Parse(std::declval< Value >(), To< T >{}))> formats::parse::Parse ( const Value & value,
To< std::optional< T > >  )

Definition at line 90 of file common_containers.hpp.

◆ Parse() [17/20]

template<typename Value, typename T>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsInteger< T >, T > formats::parse::Parse ( const Value & value,
To< T >  )

Definition at line 100 of file common.hpp.

◆ Parse() [18/20]

template<typename T, typename Value>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsRange< T > &&!meta::kIsMap< T > &&!std::is_same_v< T, boost::uuids::uuid > &&!std::is_convertible_v< T &, utils::impl::strong_typedef::StrongTypedefTag & >, T > formats::parse::Parse ( const Value & value,
To< T >  )

Definition at line 80 of file common_containers.hpp.

◆ Parse() [19/20]

template<typename T, typename Value>
std::enable_if_t< common::kIsFormatValue< Value > &&meta::kIsMap< T >, T > formats::parse::Parse ( const Value & value,
To< T >  )

Definition at line 85 of file common_containers.hpp.

◆ Parse() [20/20]

template<typename Value, typename Duration>
std::enable_if_t< common::kIsFormatValue< Value >, utils::datetime::TimeOfDay< Duration > > formats::parse::Parse ( const Value & value,
To< utils::datetime::TimeOfDay< Duration > >  )

Definition at line 19 of file time_of_day.hpp.

◆ ThrowVariantAmbiguousParse()

template<typename ParseException, typename Variant, typename TypeA>
void formats::parse::ThrowVariantAmbiguousParse ( std::string_view path,
std::type_index type_b )

Definition at line 29 of file variant.hpp.

◆ ThrowVariantParseException()

template<class ParseException, typename Variant>
void formats::parse::ThrowVariantParseException ( std::string_view path)

Definition at line 40 of file variant.hpp.