diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/yson/varint.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/yson/varint.cpp')
-rw-r--r-- | library/cpp/yson/varint.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/library/cpp/yson/varint.cpp b/library/cpp/yson/varint.cpp index d538ee3cff..d715d08294 100644 --- a/library/cpp/yson/varint.cpp +++ b/library/cpp/yson/varint.cpp @@ -5,67 +5,67 @@ #include <util/generic/yexception.h> namespace NYson { - //////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// - int WriteVarUInt64(IOutputStream* output, ui64 value) { - bool stop = false; - int bytesWritten = 0; - while (!stop) { - ++bytesWritten; - ui8 byte = static_cast<ui8>(value | 0x80); - value >>= 7; - if (value == 0) { - stop = true; - byte &= 0x7F; - } - output->Write(byte); + int WriteVarUInt64(IOutputStream* output, ui64 value) { + bool stop = false; + int bytesWritten = 0; + while (!stop) { + ++bytesWritten; + ui8 byte = static_cast<ui8>(value | 0x80); + value >>= 7; + if (value == 0) { + stop = true; + byte &= 0x7F; + } + output->Write(byte); } - return bytesWritten; + return bytesWritten; } - int WriteVarInt32(IOutputStream* output, i32 value) { - return WriteVarUInt64(output, static_cast<ui64>(ZigZagEncode32(value))); - } - - int WriteVarInt64(IOutputStream* output, i64 value) { - return WriteVarUInt64(output, static_cast<ui64>(ZigZagEncode64(value))); - } + int WriteVarInt32(IOutputStream* output, i32 value) { + return WriteVarUInt64(output, static_cast<ui64>(ZigZagEncode32(value))); + } - int ReadVarUInt64(IInputStream* input, ui64* value) { - size_t count = 0; - ui64 result = 0; + int WriteVarInt64(IOutputStream* output, i64 value) { + return WriteVarUInt64(output, static_cast<ui64>(ZigZagEncode64(value))); + } - ui8 byte = 0; - do { - if (7 * count > 8 * sizeof(ui64)) { - ythrow yexception() << "The data is too long to read ui64"; - } - if (input->Read(&byte, 1) != 1) { - ythrow yexception() << "The data is too long to read ui64"; - } - result |= (static_cast<ui64>(byte & 0x7F)) << (7 * count); - ++count; - } while (byte & 0x80); + int ReadVarUInt64(IInputStream* input, ui64* value) { + size_t count = 0; + ui64 result = 0; - *value = result; - return count; - } - - int ReadVarInt32(IInputStream* input, i32* value) { - ui64 varInt; - int bytesRead = ReadVarUInt64(input, &varInt); - if (varInt > Max<ui32>()) { + ui8 byte = 0; + do { + if (7 * count > 8 * sizeof(ui64)) { + ythrow yexception() << "The data is too long to read ui64"; + } + if (input->Read(&byte, 1) != 1) { + ythrow yexception() << "The data is too long to read ui64"; + } + result |= (static_cast<ui64>(byte & 0x7F)) << (7 * count); + ++count; + } while (byte & 0x80); + + *value = result; + return count; + } + + int ReadVarInt32(IInputStream* input, i32* value) { + ui64 varInt; + int bytesRead = ReadVarUInt64(input, &varInt); + if (varInt > Max<ui32>()) { ythrow yexception() << "The data is too long to read ui64"; } - *value = ZigZagDecode32(static_cast<ui32>(varInt)); - return bytesRead; - } + *value = ZigZagDecode32(static_cast<ui32>(varInt)); + return bytesRead; + } - int ReadVarInt64(IInputStream* input, i64* value) { - ui64 varInt; - int bytesRead = ReadVarUInt64(input, &varInt); - *value = ZigZagDecode64(varInt); - return bytesRead; + int ReadVarInt64(IInputStream* input, i64* value) { + ui64 varInt; + int bytesRead = ReadVarUInt64(input, &varInt); + *value = ZigZagDecode64(varInt); + return bytesRead; } } // namespace NYson |