aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/yson_string/convert.h
blob: 3c2cc7d284054c8973cb2c25cc30c108f20e2331 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once

#include "string.h"

#include <library/cpp/yt/misc/guid.h>

#include <library/cpp/yt/exception/exception.h>

#include <util/generic/string.h>

#include <util/datetime/base.h>

namespace NYT::NYson {

////////////////////////////////////////////////////////////////////////////////
// Generic forward declarations.

template <class T>
TYsonString ConvertToYsonString(const T& value);

template <class T>
TYsonString ConvertToYsonString(const T& value, EYsonFormat format);

template <class T>
T ConvertFromYsonString(const TYsonStringBuf& str);

////////////////////////////////////////////////////////////////////////////////
// Basic specializations for ConvertToYsonString.

template <>
TYsonString ConvertToYsonString<i8>(const i8& value);
template <>
TYsonString ConvertToYsonString<i32>(const i32& value);
template <>
TYsonString ConvertToYsonString<i64>(const i64& value);

template <>
TYsonString ConvertToYsonString<ui8>(const ui8& value);
template <>
TYsonString ConvertToYsonString<ui32>(const ui32& value);
template <>
TYsonString ConvertToYsonString<ui64>(const ui64& value);

template <>
TYsonString ConvertToYsonString<TString>(const TString& value);
template <>
TYsonString ConvertToYsonString<TStringBuf>(const TStringBuf& value);
TYsonString ConvertToYsonString(const char* value);

template <>
TYsonString ConvertToYsonString<float>(const float& value);
template <>
TYsonString ConvertToYsonString<double>(const double& value);

template <>
TYsonString ConvertToYsonString<bool>(const bool& value);

template <>
TYsonString ConvertToYsonString<TInstant>(const TInstant& value);

template <>
TYsonString ConvertToYsonString<TDuration>(const TDuration& value);

template <>
TYsonString ConvertToYsonString<TGuid>(const TGuid& value);

////////////////////////////////////////////////////////////////////////////////
// Basic specializations for ConvertFromYsonString.
// Note: these currently support a subset of NYT::NYTree::Convert features.

class TYsonLiteralParseException
    : public TCompositeException
{
public:
    using TCompositeException::TCompositeException;
};

template <>
i8 ConvertFromYsonString<i8>(const TYsonStringBuf& str);
template <>
i32 ConvertFromYsonString<i32>(const TYsonStringBuf& str);
template <>
i64 ConvertFromYsonString<i64>(const TYsonStringBuf& str);

template <>
ui8 ConvertFromYsonString<ui8>(const TYsonStringBuf& str);
template <>
ui32 ConvertFromYsonString<ui32>(const TYsonStringBuf& str);
template <>
ui64 ConvertFromYsonString<ui64>(const TYsonStringBuf& str);

template <>
TString ConvertFromYsonString<TString>(const TYsonStringBuf& str);

template <>
float ConvertFromYsonString<float>(const TYsonStringBuf& str);
template <>
double ConvertFromYsonString<double>(const TYsonStringBuf& str);

template <>
bool ConvertFromYsonString<bool>(const TYsonStringBuf& str);

template <>
TInstant ConvertFromYsonString<TInstant>(const TYsonStringBuf& str);

template <>
TDuration ConvertFromYsonString<TDuration>(const TYsonStringBuf& str);

template <>
TGuid ConvertFromYsonString<TGuid>(const TYsonStringBuf& str);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NYson