userver: /data/code/userver/libraries/protobuf/src/protobuf/json/convert.cpp Source File
Loading...
Searching...
No Matches
convert.cpp
1#include <userver/protobuf/json/convert.hpp>
2
3#include <userver/formats/json/serialize.hpp>
4
5#include <protobuf/json/impl/read.hpp>
6#include <protobuf/json/impl/write.hpp>
7#include <protobuf/json/impl/write_debug_string.hpp>
8#include <protobuf/json/impl/write_json_string.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace protobuf::json {
13
14formats::json::ValueBuilder MessageToJsonBuilder(
15 const ::google::protobuf::Message& message,
16 const PrintOptions& options
17) {
18 return impl::WriteMessage(message, options);
19}
20
21void JsonToMessage(
22 const formats::json::Value& json,
23 ::google::protobuf::Message& message,
24 const ParseOptions& options
25) {
26 impl::ReadMessage(json, message, options);
27}
28
29void JsonStringToMessage(
30 std::string_view json_string,
31 ::google::protobuf::Message& message,
32 const ParseOptions& options
33) {
34 JsonToMessage(formats::json::FromString(json_string), message, options);
35}
36
37std::string MessageToJsonString(const ::google::protobuf::Message& message, const PrintOptions& options) {
38 return impl::WriteMessageToJsonString(message, options);
39}
40
41std::string MessageToDebugString(const ::google::protobuf::Message& message, std::size_t limit) {
42 return impl::WriteMessageToDebugString(message, limit);
43}
44
45} // namespace protobuf::json
46
47namespace formats::serialize {
48
49json::Value Serialize(const ::google::protobuf::Message& message, To<json::Value>) {
50 return protobuf::json::MessageToJson(message);
51}
52
53} // namespace formats::serialize
54
55USERVER_NAMESPACE_END