diff options
author | qkrorlqr <qkrorlqr@yandex-team.ru> | 2022-02-10 16:47:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:21 +0300 |
commit | eec632e483ae34bc211138c67434b1e0e6054ced (patch) | |
tree | 9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/json/rapidjson_helpers.h | |
parent | 9b89266638b10d40309e31dcb7caa2fc52b2aefd (diff) | |
download | ydb-eec632e483ae34bc211138c67434b1e0e6054ced.tar.gz |
Restoring authorship annotation for <qkrorlqr@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json/rapidjson_helpers.h')
-rw-r--r-- | library/cpp/json/rapidjson_helpers.h | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/library/cpp/json/rapidjson_helpers.h b/library/cpp/json/rapidjson_helpers.h index 314623425e..aeb96ff670 100644 --- a/library/cpp/json/rapidjson_helpers.h +++ b/library/cpp/json/rapidjson_helpers.h @@ -1,104 +1,104 @@ -#pragma once - -#include <util/generic/strbuf.h> -#include <util/stream/input.h> - -namespace NJson { - struct TReadOnlyStreamBase { - using Ch = char; - - Ch* PutBegin() { - Y_ASSERT(false); - return nullptr; - } - - void Put(Ch) { - Y_ASSERT(false); - } - - void Flush() { - Y_ASSERT(false); - } - - size_t PutEnd(Ch*) { - Y_ASSERT(false); - return 0; - } - }; - +#pragma once + +#include <util/generic/strbuf.h> +#include <util/stream/input.h> + +namespace NJson { + struct TReadOnlyStreamBase { + using Ch = char; + + Ch* PutBegin() { + Y_ASSERT(false); + return nullptr; + } + + void Put(Ch) { + Y_ASSERT(false); + } + + void Flush() { + Y_ASSERT(false); + } + + size_t PutEnd(Ch*) { + Y_ASSERT(false); + return 0; + } + }; + struct TInputStreamWrapper : TReadOnlyStreamBase { - Ch Peek() const { - if (!Eof) { - if (Pos >= Sz) { - if (Sz < BUF_SIZE) { - Sz += Helper.Read(Buf + Sz, BUF_SIZE - Sz); - } else { - Sz = Helper.Read(Buf, BUF_SIZE); - Pos = 0; - } - } - - if (Pos < Sz) { - return Buf[Pos]; - } - } - - Eof = true; - return 0; - } - - Ch Take() { - auto c = Peek(); - ++Pos; - ++Count; - return c; - } - - size_t Tell() const { - return Count; - } - + Ch Peek() const { + if (!Eof) { + if (Pos >= Sz) { + if (Sz < BUF_SIZE) { + Sz += Helper.Read(Buf + Sz, BUF_SIZE - Sz); + } else { + Sz = Helper.Read(Buf, BUF_SIZE); + Pos = 0; + } + } + + if (Pos < Sz) { + return Buf[Pos]; + } + } + + Eof = true; + return 0; + } + + Ch Take() { + auto c = Peek(); + ++Pos; + ++Count; + return c; + } + + size_t Tell() const { + return Count; + } + TInputStreamWrapper(IInputStream& helper) - : Helper(helper) - , Eof(false) - , Sz(0) - , Pos(0) - , Count(0) - { - } - - static const size_t BUF_SIZE = 1 << 12; - + : Helper(helper) + , Eof(false) + , Sz(0) + , Pos(0) + , Count(0) + { + } + + static const size_t BUF_SIZE = 1 << 12; + IInputStream& Helper; - mutable char Buf[BUF_SIZE]; - mutable bool Eof; - mutable size_t Sz; - mutable size_t Pos; - size_t Count; - }; - + mutable char Buf[BUF_SIZE]; + mutable bool Eof; + mutable size_t Sz; + mutable size_t Pos; + size_t Count; + }; + struct TStringBufStreamWrapper : TReadOnlyStreamBase { - Ch Peek() const { + Ch Peek() const { return Pos < Data.size() ? Data[Pos] : 0; - } - - Ch Take() { - auto c = Peek(); - ++Pos; - return c; - } - - size_t Tell() const { - return Pos; - } - - TStringBufStreamWrapper(TStringBuf data) - : Data(data) - , Pos(0) - { - } - - TStringBuf Data; - size_t Pos; - }; -} + } + + Ch Take() { + auto c = Peek(); + ++Pos; + return c; + } + + size_t Tell() const { + return Pos; + } + + TStringBufStreamWrapper(TStringBuf data) + : Data(data) + , Pos(0) + { + } + + TStringBuf Data; + size_t Pos; + }; +} |