userver: userver/ugrpc/proto_json.hpp Source File
Loading...
Searching...
No Matches
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} // namespace ugrpc
29
30namespace formats::serialize {
31
32json::Value Serialize(const google::protobuf::Message& message,
33 To<json::Value>);
34
35} // namespace formats::serialize
36
37namespace formats::parse {
38
39google::protobuf::Value Parse(const formats::json::Value& value,
40 To<google::protobuf::Value>);
41
42}
43
44USERVER_NAMESPACE_END