aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/ipreg/util_helpers.h
blob: eab2dfb32090b97ea29de4dc02b868a6932fa8d3 (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
57
58
59
60
61
62
63
64
65
#pragma once

#include <library/cpp/getopt/opt.h>
#include <util/generic/string.h>
#include <util/generic/maybe.h>

class IInputStream;
class IOutputStream;

namespace NJson {
    class TJsonValue;
}

namespace NIPREG {
    class TReader;

    // @input   any form of range+payload
    // @output  $ip.begin-$ip.end \t {"region_id":$reg,"reliability":$rel}
    void DoCoarsening(IInputStream& input, IOutputStream& output);

    struct MergeTraits {
        const TVector<TString> ExcludeFieldsList;
        TString ConcatSep;
        bool SortData{};
        bool CountMerges{};
        bool JoinNestedRanges{};
    };

    void DoMerging(TReader& input, IOutputStream& output, const MergeTraits& traits);
    void DoMerging3(TReader& input, IOutputStream& output, const TString& geodata, bool ByRegsOnly = false, bool silentMode = false);
    void DoMergeEqualsRange(TReader& input, IOutputStream& output);

    void DoPatching(TReader& base, TReader& patch, IOutputStream& output, bool sortData = false);

    void AddStubRanges(TReader& input, IOutputStream& output);

    void CheckAddressSpaceForCompleteness(IInputStream& input, IOutputStream& output);
    void CheckRangesForMonotonicSequence(IInputStream& input, IOutputStream& output, bool IsStrict = false);

    NJson::TJsonValue ParseJsonString(const TString& data);
    TString SortJsonData(const NJson::TJsonValue& json);
    TString SortJsonData(const TString& json);

    TString AddJsonAttrs(const TVector<TString>& addFieldsList, const TString& jsonStr, const TMaybe<TString>& attrValue);
    TString ExcludeJsonAttrs(const TVector<TString>& excludeFieldsList, const TString& jsonStr);
    TString ExtractJsonAttrs(const TVector<TString>& excludeFieldsList, const TString& jsonStr);

    extern const TString STUB_DATA;

    struct DefaultCliParams {
        DefaultCliParams();

        NLastGetopt::TOpts& GetOpts() { return Opts; }
        void Parse(int argc, const char **argv);
        void ApplyFlags() const;

        TString InputFname  = "-";
        TString OutputFname = "";
        bool OutputFullIp = false;
        bool PrintStats = false;
        bool PrintYtStats = false;

        NLastGetopt::TOpts Opts;
    };
} // NIPREG