NWM_UDS: use sizeof(<var being used>) instead of hard-coded type (#4093)

* NWM_UDS: use sizeof(<var being used>) instead of hard-coded type

Intend to fix #4090. 

` node_map.node.second` type was changed to `u16` in #3985. However the type change wasn't reflected here. Should have used variable name instead to automatically do type change

* NWM_UDS: ... and also the node.first one

* NWM_UDS: ... and here

* Network: bump version because we changed UDS packet layout

* Update nwm_uds.cpp
This commit is contained in:
Weiyi Wang 2018-08-12 23:47:48 +03:00 committed by Ben
parent c18a7896e0
commit 1b1439c6af
2 changed files with 4 additions and 3 deletions

View File

@ -161,14 +161,15 @@ static void BroadcastNodeMap() {
packet.type = Network::WifiPacket::PacketType::NodeMap;
packet.destination_address = Network::BroadcastMac;
size_t size = node_map.size();
packet.data.resize(sizeof(size) + (sizeof(Network::MacAddress) + sizeof(u32)) * size);
using node_t = decltype(node_map)::value_type;
packet.data.resize(sizeof(size) + (sizeof(node_t::first) + sizeof(node_t::second)) * size);
std::memcpy(packet.data.data(), &size, sizeof(size));
size_t offset = sizeof(size);
for (const auto& node : node_map) {
std::memcpy(packet.data.data() + offset, node.first.data(), sizeof(node.first));
std::memcpy(packet.data.data() + offset + sizeof(node.first), &node.second,
sizeof(node.second));
offset += sizeof(Network::MacAddress) + sizeof(u32);
offset += sizeof(node.first) + sizeof(node.second);
}
SendPacket(packet);

View File

@ -12,7 +12,7 @@
namespace Network {
constexpr u32 network_version = 2; ///< The version of this Room and RoomMember
constexpr u32 network_version = 3; ///< The version of this Room and RoomMember
constexpr u16 DefaultRoomPort = 24872;