userver: userver/ugrpc/proto_json.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
proto_json.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/proto_json.hpp
4/// @brief Utilities for conversion Protobuf -> Json
5/// @ingroup userver_formats_serialize userver_formats_parse
6
7#include <google/protobuf/struct.pb.h>
8#include <google/protobuf/util/json_util.h>
9
10#include <userver/formats/json.hpp>
11#include <userver/formats/json/serialize.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace ugrpc {
16
17/// @brief Returns formats::json::Value representation of protobuf message
18/// @throws SerializationError
19formats::json::Value MessageToJson(const google::protobuf::Message& message);
20
21/// @brief Converts message to human readable string
22std::string ToString(const google::protobuf::Message& message);
23
24/// @brief Returns Json-string representation of protobuf message
25/// @throws formats::json::Exception
26std::string ToJsonString(const google::protobuf::Message& message);
27
28/// @brief Returns formats::json::Value representation of protobuf message
29/// @throws SerializationError
30formats::json::Value
31MessageToJson(const google::protobuf::Message& message, const google::protobuf::util::JsonPrintOptions& options);
32
33/// @brief Returns Json-string representation of protobuf message
34/// @throws formats::json::Exception
35std::string
36ToJsonString(const google::protobuf::Message& message, const google::protobuf::util::JsonPrintOptions& options);
37
38} // namespace ugrpc
39
40namespace formats::serialize {
41
42json::Value Serialize(const google::protobuf::Message& message, To<json::Value>);
43
44} // namespace formats::serialize
45
46namespace formats::parse {
47
48google::protobuf::Value Parse(const formats::json::Value& value, To<google::protobuf::Value>);
49
50}
51
52USERVER_NAMESPACE_END