aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/proto2json.cpp
blob: 3d76a9168675797ea810deb5691f60c243d29b7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "proto2json.h"

#include "json_output_create.h"
#include "proto2json_printer.h"

#include <library/cpp/json/json_reader.h>
#include <library/cpp/json/json_value.h>
#include <library/cpp/json/json_writer.h>

#include <util/generic/ptr.h>
#include <util/generic/strbuf.h>
#include <util/stream/output.h>
#include <util/stream/str.h>
#include <util/system/yassert.h>

namespace NProtobufJson {
    void Proto2Json(const NProtoBuf::Message& proto, IJsonOutput& jsonOutput,
                    const TProto2JsonConfig& config, bool closeMap) {
        TProto2JsonPrinter printer(config);
        printer.Print(proto, jsonOutput, closeMap);
    }

    void Proto2Json(const NProtoBuf::Message& proto, NJson::TJsonValue& json,
                    const TProto2JsonConfig& config) {
        Proto2Json(proto, *CreateJsonMapOutput(json), config);
    }

    void Proto2Json(const NProtoBuf::Message& proto, NJson::TJsonWriter& writer,
                    const TProto2JsonConfig& config) {
        Proto2Json(proto, *CreateJsonMapOutput(writer), config);
        writer.Flush();
    }

    void Proto2Json(const NProtoBuf::Message& proto, IOutputStream& out,
                    const TProto2JsonConfig& config) {
        Proto2Json(proto, *CreateJsonMapOutput(out, config), config);
    }

    void Proto2Json(const NProtoBuf::Message& proto, TStringStream& out,
                    const TProto2JsonConfig& config) {
        Proto2Json(proto, *CreateJsonMapOutput(out, config), config);
    }

    void Proto2Json(const NProtoBuf::Message& proto, TString& str,
                    const TProto2JsonConfig& config) {
        Proto2Json(proto, *CreateJsonMapOutput(str, config), config);
    }

    TString Proto2Json(const ::NProtoBuf::Message& proto,
                       const TProto2JsonConfig& config) {
        TString res;
        Proto2Json(proto, res, config);
        return res;
    }

}