MCPcopy Create free account
hub / github.com/comaps/comaps / SerializeDataPointsV1

Method SerializeDataPointsV1

libs/coding/traffic.hpp:117–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115
116 template <typename Writer, typename Collection>
117 static size_t SerializeDataPointsV1(Writer & writer, Collection const & points)
118 {
119 auto const startPos = writer.Pos();
120
121 if (!points.empty())
122 {
123 uint64_t const firstTimestamp = points[0].m_timestamp;
124 uint32_t const firstLat =
125 DoubleToUint32(points[0].m_latLon.m_lat, ms::LatLon::kMinLat, ms::LatLon::kMaxLat, kCoordBits);
126 uint32_t const firstLon =
127 DoubleToUint32(points[0].m_latLon.m_lon, ms::LatLon::kMinLon, ms::LatLon::kMaxLon, kCoordBits);
128 uint32_t const traffic = points[0].m_traffic;
129 WriteVarUint(writer, firstTimestamp);
130 WriteVarUint(writer, firstLat);
131 WriteVarUint(writer, firstLon);
132 WriteVarUint(writer, traffic);
133 }
134
135 for (size_t i = 1; i < points.size(); ++i)
136 {
137 ASSERT_LESS_OR_EQUAL(points[i - 1].m_timestamp, points[i].m_timestamp, ());
138
139 uint64_t const deltaTimestamp = points[i].m_timestamp - points[i - 1].m_timestamp;
140 uint32_t deltaLat = DoubleToUint32(points[i].m_latLon.m_lat - points[i - 1].m_latLon.m_lat, kMinDeltaLat,
141 kMaxDeltaLat, kCoordBits);
142 uint32_t deltaLon = DoubleToUint32(points[i].m_latLon.m_lon - points[i - 1].m_latLon.m_lon, kMinDeltaLon,
143 kMaxDeltaLon, kCoordBits);
144
145 uint32_t const traffic = points[i - 1].m_traffic;
146 WriteVarUint(writer, deltaTimestamp);
147 WriteVarUint(writer, deltaLat);
148 WriteVarUint(writer, deltaLon);
149 WriteVarUint(writer, traffic);
150 }
151
152 ASSERT_LESS_OR_EQUAL(writer.Pos() - startPos, std::numeric_limits<size_t>::max(), ("Too much data."));
153 return static_cast<size_t>(writer.Pos() - startPos);
154 }
155
156 template <typename Source, typename Collection>
157 static void DeserializeDataPointsV0(Source & src, Collection & result)

Callers

nothing calls this directly

Calls 5

DoubleToUint32Function · 0.85
WriteVarUintFunction · 0.85
PosMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected