Utilities for converting protobuf structs to/from formats::json::Value.
Definition in file json.hpp.
Go to the source code of this file.
#include <userver/formats/json/serialize.hpp>#include <userver/logging/log_helper.hpp>#include <userver/proto-structs/convert.hpp>#include <userver/proto-structs/type_mapping.hpp>#include <userver/protobuf/json/convert.hpp>
This graph shows which files directly or indirectly include this file:Namespaces | |
| namespace | proto_structs |
| Top namespace for the proto-structs library. | |
| namespace | formats |
| Value formats representation, parsing and serialization. | |
| namespace | formats::serialize |
| Common serializers. | |
| namespace | formats::parse |
| Generic parsers and converters. | |
| namespace | logging |
| Logging macro and utilities. | |
Functions | |
| template<typename TStruct> requires traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| formats::json::Value | proto_structs::StructToJson (TStruct &&obj, const protobuf::json::PrintOptions &options) |
| Converts protobuf struct obj to formats::json::Value. Conversion is performed by converting the protobuf struct to an intermediate protobuf message and then converting the message to formats::json::Value. | |
| template<typename TStruct> requires traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| std::string | proto_structs::StructToJsonString (TStruct &&obj, const protobuf::json::PrintOptions &options) |
| Converts protobuf struct obj to an std::string, containing the JSON representation of the struct. Conversion is performed by converting the protobuf struct to an intermediate protobuf message, then converting the message to formats::json::Value, and finally converting the value to a string. | |
| template<typename TStruct> requires traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| TStruct | proto_structs::JsonToStruct (const formats::json::Value &json, const protobuf::json::ParseOptions &options) |
Converts json to protobuf struct of type TStruct. Conversion is performed by converting the formats::json::Value to an intermediate protobuf message and then converting the message to a protobuf struct. | |
| template<typename TStruct> requires traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| TStruct | proto_structs::JsonStringToStruct (std::string_view json_string, const protobuf::json::ParseOptions &options) |
Converts json_string to protobuf struct of type TStruct. Conversion is performed by first converting the string to formats::json::Value, then converting the value to an intermediate protobuf message, and finally converting the message to a protobuf struct. | |
| 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. | |
| template<typename TStruct> requires proto_structs::traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| TStruct | formats::parse::Parse (const json::Value &json, To< TStruct >) |
Converts json to protobuf struct of type TStruct. Conversion is performed by applying proto_structs::JsonToStruct to json with default protobuf::json::ParseOptions. | |
| template<typename TStruct> requires proto_structs::traits::ProtoStruct<std::remove_cvref_t<TStruct>> | |
| logging::LogHelper & | logging::operator<< (logging::LogHelper &h, const TStruct &obj) |
| Logs the protobuf struct obj as a JSON string. The resulting JSON is constructed with always_print_primitive_fields and preserve_proto_field_names set to true, which allows the struct field names and values to be serialized as close as possible to the definition. | |