aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json/flex_buffers
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/json/flex_buffers
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json/flex_buffers')
-rw-r--r--library/cpp/json/flex_buffers/cvt.cpp236
-rw-r--r--library/cpp/json/flex_buffers/cvt.h40
-rw-r--r--library/cpp/json/flex_buffers/ut/cvt_ut.cpp38
-rw-r--r--library/cpp/json/flex_buffers/ut/ya.make16
-rw-r--r--library/cpp/json/flex_buffers/ya.make28
5 files changed, 179 insertions, 179 deletions
diff --git a/library/cpp/json/flex_buffers/cvt.cpp b/library/cpp/json/flex_buffers/cvt.cpp
index 9f7d630373..fee0cea0b8 100644
--- a/library/cpp/json/flex_buffers/cvt.cpp
+++ b/library/cpp/json/flex_buffers/cvt.cpp
@@ -1,139 +1,139 @@
-#include "cvt.h"
-
-#include <flatbuffers/flexbuffers.h>
-
+#include "cvt.h"
+
+#include <flatbuffers/flexbuffers.h>
+
#include <library/cpp/json/fast_sax/parser.h>
#include <library/cpp/json/json_reader.h>
-
-#include <util/generic/vector.h>
-#include <util/stream/output.h>
-#include <util/stream/input.h>
-#include <util/memory/pool.h>
-
-using namespace NJson;
-
-namespace {
- struct TJsonToFlexCallbacks: public TJsonCallbacks {
- inline TJsonToFlexCallbacks()
- : P(8192)
- {
- }
-
+
+#include <util/generic/vector.h>
+#include <util/stream/output.h>
+#include <util/stream/input.h>
+#include <util/memory/pool.h>
+
+using namespace NJson;
+
+namespace {
+ struct TJsonToFlexCallbacks: public TJsonCallbacks {
+ inline TJsonToFlexCallbacks()
+ : P(8192)
+ {
+ }
+
bool OnNull() override {
- B.Null();
-
- return true;
- }
-
+ B.Null();
+
+ return true;
+ }
+
bool OnBoolean(bool v) override {
- B.Bool(v);
-
- return true;
- }
-
+ B.Bool(v);
+
+ return true;
+ }
+
bool OnInteger(long long v) override {
- B.Int(v);
-
- return true;
- }
-
+ B.Int(v);
+
+ return true;
+ }
+
bool OnUInteger(unsigned long long v) override {
- B.UInt(v);
-
- return true;
- }
-
+ B.UInt(v);
+
+ return true;
+ }
+
bool OnDouble(double v) override {
- B.Double(v);
-
- return true;
- }
-
+ B.Double(v);
+
+ return true;
+ }
+
bool OnString(const TStringBuf& v) override {
B.String(v.data(), v.size());
-
- return true;
- }
-
+
+ return true;
+ }
+
bool OnOpenMap() override {
- S.push_back(B.StartMap());
-
- return true;
- }
-
+ S.push_back(B.StartMap());
+
+ return true;
+ }
+
bool OnMapKey(const TStringBuf& v) override {
auto iv = P.AppendCString(v);
-
+
B.Key(iv.data(), iv.size());
-
- return true;
- }
-
+
+ return true;
+ }
+
bool OnCloseMap() override {
- B.EndMap(PopOffset());
-
- return true;
- }
-
+ B.EndMap(PopOffset());
+
+ return true;
+ }
+
bool OnOpenArray() override {
- S.push_back(B.StartVector());
-
- return true;
- }
-
+ S.push_back(B.StartVector());
+
+ return true;
+ }
+
bool OnCloseArray() override {
- B.EndVector(PopOffset(), false, false);
-
- return true;
- }
-
+ B.EndVector(PopOffset(), false, false);
+
+ return true;
+ }
+
bool OnStringNoCopy(const TStringBuf& s) override {
- return OnString(s);
- }
-
+ return OnString(s);
+ }
+
bool OnMapKeyNoCopy(const TStringBuf& s) override {
- return OnMapKey(s);
- }
-
+ return OnMapKey(s);
+ }
+
bool OnEnd() override {
- B.Finish();
-
- Y_ENSURE(S.empty());
-
- return true;
- }
-
+ B.Finish();
+
+ Y_ENSURE(S.empty());
+
+ return true;
+ }
+
void OnError(size_t, TStringBuf reason) override {
- ythrow yexception() << reason;
- }
-
- inline size_t PopOffset() {
- auto res = S.back();
-
- S.pop_back();
-
- return res;
- }
-
- inline auto& Buffer() {
- return B.GetBuffer();
- }
-
- flexbuffers::Builder B;
- TVector<size_t> S;
- TMemoryPool P;
- };
-}
-
-void NJson::ConvertJsonToFlexBuffers(TStringBuf input, TFlexBuffersData& result) {
- TJsonToFlexCallbacks cb;
-
- ReadJsonFast(input, &cb);
- result.swap(const_cast<std::vector<ui8>&>(cb.Buffer()));
-}
-
-TString NJson::FlexToString(const TFlexBuffersData& v) {
+ ythrow yexception() << reason;
+ }
+
+ inline size_t PopOffset() {
+ auto res = S.back();
+
+ S.pop_back();
+
+ return res;
+ }
+
+ inline auto& Buffer() {
+ return B.GetBuffer();
+ }
+
+ flexbuffers::Builder B;
+ TVector<size_t> S;
+ TMemoryPool P;
+ };
+}
+
+void NJson::ConvertJsonToFlexBuffers(TStringBuf input, TFlexBuffersData& result) {
+ TJsonToFlexCallbacks cb;
+
+ ReadJsonFast(input, &cb);
+ result.swap(const_cast<std::vector<ui8>&>(cb.Buffer()));
+}
+
+TString NJson::FlexToString(const TFlexBuffersData& v) {
auto root = flexbuffers::GetRoot(v.data(), v.size());
-
- return TString(root.ToString());
-}
+
+ return TString(root.ToString());
+}
diff --git a/library/cpp/json/flex_buffers/cvt.h b/library/cpp/json/flex_buffers/cvt.h
index 489f2dad83..82d2874268 100644
--- a/library/cpp/json/flex_buffers/cvt.h
+++ b/library/cpp/json/flex_buffers/cvt.h
@@ -1,20 +1,20 @@
-#pragma once
-
-#include <util/generic/vector.h>
-#include <util/generic/strbuf.h>
-#include <util/generic/string.h>
-
-namespace NJson {
- using TFlexBuffersData = TVector<ui8>;
-
- TString FlexToString(const TFlexBuffersData& v);
- void ConvertJsonToFlexBuffers(TStringBuf input, TFlexBuffersData& result);
-
- inline TFlexBuffersData ConvertJsonToFlexBuffers(TStringBuf input) {
- TFlexBuffersData result;
-
- ConvertJsonToFlexBuffers(input, result);
-
- return result;
- }
-}
+#pragma once
+
+#include <util/generic/vector.h>
+#include <util/generic/strbuf.h>
+#include <util/generic/string.h>
+
+namespace NJson {
+ using TFlexBuffersData = TVector<ui8>;
+
+ TString FlexToString(const TFlexBuffersData& v);
+ void ConvertJsonToFlexBuffers(TStringBuf input, TFlexBuffersData& result);
+
+ inline TFlexBuffersData ConvertJsonToFlexBuffers(TStringBuf input) {
+ TFlexBuffersData result;
+
+ ConvertJsonToFlexBuffers(input, result);
+
+ return result;
+ }
+}
diff --git a/library/cpp/json/flex_buffers/ut/cvt_ut.cpp b/library/cpp/json/flex_buffers/ut/cvt_ut.cpp
index de3eb0d520..9fffef4d38 100644
--- a/library/cpp/json/flex_buffers/ut/cvt_ut.cpp
+++ b/library/cpp/json/flex_buffers/ut/cvt_ut.cpp
@@ -1,21 +1,21 @@
#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/json/flex_buffers/cvt.h>
-
-using namespace NJson;
-
-static auto JSON = R"({
- "a": {
- "b": [1, 2, 3],
- "c": ["x", "y", 3, "z"]
- }
-})";
-
-static auto RES = R"({ a: { b: [ 1, 2, 3 ], c: [ "x", "y", 3, "z" ] } })";
-
-Y_UNIT_TEST_SUITE(JsonToFlex) {
- Y_UNIT_TEST(Test1) {
- auto buf = ConvertJsonToFlexBuffers(JSON);
-
- UNIT_ASSERT_VALUES_EQUAL(FlexToString(buf), RES);
- }
-}
+
+using namespace NJson;
+
+static auto JSON = R"({
+ "a": {
+ "b": [1, 2, 3],
+ "c": ["x", "y", 3, "z"]
+ }
+})";
+
+static auto RES = R"({ a: { b: [ 1, 2, 3 ], c: [ "x", "y", 3, "z" ] } })";
+
+Y_UNIT_TEST_SUITE(JsonToFlex) {
+ Y_UNIT_TEST(Test1) {
+ auto buf = ConvertJsonToFlexBuffers(JSON);
+
+ UNIT_ASSERT_VALUES_EQUAL(FlexToString(buf), RES);
+ }
+}
diff --git a/library/cpp/json/flex_buffers/ut/ya.make b/library/cpp/json/flex_buffers/ut/ya.make
index 148ac13856..3fdc93f88e 100644
--- a/library/cpp/json/flex_buffers/ut/ya.make
+++ b/library/cpp/json/flex_buffers/ut/ya.make
@@ -1,9 +1,9 @@
UNITTEST_FOR(library/cpp/json/flex_buffers)
-
-OWNER(pg)
-
-SRCS(
- cvt_ut.cpp
-)
-
-END()
+
+OWNER(pg)
+
+SRCS(
+ cvt_ut.cpp
+)
+
+END()
diff --git a/library/cpp/json/flex_buffers/ya.make b/library/cpp/json/flex_buffers/ya.make
index 1b38b2f3d1..3ece5e3703 100644
--- a/library/cpp/json/flex_buffers/ya.make
+++ b/library/cpp/json/flex_buffers/ya.make
@@ -1,16 +1,16 @@
-LIBRARY()
-
-OWNER(pg)
-
+LIBRARY()
+
+OWNER(pg)
+
ADDINCL(contrib/libs/flatbuffers/include)
-
-PEERDIR(
+
+PEERDIR(
library/cpp/json
- contrib/libs/flatbuffers
-)
-
-SRCS(
- cvt.cpp
-)
-
-END()
+ contrib/libs/flatbuffers
+)
+
+SRCS(
+ cvt.cpp
+)
+
+END()