diff options
author | Sergey Yershov <syershov@maps.me> | 2017-03-06 17:58:42 +0300 |
---|---|---|
committer | Sergey Yershov <syershov@maps.me> | 2017-03-20 11:34:39 +0300 |
commit | 6c57ac53cdb7bc9ac4ea350f4b0c1099b06ddb96 (patch) | |
tree | 86120db4912e779a50aadef28fa9103392a4ceb3 /tracking/protocol.cpp | |
parent | 366574678dd0b4a8d84c40beb30f6b698589348b (diff) |
New serializer for traffic data
Diffstat (limited to 'tracking/protocol.cpp')
-rw-r--r-- | tracking/protocol.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/tracking/protocol.cpp b/tracking/protocol.cpp index 8a2fa90374..3d97400a87 100644 --- a/tracking/protocol.cpp +++ b/tracking/protocol.cpp @@ -12,15 +12,23 @@ namespace { template <typename Container> -vector<uint8_t> CreateDataPacketImpl(Container const & points) +vector<uint8_t> CreateDataPacketImpl(Container const & points, + tracking::Protocol::PacketType const type) { vector<uint8_t> buffer; MemWriter<decltype(buffer)> writer(buffer); - tracking::Protocol::Encoder::SerializeDataPoints(tracking::Protocol::Encoder::kLatestVersion, - writer, points); - auto packet = tracking::Protocol::CreateHeader(tracking::Protocol::PacketType::CurrentData, - static_cast<uint32_t>(buffer.size())); + uint32_t serializer_version = tracking::Protocol::Encoder::kLatestVersion; + switch (type) + { + case tracking::Protocol::PacketType::DataV0: serializer_version = 0; break; + case tracking::Protocol::PacketType::DataV1: serializer_version = 1; break; + case tracking::Protocol::PacketType::AuthV0: ASSERT(false, ("Not a DATA type.")); break; + } + + tracking::Protocol::Encoder::SerializeDataPoints(serializer_version, writer, points); + + auto packet = tracking::Protocol::CreateHeader(type, static_cast<uint32_t>(buffer.size())); packet.insert(packet.end(), begin(buffer), end(buffer)); return packet; @@ -54,15 +62,15 @@ vector<uint8_t> Protocol::CreateAuthPacket(string const & clientId) } // static -vector<uint8_t> Protocol::CreateDataPacket(DataElementsCirc const & points) +vector<uint8_t> Protocol::CreateDataPacket(DataElementsCirc const & points, PacketType type) { - return CreateDataPacketImpl(points); + return CreateDataPacketImpl(points, type); } // static -vector<uint8_t> Protocol::CreateDataPacket(DataElementsVec const & points) +vector<uint8_t> Protocol::CreateDataPacket(DataElementsVec const & points, PacketType type) { - return CreateDataPacketImpl(points); + return CreateDataPacketImpl(points, type); } // static @@ -82,9 +90,9 @@ string Protocol::DecodeAuthPacket(Protocol::PacketType type, vector<uint8_t> con { switch (type) { - case Protocol::PacketType::AuthV0: - return string(begin(data), end(data)); - case Protocol::PacketType::DataV0: break; + case Protocol::PacketType::AuthV0: return string(begin(data), end(data)); + case Protocol::PacketType::DataV0: + case Protocol::PacketType::DataV1: ASSERT(false, ("Not AUTH packet.")); break; } return string(); } @@ -98,9 +106,12 @@ Protocol::DataElementsVec Protocol::DecodeDataPacket(PacketType type, vector<uin switch (type) { case Protocol::PacketType::DataV0: - Encoder::DeserializeDataPoints(Encoder::kLatestVersion, src, points); + Encoder::DeserializeDataPoints(0 /* version */, src, points); + break; + case Protocol::PacketType::DataV1: + Encoder::DeserializeDataPoints(1 /* version */, src, points); break; - case Protocol::PacketType::AuthV0: break; + case Protocol::PacketType::AuthV0: ASSERT(false, ("Not DATA packet.")); break; } return points; } @@ -126,6 +137,7 @@ string DebugPrint(Protocol::PacketType type) { case Protocol::PacketType::AuthV0: return "AuthV0"; case Protocol::PacketType::DataV0: return "DataV0"; + case Protocol::PacketType::DataV1: return "DataV1"; } stringstream ss; ss << "Unknown(" << static_cast<uint32_t>(type) << ")"; |