Files
comaps/indexer/complex/serdes_utils.hpp
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

35 lines
1.0 KiB
C++

#pragma once
#include "coding/reader.hpp"
#include "coding/varint.hpp"
#include "base/assert.hpp"
#include "base/checked_cast.hpp"
namespace coding_utils
{
// Type of collection size. Used for reading and writing collections.
using CollectionSizeType = uint64_t;
// WriteCollectionPrimitive writes collection. It uses WriteToSink function.
template <typename Sink, typename Cont>
void WriteCollectionPrimitive(Sink & sink, Cont const & container)
{
auto const contSize = base::checked_cast<CollectionSizeType>(container.size());
WriteVarUint(sink, contSize);
for (auto value : container)
WriteToSink(sink, value);
}
// ReadCollectionPrimitive reads collection. It uses ReadPrimitiveFromSource function.
template <typename Source, typename OutIt>
void ReadCollectionPrimitive(Source & src, OutIt it)
{
using ValueType = typename OutIt::container_type::value_type;
auto size = ReadVarUint<CollectionSizeType>(src);
while (size--)
*it++ = ReadPrimitiveFromSource<ValueType>(src);
}
} // namespace coding_utils