[coding] Added varint short arrays ser/des.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>

# Conflicts:
#	libs/coding/coding_tests/varint_test.cpp
This commit is contained in:
Viktor Govako
2025-07-05 11:19:30 -03:00
committed by Konstantin Pastbin
parent 111e913478
commit 25a4a3b76f
2 changed files with 77 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
#include "coding/varint.hpp"
#include "testing/testing.hpp"
#include "coding/byte_stream.hpp"
#include "coding/reader.hpp"
#include "coding/varint.hpp"
#include "base/macros.hpp"
#include "base/stl_helpers.hpp"
@@ -185,3 +186,29 @@ UNIT_TEST(ReadVarInt64Array)
}
}
}
UNIT_TEST(VarInt_ShortSortedArray)
{
uint32_t constexpr maxVal = (uint32_t(1) << 30) - 1;
std::vector<uint32_t> samples[] = {
{0},
{10, 10000},
{maxVal - 2, maxVal - 1, maxVal},
};
for (auto const & s : samples)
{
std::vector<uint8_t> buffer;
PushBackByteSink sink(buffer);
WriteVarUInt32SortedShortArray(s, sink);
MemReader reader(buffer.data(), buffer.size());
ReaderSource src(reader);
std::vector<uint32_t> actual;
ReadVarUInt32SortedShortArray(src, actual);
TEST_EQUAL(s, actual, ());
}
}