aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json/json_writer.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/json/json_writer.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json/json_writer.h')
-rw-r--r--library/cpp/json/json_writer.h296
1 files changed, 148 insertions, 148 deletions
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h
index c7f5c9499a..b56ba5e8a7 100644
--- a/library/cpp/json/json_writer.h
+++ b/library/cpp/json/json_writer.h
@@ -12,148 +12,148 @@
#include <util/generic/strbuf.h>
namespace NJson {
- struct TJsonWriterConfig {
+ struct TJsonWriterConfig {
constexpr static ui32 DefaultDoubleNDigits = 10;
constexpr static ui32 DefaultFloatNDigits = 6;
constexpr static EFloatToStringMode DefaultFloatToStringMode = PREC_NDIGITS;
- inline TJsonWriterConfig& SetUnbuffered(bool v) noexcept {
- Unbuffered = v;
-
- return *this;
- }
-
- inline TJsonWriterConfig& SetValidateUtf8(bool v) noexcept {
- ValidateUtf8 = v;
-
- return *this;
- }
-
- inline TJsonWriterConfig& SetFormatOutput(bool v) noexcept {
- FormatOutput = v;
-
- return *this;
- }
-
+ inline TJsonWriterConfig& SetUnbuffered(bool v) noexcept {
+ Unbuffered = v;
+
+ return *this;
+ }
+
+ inline TJsonWriterConfig& SetValidateUtf8(bool v) noexcept {
+ ValidateUtf8 = v;
+
+ return *this;
+ }
+
+ inline TJsonWriterConfig& SetFormatOutput(bool v) noexcept {
+ FormatOutput = v;
+
+ return *this;
+ }
+
ui32 DoubleNDigits = DefaultDoubleNDigits;
ui32 FloatNDigits = DefaultFloatNDigits;
EFloatToStringMode FloatToStringMode = DefaultFloatToStringMode;
- bool FormatOutput = false;
- bool SortKeys = false;
- bool ValidateUtf8 = true;
- bool DontEscapeStrings = false;
- bool Unbuffered = false;
- bool WriteNanAsString = false; // NaN and Inf are not valid json values, so if WriteNanAsString is set, writer would write string intead of throwing exception (default case)
- };
-
- class TJsonWriter {
- IOutputStream* Out;
- NJsonWriter::TBuf Buf;
+ bool FormatOutput = false;
+ bool SortKeys = false;
+ bool ValidateUtf8 = true;
+ bool DontEscapeStrings = false;
+ bool Unbuffered = false;
+ bool WriteNanAsString = false; // NaN and Inf are not valid json values, so if WriteNanAsString is set, writer would write string intead of throwing exception (default case)
+ };
+
+ class TJsonWriter {
+ IOutputStream* Out;
+ NJsonWriter::TBuf Buf;
const ui32 DoubleNDigits;
const ui32 FloatNDigits;
const EFloatToStringMode FloatToStringMode;
- const bool SortKeys;
- const bool ValidateUtf8;
- const bool DontEscapeStrings;
- const bool DontFlushInDestructor;
-
- public:
- TJsonWriter(IOutputStream* out, bool formatOutput, bool sortkeys = false, bool validateUtf8 = true);
- TJsonWriter(IOutputStream* out, const TJsonWriterConfig& config, bool DontFlushInDestructor = false);
- ~TJsonWriter();
-
- void Flush();
-
- void OpenMap();
- void OpenMap(const TStringBuf& key) {
- Buf.WriteKey(key);
- OpenMap();
- }
- void CloseMap();
-
- void OpenArray();
- void OpenArray(const TStringBuf& key) {
- Buf.WriteKey(key);
- OpenArray();
- }
- void CloseArray();
-
- void WriteNull();
-
- void Write(const TStringBuf& value);
- void Write(float value);
- void Write(double value);
- void Write(bool value);
- void Write(const TJsonValue* value);
+ const bool SortKeys;
+ const bool ValidateUtf8;
+ const bool DontEscapeStrings;
+ const bool DontFlushInDestructor;
+
+ public:
+ TJsonWriter(IOutputStream* out, bool formatOutput, bool sortkeys = false, bool validateUtf8 = true);
+ TJsonWriter(IOutputStream* out, const TJsonWriterConfig& config, bool DontFlushInDestructor = false);
+ ~TJsonWriter();
+
+ void Flush();
+
+ void OpenMap();
+ void OpenMap(const TStringBuf& key) {
+ Buf.WriteKey(key);
+ OpenMap();
+ }
+ void CloseMap();
+
+ void OpenArray();
+ void OpenArray(const TStringBuf& key) {
+ Buf.WriteKey(key);
+ OpenArray();
+ }
+ void CloseArray();
+
+ void WriteNull();
+
+ void Write(const TStringBuf& value);
+ void Write(float value);
+ void Write(double value);
+ void Write(bool value);
+ void Write(const TJsonValue* value);
void Write(const TJsonValue& value);
- // must use all variations of integer types since long
- // and long long are different types but with same size
- void Write(long long value);
- void Write(unsigned long long value);
- void Write(long value) {
- Write((long long)value);
- }
- void Write(unsigned long value) {
- Write((unsigned long long)value);
- }
- void Write(int value) {
- Write((long long)value);
- }
- void Write(unsigned int value) {
- Write((unsigned long long)value);
- }
- void Write(short value) {
- Write((long long)value);
- }
- void Write(unsigned short value) {
- Write((unsigned long long)value);
- }
-
- void Write(const unsigned char* value) {
- Write((const char*)value);
- }
- void Write(const char* value) {
- Write(TStringBuf(value));
- }
- void Write(const TString& value) {
- Write(TStringBuf(value));
- }
- void Write(const std::string& value) {
- Write(TStringBuf(value));
- }
-
- // write raw json without checks
- void UnsafeWrite(const TStringBuf& value) {
- Buf.UnsafeWriteValue(value);
- }
-
- template <typename T>
- void Write(const TStringBuf& key, const T& value) {
- Buf.WriteKey(key);
- Write(value);
- }
-
- // write raw json without checks
- void UnsafeWrite(const TStringBuf& key, const TStringBuf& value) {
- Buf.WriteKey(key);
- UnsafeWrite(value);
- }
-
- void WriteNull(const TStringBuf& key) {
- Buf.WriteKey(key);
- WriteNull();
- }
-
- template <typename T>
- void WriteOptional(const TStringBuf& key, const TMaybe<T>& value) {
- if (value) {
- Write(key, *value);
- }
- }
-
- void WriteOptional(const TStringBuf&, const TNothing&) {
- // nothing to do
+ // must use all variations of integer types since long
+ // and long long are different types but with same size
+ void Write(long long value);
+ void Write(unsigned long long value);
+ void Write(long value) {
+ Write((long long)value);
+ }
+ void Write(unsigned long value) {
+ Write((unsigned long long)value);
+ }
+ void Write(int value) {
+ Write((long long)value);
+ }
+ void Write(unsigned int value) {
+ Write((unsigned long long)value);
+ }
+ void Write(short value) {
+ Write((long long)value);
+ }
+ void Write(unsigned short value) {
+ Write((unsigned long long)value);
+ }
+
+ void Write(const unsigned char* value) {
+ Write((const char*)value);
+ }
+ void Write(const char* value) {
+ Write(TStringBuf(value));
+ }
+ void Write(const TString& value) {
+ Write(TStringBuf(value));
+ }
+ void Write(const std::string& value) {
+ Write(TStringBuf(value));
+ }
+
+ // write raw json without checks
+ void UnsafeWrite(const TStringBuf& value) {
+ Buf.UnsafeWriteValue(value);
+ }
+
+ template <typename T>
+ void Write(const TStringBuf& key, const T& value) {
+ Buf.WriteKey(key);
+ Write(value);
+ }
+
+ // write raw json without checks
+ void UnsafeWrite(const TStringBuf& key, const TStringBuf& value) {
+ Buf.WriteKey(key);
+ UnsafeWrite(value);
+ }
+
+ void WriteNull(const TStringBuf& key) {
+ Buf.WriteKey(key);
+ WriteNull();
+ }
+
+ template <typename T>
+ void WriteOptional(const TStringBuf& key, const TMaybe<T>& value) {
+ if (value) {
+ Write(key, *value);
+ }
+ }
+
+ void WriteOptional(const TStringBuf&, const TNothing&) {
+ // nothing to do
}
void WriteKey(const TStringBuf key) {
@@ -172,25 +172,25 @@ namespace NJson {
WriteKey(TStringBuf{key});
}
- void WriteKey(const std::string& key) {
- WriteKey(TStringBuf{key});
- }
-
- NJsonWriter::TBufState State() const {
- return Buf.State();
- }
+ void WriteKey(const std::string& key) {
+ WriteKey(TStringBuf{key});
+ }
+
+ NJsonWriter::TBufState State() const {
+ return Buf.State();
+ }
- void Reset(const NJsonWriter::TBufState& from) {
- return Buf.Reset(from);
- }
+ void Reset(const NJsonWriter::TBufState& from) {
+ return Buf.Reset(from);
+ }
- void Reset(NJsonWriter::TBufState&& from) {
- return Buf.Reset(std::move(from));
- }
- };
+ void Reset(NJsonWriter::TBufState&& from) {
+ return Buf.Reset(std::move(from));
+ }
+ };
- void WriteJson(IOutputStream*, const TJsonValue*, bool formatOutput = false, bool sortkeys = false, bool validateUtf8 = true);
- TString WriteJson(const TJsonValue*, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
- TString WriteJson(const TJsonValue&, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
- void WriteJson(IOutputStream*, const TJsonValue*, const TJsonWriterConfig& config);
+ void WriteJson(IOutputStream*, const TJsonValue*, bool formatOutput = false, bool sortkeys = false, bool validateUtf8 = true);
+ TString WriteJson(const TJsonValue*, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
+ TString WriteJson(const TJsonValue&, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
+ void WriteJson(IOutputStream*, const TJsonValue*, const TJsonWriterConfig& config);
}