aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/coding/varint-inl.h
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.ru>2022-02-10 16:49:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:19 +0300
commitf31097c96270919a1f49360bdaaa69ea4f3fefab (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/yt/coding/varint-inl.h
parentcec37806d8847aa3db53bafc9e251d4aaf325c12 (diff)
downloadydb-f31097c96270919a1f49360bdaaa69ea4f3fefab.tar.gz
Restoring authorship annotation for <babenko@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/yt/coding/varint-inl.h')
-rw-r--r--library/cpp/yt/coding/varint-inl.h322
1 files changed, 161 insertions, 161 deletions
diff --git a/library/cpp/yt/coding/varint-inl.h b/library/cpp/yt/coding/varint-inl.h
index c70b737af3..f0a09e9d30 100644
--- a/library/cpp/yt/coding/varint-inl.h
+++ b/library/cpp/yt/coding/varint-inl.h
@@ -4,146 +4,146 @@
#include "varint.h"
#endif
-#include "zig_zag.h"
-
-namespace NYT {
-
-////////////////////////////////////////////////////////////////////////////////
-
-template <class TWriteCallback>
+#include "zig_zag.h"
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TWriteCallback>
Y_FORCE_INLINE int WriteVarUint64Impl(TWriteCallback doWrite, ui64 value)
-{
- bool stop = false;
- int bytesWritten = 0;
- while (!stop) {
- ++bytesWritten;
+{
+ 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;
- }
- doWrite(byte);
- }
- return bytesWritten;
-}
-
-// These are optimized versions of these Read/Write functions in protobuf/io/coded_stream.cc.
+ value >>= 7;
+ if (value == 0) {
+ stop = true;
+ byte &= 0x7F;
+ }
+ doWrite(byte);
+ }
+ return bytesWritten;
+}
+
+// These are optimized versions of these Read/Write functions in protobuf/io/coded_stream.cc.
Y_FORCE_INLINE int WriteVarUint64(IOutputStream* output, ui64 value)
-{
+{
return WriteVarUint64Impl([&] (ui8 byte) {
- output->Write(byte);
- }, value);
-}
-
+ output->Write(byte);
+ }, value);
+}
+
Y_FORCE_INLINE int WriteVarUint64(char* output, ui64 value)
-{
+{
return WriteVarUint64Impl([&] (ui8 byte) {
*output++ = byte;
- }, value);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-template <class TOutput>
+ }, value);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TOutput>
Y_FORCE_INLINE int WriteVarUint32Impl(TOutput output, ui32 value)
-{
+{
return WriteVarUint64(output, static_cast<ui64>(value));
-}
-
+}
+
Y_FORCE_INLINE int WriteVarUint32(IOutputStream* output, ui32 value)
-{
+{
return WriteVarUint32Impl(output, value);
-}
-
+}
+
Y_FORCE_INLINE int WriteVarUint32(char* output, ui32 value)
-{
+{
return WriteVarUint32Impl(output, value);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-template <class TOutput>
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TOutput>
Y_FORCE_INLINE int WriteVarInt32Impl(TOutput output, i32 value)
-{
+{
return WriteVarUint64(output, static_cast<ui64>(ZigZagEncode32(value)));
-}
-
+}
+
Y_FORCE_INLINE int WriteVarInt32(IOutputStream* output, i32 value)
-{
- return WriteVarInt32Impl(output, value);
-}
-
+{
+ return WriteVarInt32Impl(output, value);
+}
+
Y_FORCE_INLINE int WriteVarInt32(char* output, i32 value)
-{
- return WriteVarInt32Impl(output, value);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-template <class TOutput>
+{
+ return WriteVarInt32Impl(output, value);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TOutput>
Y_FORCE_INLINE int WriteVarInt64Impl(TOutput output, i64 value)
-{
+{
return WriteVarUint64(output, static_cast<ui64>(ZigZagEncode64(value)));
-}
-
+}
+
Y_FORCE_INLINE int WriteVarInt64(IOutputStream* output, i64 value)
-{
- return WriteVarInt64Impl(output, value);
-}
-
+{
+ return WriteVarInt64Impl(output, value);
+}
+
Y_FORCE_INLINE int WriteVarInt64(char* output, i64 value)
-{
- return WriteVarInt64Impl(output, value);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-template <class TReadCallback>
+{
+ return WriteVarInt64Impl(output, value);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TReadCallback>
Y_FORCE_INLINE int ReadVarUint64Impl(TReadCallback doRead, ui64* value)
-{
- size_t count = 0;
- ui64 result = 0;
-
- ui8 byte;
- do {
- if (7 * count > 8 * sizeof(ui64) ) {
- throw TSimpleException("Value is too big for varuint64");
- }
- byte = doRead();
- result |= (static_cast<ui64> (byte & 0x7F)) << (7 * count);
- ++count;
- } while (byte & 0x80);
-
- *value = result;
- return count;
-}
-
+{
+ size_t count = 0;
+ ui64 result = 0;
+
+ ui8 byte;
+ do {
+ if (7 * count > 8 * sizeof(ui64) ) {
+ throw TSimpleException("Value is too big for varuint64");
+ }
+ byte = doRead();
+ result |= (static_cast<ui64> (byte & 0x7F)) << (7 * count);
+ ++count;
+ } while (byte & 0x80);
+
+ *value = result;
+ return count;
+}
+
Y_FORCE_INLINE int ReadVarUint64(IInputStream* input, ui64* value)
-{
+{
return ReadVarUint64Impl([&] () {
- char byte;
- if (input->Read(&byte, 1) != 1) {
- throw TSimpleException("Premature end of stream while reading varuint64");
- }
- return byte;
- }, value);
-}
-
+ char byte;
+ if (input->Read(&byte, 1) != 1) {
+ throw TSimpleException("Premature end of stream while reading varuint64");
+ }
+ return byte;
+ }, value);
+}
+
Y_FORCE_INLINE int ReadVarUint64(const char* input, ui64* value)
-{
+{
return ReadVarUint64Impl([&] () {
- char byte = *input;
- ++input;
- return byte;
- }, value);
-}
-
+ char byte = *input;
+ ++input;
+ return byte;
+ }, value);
+}
+
Y_FORCE_INLINE int ReadVarUint64(const char* input, const char* end, ui64* value)
{
return ReadVarUint64Impl([&] () {
if (input == end) {
- throw TSimpleException("Premature end of data while reading varuint64");
+ throw TSimpleException("Premature end of data while reading varuint64");
}
char byte = *input;
++input;
@@ -151,90 +151,90 @@ Y_FORCE_INLINE int ReadVarUint64(const char* input, const char* end, ui64* value
}, value);
}
-////////////////////////////////////////////////////////////////////////////////
-
+////////////////////////////////////////////////////////////////////////////////
+
template <class... Args>
Y_FORCE_INLINE int ReadVarUint32Impl(ui32* value, Args... args)
-{
- ui64 varInt;
+{
+ ui64 varInt;
int bytesRead = ReadVarUint64(args..., &varInt);
- if (varInt > std::numeric_limits<ui32>::max()) {
- throw TSimpleException("Value is too big for varuint32");
- }
- *value = static_cast<ui32>(varInt);
- return bytesRead;
-}
-
+ if (varInt > std::numeric_limits<ui32>::max()) {
+ throw TSimpleException("Value is too big for varuint32");
+ }
+ *value = static_cast<ui32>(varInt);
+ return bytesRead;
+}
+
Y_FORCE_INLINE int ReadVarUint32(IInputStream* input, ui32* value)
-{
+{
return ReadVarUint32Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarUint32(const char* input, ui32* value)
-{
+{
return ReadVarUint32Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarUint32(const char* input, const char* end, ui32* value)
{
return ReadVarUint32Impl(value, input, end);
}
-////////////////////////////////////////////////////////////////////////////////
-
+////////////////////////////////////////////////////////////////////////////////
+
template <class... Args>
Y_FORCE_INLINE int ReadVarInt32Impl(i32* value, Args... args)
-{
- ui64 varInt;
+{
+ ui64 varInt;
int bytesRead = ReadVarUint64(args..., &varInt);
- if (varInt > std::numeric_limits<ui32>::max()) {
- throw TSimpleException("Value is too big for varint32");
- }
- *value = ZigZagDecode32(static_cast<ui32>(varInt));
- return bytesRead;
-}
-
+ if (varInt > std::numeric_limits<ui32>::max()) {
+ throw TSimpleException("Value is too big for varint32");
+ }
+ *value = ZigZagDecode32(static_cast<ui32>(varInt));
+ return bytesRead;
+}
+
Y_FORCE_INLINE int ReadVarInt32(IInputStream* input, i32* value)
-{
+{
return ReadVarInt32Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarInt32(const char* input, i32* value)
-{
+{
return ReadVarInt32Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarInt32(const char* input, const char* end, i32* value)
{
return ReadVarInt32Impl(value, input, end);
}
-////////////////////////////////////////////////////////////////////////////////
-
+////////////////////////////////////////////////////////////////////////////////
+
template <class... Args>
Y_FORCE_INLINE int ReadVarInt64Impl(i64* value, Args... args)
-{
- ui64 varInt;
+{
+ ui64 varInt;
int bytesRead = ReadVarUint64(args..., &varInt);
- *value = ZigZagDecode64(varInt);
- return bytesRead;
-}
-
+ *value = ZigZagDecode64(varInt);
+ return bytesRead;
+}
+
Y_FORCE_INLINE int ReadVarInt64(IInputStream* input, i64* value)
-{
+{
return ReadVarInt64Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarInt64(const char* input, i64* value)
-{
+{
return ReadVarInt64Impl(value, input);
-}
-
+}
+
Y_FORCE_INLINE int ReadVarInt64(const char* input, const char* end, i64* value)
{
return ReadVarInt64Impl(value, input, end);
}
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace NYT
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT