From ec190d8b6f32721869b0f5e7c288d0f46f598edb Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Wed, 25 Apr 2018 17:32:58 +0300 Subject: [PATCH] Added minimal support of KMB v.2 (added server id) --- kml/kml_tests/serdes_tests.cpp | 73 +++++++++++++++++----------------- kml/serdes_binary.hpp | 33 +++++++++++---- kml/types.hpp | 14 ++++--- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/kml/kml_tests/serdes_tests.cpp b/kml/kml_tests/serdes_tests.cpp index b614fc5c14..2e7c9f5a4a 100644 --- a/kml/kml_tests/serdes_tests.cpp +++ b/kml/kml_tests/serdes_tests.cpp @@ -123,42 +123,43 @@ char const * kTextKml = ""; std::vector const kBinKml = { - 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, + 0x02, 0x00, 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 like you see above. diff --git a/kml/serdes_binary.hpp b/kml/serdes_binary.hpp index c0bbbace78..b6801f2b0a 100644 --- a/kml/serdes_binary.hpp +++ b/kml/serdes_binary.hpp @@ -21,7 +21,8 @@ enum class Version : uint8_t { V0 = 0, V1 = 1, // 11th April 2018 (new Point2D storage, added deviceId, feature name -> custom name). - Latest = V1 + V2 = 2, // 25th April 2018 (added serverId). + Latest = V2 }; class SerializerKml @@ -39,9 +40,18 @@ public: WriteToSink(sink, Version::Latest); // Write device id. - auto const sz = static_cast(m_data.m_deviceId.size()); - WriteVarUint(sink, sz); - sink.Write(m_data.m_deviceId.data(), sz); + { + auto const sz = static_cast(m_data.m_deviceId.size()); + WriteVarUint(sink, sz); + sink.Write(m_data.m_deviceId.data(), sz); + } + + // Write server id. + { + auto const sz = static_cast(m_data.m_serverId.size()); + WriteVarUint(sink, sz); + sink.Write(m_data.m_serverId.data(), sz); + } // Write bits count in double number. WriteToSink(sink, kDoubleBits); @@ -127,9 +137,18 @@ public: MYTHROW(DeserializeException, ("Incorrect file version.")); // Read device id. - auto const sz = ReadVarUint(source); - m_data.m_deviceId.resize(sz); - source.Read(&m_data.m_deviceId[0], sz); + { + auto const sz = ReadVarUint(source); + m_data.m_deviceId.resize(sz); + source.Read(&m_data.m_deviceId[0], sz); + } + + // Read server id. + { + auto const sz = ReadVarUint(source); + m_data.m_serverId.resize(sz); + source.Read(&m_data.m_serverId[0], sz); + } // Read bits count in double number. m_doubleBits = ReadPrimitiveFromSource(source); diff --git a/kml/types.hpp b/kml/types.hpp index de6c95ac99..2dd4f23e41 100644 --- a/kml/types.hpp +++ b/kml/types.hpp @@ -130,7 +130,7 @@ struct BookmarkData bool operator!=(BookmarkData const & data) const { return !operator==(data); } - // Unique id. + // Unique id (it will not be serialized in text files). MarkId m_id = kInvalidMarkId; // Bookmark's name. LocalizableString m_name; @@ -195,7 +195,7 @@ struct TrackData bool operator!=(TrackData const & data) const { return !operator==(data); } - // Unique id. + // Unique id (it will not be serialized in text files). TrackId m_id = kInvalidTrackId; // Local track id. LocalId m_localId = 0; @@ -249,7 +249,7 @@ struct CategoryData bool operator!=(CategoryData const & data) const { return !operator==(data); } - // Unique id. + // Unique id (it will not be serialized in text files). MarkGroupId m_id = kInvalidMarkGroupId; // Category's name. LocalizableString m_name; @@ -291,14 +291,16 @@ struct FileData bool operator==(FileData const & data) const { - return m_categoryData == data.m_categoryData && m_bookmarksData == data.m_bookmarksData && - m_tracksData == data.m_tracksData; + return m_serverId == data.m_serverId && m_categoryData == data.m_categoryData && + m_bookmarksData == data.m_bookmarksData && m_tracksData == data.m_tracksData; } bool operator!=(FileData const & data) const { return !operator==(data); } - // Device id. + // Device id (it will not be serialized in text files). std::string m_deviceId; + // Server id. + std::string m_serverId; // Category's data. CategoryData m_categoryData; // Bookmarks collection.