userver: /data/code/userver/libraries/proto-structs/src/proto-structs/io/userver/formats/json/value_conv.cpp Source File
Loading...
Searching...
No Matches
value_conv.cpp
1#include <userver/proto-structs/io/userver/formats/json/value_conv.hpp>
2
3#include <google/protobuf/struct.pb.h>
4
5#include <userver/proto-structs/io/context.hpp>
6#include <userver/protobuf/json/convert.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace proto_structs::io {
11
12formats::json::Value ReadProtoStruct(ReadContext& ctx, To<formats::json::Value>, const ::google::protobuf::Value& msg) {
13 try {
14 return protobuf::json::MessageToJson(msg, protobuf::json::PrintOptions{});
15 } catch (const protobuf::json::PrintError& e) {
16 ctx.AddError(e.what());
17 return formats::json::Value{};
18 }
19}
20
21void WriteProtoStruct(WriteContext&, const formats::json::Value& obj, ::google::protobuf::Value& msg) {
22 protobuf::json::JsonToMessage(obj, msg, protobuf::json::ParseOptions{});
23}
24
25} // namespace proto_structs::io
26
27USERVER_NAMESPACE_END