Review fixes

This commit is contained in:
r.kuznetsov 2018-04-12 14:35:50 +03:00 committed by mpimenov
parent 84b7202973
commit ab8d95ad28
4 changed files with 94 additions and 86 deletions

View file

@ -123,42 +123,42 @@ char const * kTextKml =
"</kml>";
std::vector<uint8_t> const kBinKml = {
0x01, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x8D, 0xB7, 0xF5, 0x71, 0xFC, 0x8C, 0xFC, 0xC0, 0x02, 0x00, 0x03, 0x01, 0x00, 0x03,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9, 0x01, 0xE3, 0xB9, 0xBB, 0x8E, 0x01, 0xC3, 0xC5, 0xD2,
0xBB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x04, 0x01, 0x00, 0x05, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0xBC, 0xED, 0xA7,
0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x06,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7, 0x02, 0xFD, 0xC1, 0xAC, 0xDB, 0x02, 0x00, 0x03,
0x01, 0x00, 0x07, 0x01, 0x00, 0x08, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0x0E, 0x08, 0x1B, 0x1A, 0x41, 0x0C, 0x11, 0x25, 0x3F, 0x00, 0x02, 0x00, 0x01, 0x08,
0x03, 0x02, 0x06, 0x01, 0x03, 0x06, 0x40, 0x05, 0x07, 0x8D, 0x01, 0x06, 0x05, 0x02, 0x07, 0x07,
0x71, 0x09, 0x05, 0x05, 0x0A, 0x07, 0x12, 0x0B, 0x06, 0x5E, 0x0D, 0x06, 0xBA, 0x01, 0x0E, 0x05,
0x04, 0x0F, 0x05, 0x75, 0x11, 0x05, 0x0D, 0x12, 0x06, 0x09, 0x13, 0x07, 0x4E, 0x15, 0x06, 0x91,
0x01, 0x16, 0x06, 0x0B, 0x17, 0x06, 0x73, 0x19, 0x05, 0x06, 0x1A, 0x08, 0x1C, 0x1B, 0x07, 0x63,
0x1D, 0x06, 0xC0, 0x01, 0x1E, 0x05, 0x07, 0x1F, 0x06, 0x77, 0x21, 0x06, 0x0A, 0x22, 0x07, 0x08,
0x23, 0x07, 0x49, 0x25, 0x07, 0x90, 0x01, 0x27, 0x06, 0x72, 0x2A, 0x08, 0x14, 0x2B, 0x06, 0x62,
0x2D, 0x06, 0xBD, 0x01, 0x32, 0x06, 0x0C, 0x33, 0x06, 0x57, 0x35, 0x07, 0xA1, 0x01, 0x36, 0x06,
0x0F, 0x37, 0x07, 0x76, 0x3A, 0x08, 0x31, 0x3B, 0x06, 0x68, 0x3D, 0x06, 0xD1, 0x01, 0x3F, 0x06,
0x79, 0x41, 0x07, 0xB8, 0x01, 0x45, 0x07, 0x8F, 0x01, 0x47, 0x07, 0x74, 0x4A, 0x07, 0x13, 0x53,
0x07, 0x59, 0x5A, 0x07, 0x29, 0x5B, 0x07, 0x6D, 0x62, 0x08, 0x10, 0x63, 0x07, 0x4B, 0x65, 0x07,
0x96, 0x01, 0x6A, 0x08, 0x18, 0x75, 0x07, 0xB7, 0x01, 0x77, 0x07, 0x8A, 0x01, 0x7A, 0x08, 0x3F,
0x81, 0x01, 0x08, 0x0E, 0x9A, 0x01, 0x08, 0x25, 0xAA, 0x01, 0x08, 0x17, 0xBA, 0x01, 0x08, 0x3E,
0xE2, 0x01, 0x08, 0x11, 0xEA, 0x01, 0x08, 0x19, 0xFA, 0x01, 0x08, 0x41, 0xB0, 0x01, 0xD7, 0x64,
0xD6, 0x6E, 0x37, 0x46, 0x07, 0x3D, 0xA1, 0xA8, 0x65, 0x2F, 0x34, 0x01, 0x83, 0xBE, 0x2E, 0x87,
0x3C, 0x64, 0x71, 0x6E, 0xA3, 0xE7, 0xCC, 0xB7, 0x8E, 0x6D, 0xA7, 0xE2, 0xFD, 0x13, 0xBC, 0x9A,
0x51, 0x7D, 0xF2, 0xE9, 0x17, 0x8F, 0x33, 0x91, 0x28, 0xDB, 0xA1, 0x22, 0x5F, 0xB3, 0x14, 0x65,
0xE9, 0x57, 0x92, 0xAC, 0x33, 0xC5, 0xF8, 0x3E, 0x37, 0x35, 0x00, 0x88, 0x1C, 0x96, 0x62, 0x97,
0x17, 0x09, 0xA5, 0x3F, 0x42, 0x18, 0x98, 0xD5, 0x45, 0x96, 0x1D, 0x0A, 0x46, 0x2C, 0xB9, 0x94,
0xFE, 0x35, 0xF7, 0x00, 0x00, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x1A, 0xD0, 0xA2, 0xD9, 0x95, 0x6B,
0xDC, 0x69, 0xEA, 0x2D, 0x52, 0xB0, 0x43, 0xA8, 0x7C, 0xA9, 0x32, 0x0E, 0x01, 0x00, 0x09,
0x01, 0x00, 0x1E, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3D, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x8D, 0xB7, 0xF5, 0x71, 0xFC, 0x8C, 0xFC, 0xC0, 0x02, 0x00, 0x03, 0x01, 0x00,
0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9, 0x01, 0xE3, 0xB9, 0xBB, 0x8E, 0x01, 0xC3, 0xC5,
0xD2, 0xBB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x04, 0x01, 0x00, 0x05, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0xBC, 0xED,
0xA7, 0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB, 0x02, 0x00, 0x03, 0x01, 0x00,
0x06, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7, 0x02, 0xFD, 0xC1, 0xAC, 0xDB, 0x02, 0x00,
0x03, 0x01, 0x00, 0x07, 0x01, 0x00, 0x08, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0x0E, 0x08, 0x1B, 0x1A, 0x41, 0x0C, 0x11, 0x25, 0x3F, 0x00, 0x02, 0x00, 0x01,
0x08, 0x03, 0x02, 0x06, 0x01, 0x03, 0x06, 0x40, 0x05, 0x07, 0x8D, 0x01, 0x06, 0x05, 0x02, 0x07,
0x07, 0x71, 0x09, 0x05, 0x05, 0x0A, 0x07, 0x12, 0x0B, 0x06, 0x5E, 0x0D, 0x06, 0xBA, 0x01, 0x0E,
0x05, 0x04, 0x0F, 0x05, 0x75, 0x11, 0x05, 0x0D, 0x12, 0x06, 0x09, 0x13, 0x07, 0x4E, 0x15, 0x06,
0x91, 0x01, 0x16, 0x06, 0x0B, 0x17, 0x06, 0x73, 0x19, 0x05, 0x06, 0x1A, 0x08, 0x1C, 0x1B, 0x07,
0x63, 0x1D, 0x06, 0xC0, 0x01, 0x1E, 0x05, 0x07, 0x1F, 0x06, 0x77, 0x21, 0x06, 0x0A, 0x22, 0x07,
0x08, 0x23, 0x07, 0x49, 0x25, 0x07, 0x90, 0x01, 0x27, 0x06, 0x72, 0x2A, 0x08, 0x14, 0x2B, 0x06,
0x62, 0x2D, 0x06, 0xBD, 0x01, 0x32, 0x06, 0x0C, 0x33, 0x06, 0x57, 0x35, 0x07, 0xA1, 0x01, 0x36,
0x06, 0x0F, 0x37, 0x07, 0x76, 0x3A, 0x08, 0x31, 0x3B, 0x06, 0x68, 0x3D, 0x06, 0xD1, 0x01, 0x3F,
0x06, 0x79, 0x41, 0x07, 0xB8, 0x01, 0x45, 0x07, 0x8F, 0x01, 0x47, 0x07, 0x74, 0x4A, 0x07, 0x13,
0x53, 0x07, 0x59, 0x5A, 0x07, 0x29, 0x5B, 0x07, 0x6D, 0x62, 0x08, 0x10, 0x63, 0x07, 0x4B, 0x65,
0x07, 0x96, 0x01, 0x6A, 0x08, 0x18, 0x75, 0x07, 0xB7, 0x01, 0x77, 0x07, 0x8A, 0x01, 0x7A, 0x08,
0x3F, 0x81, 0x01, 0x08, 0x0E, 0x9A, 0x01, 0x08, 0x25, 0xAA, 0x01, 0x08, 0x17, 0xBA, 0x01, 0x08,
0x3E, 0xE2, 0x01, 0x08, 0x11, 0xEA, 0x01, 0x08, 0x19, 0xFA, 0x01, 0x08, 0x41, 0xB0, 0x01, 0xD7,
0x64, 0xD6, 0x6E, 0x37, 0x46, 0x07, 0x3D, 0xA1, 0xA8, 0x65, 0x2F, 0x34, 0x01, 0x83, 0xBE, 0x2E,
0x87, 0x3C, 0x64, 0x71, 0x6E, 0xA3, 0xE7, 0xCC, 0xB7, 0x8E, 0x6D, 0xA7, 0xE2, 0xFD, 0x13, 0xBC,
0x9A, 0x51, 0x7D, 0xF2, 0xE9, 0x17, 0x8F, 0x33, 0x91, 0x28, 0xDB, 0xA1, 0x22, 0x5F, 0xB3, 0x14,
0x65, 0xE9, 0x57, 0x92, 0xAC, 0x33, 0xC5, 0xF8, 0x3E, 0x37, 0x35, 0x00, 0x88, 0x1C, 0x96, 0x62,
0x97, 0x17, 0x09, 0xA5, 0x3F, 0x42, 0x18, 0x98, 0xD5, 0x45, 0x96, 0x1D, 0x0A, 0x46, 0x2C, 0xB9,
0x94, 0xFE, 0x35, 0xF7, 0x00, 0x00, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x1A, 0xD0, 0xA2, 0xD9, 0x95,
0x6B, 0xDC, 0x69, 0xEA, 0x2D, 0x52, 0xB0, 0x43, 0xA8, 0x7C, 0xA9, 0x32, 0x0E, 0x01, 0x00, 0x09,
};
// This function can be used to generate textual representation of vector<uint8_t> like you see above.
@ -491,7 +491,7 @@ UNIT_TEST(Kml_Serialization_Bin_Memory)
// 4. Check deserialization from the text file.
UNIT_TEST(Kml_Deserialization_Text_File)
{
std::string const kmlFile = my::JoinFoldersToPath(GetPlatform().TmpDir(), "tmp.kml");
std::string const kmlFile = my::JoinPath(GetPlatform().TmpDir(), "tmp.kml");
MY_SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, kmlFile));
try
{
@ -528,7 +528,7 @@ UNIT_TEST(Kml_Deserialization_Text_File)
// 5. Check deserialization from the binary file.
UNIT_TEST(Kml_Deserialization_Bin_File)
{
std::string const kmbFile = my::JoinFoldersToPath(GetPlatform().TmpDir(), "tmp.kmb");
std::string const kmbFile = my::JoinPath(GetPlatform().TmpDir(), "tmp.kmb");
MY_SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, kmbFile));
try
{
@ -568,7 +568,7 @@ UNIT_TEST(Kml_Serialization_Bin_File)
{
auto data = GenerateKmlFileData();
std::string const kmbFile = my::JoinFoldersToPath(GetPlatform().TmpDir(), "tmp.kmb");
std::string const kmbFile = my::JoinPath(GetPlatform().TmpDir(), "tmp.kmb");
MY_SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, kmbFile));
try
{
@ -604,7 +604,7 @@ UNIT_TEST(Kml_Serialization_Text_File)
{
auto data = GenerateKmlFileData();
std::string const kmlFile = my::JoinFoldersToPath(GetPlatform().TmpDir(), "tmp.kml");
std::string const kmlFile = my::JoinPath(GetPlatform().TmpDir(), "tmp.kml");
MY_SCOPE_GUARD(fileGuard, std::bind(&FileWriter::DeleteFileX, kmlFile));
try
{

View file

@ -39,10 +39,13 @@ public:
WriteToSink(sink, Version::Latest);
// Write device id.
auto const sz = m_data.m_deviceId.size();
WriteVarUint(sink, static_cast<uint32_t>(sz));
auto const sz = static_cast<uint32_t>(m_data.m_deviceId.size());
WriteVarUint(sink, sz);
sink.Write(m_data.m_deviceId.data(), sz);
// Write bits count in double number.
WriteToSink(sink, kDoubleBits);
auto const startPos = sink.Pos();
// Reserve place for the header.
@ -75,21 +78,21 @@ public:
template <typename Sink>
void SerializeCategory(Sink & sink)
{
CategorySerializerVisitor<Sink> visitor(sink);
CategorySerializerVisitor<Sink> visitor(sink, kDoubleBits);
visitor(m_data.m_categoryData);
}
template <typename Sink>
void SerializeBookmarks(Sink & sink)
{
BookmarkSerializerVisitor<Sink> visitor(sink);
BookmarkSerializerVisitor<Sink> visitor(sink, kDoubleBits);
visitor(m_data.m_bookmarksData);
}
template <typename Sink>
void SerializeTracks(Sink & sink)
{
BookmarkSerializerVisitor<Sink> visitor(sink);
BookmarkSerializerVisitor<Sink> visitor(sink, kDoubleBits);
visitor(m_data.m_tracksData);
}
@ -128,6 +131,11 @@ public:
m_data.m_deviceId.resize(sz);
source.Read(&m_data.m_deviceId[0], sz);
// Read bits count in double number.
m_doubleBits = ReadPrimitiveFromSource<uint8_t>(source);
if (m_doubleBits == 0 || m_doubleBits > 32)
MYTHROW(DeserializeException, ("Incorrect double bits count: ", m_doubleBits));
auto subReader = reader.CreateSubReader(source.Pos(), source.Size());
InitializeIfNeeded(*subReader);
@ -135,7 +143,7 @@ public:
{
auto categorySubReader = CreateCategorySubReader(*subReader);
NonOwningReaderSource src(*categorySubReader);
CategoryDeserializerVisitor<decltype(src)> visitor(src);
CategoryDeserializerVisitor<decltype(src)> visitor(src, m_doubleBits);
visitor(m_data.m_categoryData);
}
@ -143,7 +151,7 @@ public:
{
auto bookmarkSubReader = CreateBookmarkSubReader(*subReader);
NonOwningReaderSource src(*bookmarkSubReader);
BookmarkDeserializerVisitor<decltype(src)> visitor(src);
BookmarkDeserializerVisitor<decltype(src)> visitor(src, m_doubleBits);
visitor(m_data.m_bookmarksData);
}
@ -151,7 +159,7 @@ public:
{
auto trackSubReader = CreateTrackSubReader(*subReader);
NonOwningReaderSource src(*trackSubReader);
BookmarkDeserializerVisitor<decltype(src)> visitor(src);
BookmarkDeserializerVisitor<decltype(src)> visitor(src, m_doubleBits);
visitor(m_data.m_tracksData);
}
@ -216,6 +224,7 @@ private:
FileData & m_data;
Header m_header;
uint8_t m_doubleBits = 0;
bool m_initialized = false;
};
} // namespace binary

View file

@ -74,7 +74,7 @@ double constexpr kMinLineWidth = 0.0;
double constexpr kMaxLineWidth = 100.0;
double constexpr kMinRating = 0.0;
double constexpr kMaxRating = 10.0;
uint32_t constexpr kDoubleBits = 30;
uint8_t constexpr kDoubleBits = 30;
int8_t constexpr kDefaultLangCode = 0;

View file

@ -214,36 +214,39 @@ inline void ReadLocalizableStringIndex(Source & source, LocalizableStringIndex &
}
template <typename Sink>
inline void WritePointU2D(Sink & sink, m2::PointU const & pt)
inline void WritePointU(Sink & sink, m2::PointU const & pt)
{
WriteVarUint(sink, pt.x);
WriteVarUint(sink, pt.y);
}
template <typename Sink>
inline void WritePoint2D(Sink & sink, m2::PointD const & pt)
inline void WritePointD(Sink & sink, m2::PointD const & pt, uint8_t doubleBits)
{
WritePointU2D(sink, PointDToPointU(pt, kDoubleBits));
WritePointU(sink, PointDToPointU(pt, doubleBits));
}
template <typename Source>
inline m2::PointU ReadPointU2D(Source & source)
inline m2::PointU ReadPointU(Source & source)
{
return {ReadVarUint<uint32_t, Source>(source), ReadVarUint<uint32_t, Source>(source)};
auto x = ReadVarUint<uint32_t>(source);
auto y = ReadVarUint<uint32_t>(source);
return {x, y};
}
template <typename Source>
inline m2::PointD ReadPoint2D(Source & source)
inline m2::PointD ReadPointD(Source & source, uint8_t doubleBits)
{
return PointUToPointD(ReadPointU2D(source), kDoubleBits);
return PointUToPointD(ReadPointU(source), doubleBits);
}
template <typename Sink>
class CategorySerializerVisitor
{
public:
explicit CategorySerializerVisitor(Sink & sink)
explicit CategorySerializerVisitor(Sink & sink, uint8_t doubleBits)
: m_sink(sink)
, m_doubleBits(doubleBits)
{}
void operator()(LocalizableStringIndex const & index, char const * /* name */ = nullptr)
@ -268,13 +271,13 @@ public:
void operator()(double d, char const * /* name */ = nullptr)
{
auto const encoded = DoubleToUint32(d, kMinRating, kMaxRating, kDoubleBits);
auto const encoded = DoubleToUint32(d, kMinRating, kMaxRating, m_doubleBits);
WriteVarUint(m_sink, encoded);
}
void operator()(m2::PointD const & pt, char const * /* name */ = nullptr)
{
WritePoint2D(m_sink, pt);
WritePointD(m_sink, pt, m_doubleBits);
}
template <typename T>
@ -309,14 +312,16 @@ public:
private:
Sink & m_sink;
uint8_t const m_doubleBits;
};
template <typename Sink>
class BookmarkSerializerVisitor
{
public:
explicit BookmarkSerializerVisitor(Sink & sink)
explicit BookmarkSerializerVisitor(Sink & sink, uint8_t doubleBits)
: m_sink(sink)
, m_doubleBits(doubleBits)
{}
void operator()(LocalizableStringIndex const & index, char const * /* name */ = nullptr)
@ -331,12 +336,12 @@ public:
void operator()(m2::PointD const & pt, char const * /* name */ = nullptr)
{
WritePoint2D(m_sink, pt);
WritePointD(m_sink, pt, m_doubleBits);
}
void operator()(double d, char const * /* name */ = nullptr)
{
auto const encoded = DoubleToUint32(d, kMinLineWidth, kMaxLineWidth, kDoubleBits);
auto const encoded = DoubleToUint32(d, kMinLineWidth, kMaxLineWidth, m_doubleBits);
WriteVarUint(m_sink, encoded);
}
@ -366,20 +371,12 @@ public:
void operator()(std::vector<m2::PointD> const & points, char const * /* name */ = nullptr)
{
WriteVarUint(m_sink, static_cast<uint32_t>(points.size()));
m2::PointU lastUpt;
m2::PointU lastUpt = m2::PointU::Zero();
for (uint32_t i = 0; i < static_cast<uint32_t>(points.size()); ++i)
{
if (i == 0)
{
lastUpt = PointDToPointU(points[i], kDoubleBits);
WritePointU2D(m_sink, lastUpt);
}
else
{
auto const upt = PointDToPointU(points[i], kDoubleBits);
coding::EncodePointDelta(m_sink, lastUpt, upt);
lastUpt = upt;
}
auto const upt = PointDToPointU(points[i], m_doubleBits);
coding::EncodePointDelta(m_sink, lastUpt, upt);
lastUpt = upt;
}
}
@ -405,14 +402,16 @@ public:
private:
Sink & m_sink;
uint8_t const m_doubleBits;
};
template <typename Source>
class CategoryDeserializerVisitor
{
public:
explicit CategoryDeserializerVisitor(Source & source)
explicit CategoryDeserializerVisitor(Source & source, uint8_t doubleBits)
: m_source(source)
, m_doubleBits(doubleBits)
{}
void operator()(LocalizableStringIndex & index, char const * /* name */ = nullptr)
@ -439,12 +438,12 @@ public:
void operator()(double & d, char const * /* name */ = nullptr)
{
auto const v = ReadVarUint<uint32_t, Source>(m_source);
d = Uint32ToDouble(v, kMinRating, kMaxRating, kDoubleBits);
d = Uint32ToDouble(v, kMinRating, kMaxRating, m_doubleBits);
}
void operator()(m2::PointD & pt, char const * /* name */ = nullptr)
{
pt = ReadPoint2D(m_source);
pt = ReadPointD(m_source, m_doubleBits);
}
template <typename T>
@ -483,14 +482,16 @@ public:
private:
Source & m_source;
uint8_t const m_doubleBits;
};
template <typename Source>
class BookmarkDeserializerVisitor
{
public:
explicit BookmarkDeserializerVisitor(Source & source)
explicit BookmarkDeserializerVisitor(Source & source, uint8_t doubleBits)
: m_source(source)
, m_doubleBits(doubleBits)
{}
void operator()(LocalizableStringIndex & index, char const * /* name */ = nullptr)
@ -505,13 +506,13 @@ public:
void operator()(m2::PointD & pt, char const * /* name */ = nullptr)
{
pt = ReadPoint2D(m_source);
pt = ReadPointD(m_source, m_doubleBits);
}
void operator()(double & d, char const * /* name */ = nullptr)
{
auto const v = ReadVarUint<uint32_t, Source>(m_source);
d = Uint32ToDouble(v, kMinLineWidth, kMaxLineWidth, kDoubleBits);
d = Uint32ToDouble(v, kMinLineWidth, kMaxLineWidth, m_doubleBits);
}
void operator()(Timestamp & t, char const * /* name */ = nullptr)
@ -551,14 +552,11 @@ public:
{
auto const sz = ReadVarUint<uint32_t, Source>(m_source);
points.reserve(sz);
m2::PointU lastUpt;
m2::PointU lastUpt = m2::PointU::Zero();
for (uint32_t i = 0; i < sz; ++i)
{
if (i == 0)
lastUpt = ReadPointU2D(m_source);
else
lastUpt = coding::DecodePointDelta(m_source, lastUpt);
points.emplace_back(PointUToPointD(lastUpt, kDoubleBits));
lastUpt = coding::DecodePointDelta(m_source, lastUpt);
points.emplace_back(PointUToPointD(lastUpt, m_doubleBits));
}
}
@ -584,6 +582,7 @@ public:
private:
Source & m_source;
uint8_t const m_doubleBits;
};
template <typename Reader>