blob: 4ae4bb7ae84e7d5f2998da4ae66cf6eb725ee509 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "routing/cross_mwm_connector_serialization.hpp"
#include "base/bits.hpp"
using namespace std;
namespace routing
{
// static
uint32_t constexpr CrossMwmConnectorSerializer::kLastVersion;
// static
void CrossMwmConnectorSerializer::WriteWeights(vector<Weight> const & weights,
vector<uint8_t> & buffer)
{
MemWriter<vector<uint8_t>> memWriter(buffer);
BitWriter<MemWriter<vector<uint8_t>>> writer(memWriter);
connector::Weight prevWeight = 1;
for (auto const weight : weights)
{
if (weight == connector::kNoRoute)
{
writer.Write(kNoRouteBit, 1);
continue;
}
writer.Write(kRouteBit, 1);
auto const storedWeight = (weight + kGranularity - 1) / kGranularity;
WriteDelta(writer, EncodeZigZagDelta(prevWeight, storedWeight) + 1);
prevWeight = storedWeight;
}
}
} // namespace routing
|