From e8ffe962325d261de9430e83355c2fc8649be906 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 30 Jul 2015 15:58:05 -0700 Subject: [PATCH] Remove const_cast --- libraries/networking/src/Assignment.cpp | 4 +--- libraries/networking/src/LimitedNodeList.cpp | 4 ++-- libraries/networking/src/NLPacket.cpp | 4 ++-- libraries/networking/src/NLPacket.h | 6 +++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libraries/networking/src/Assignment.cpp b/libraries/networking/src/Assignment.cpp index 293d86475f..e8ba67c4a6 100644 --- a/libraries/networking/src/Assignment.cpp +++ b/libraries/networking/src/Assignment.cpp @@ -150,11 +150,9 @@ QDataStream& operator<<(QDataStream &out, const Assignment& assignment) { QDataStream& operator>>(QDataStream &in, Assignment& assignment) { quint8 packedType; - in >> packedType; + in >> packedType >> assignment._uuid >> assignment._pool >> assignment._payload; assignment._type = (Assignment::Type) packedType; - in >> assignment._uuid >> assignment._pool >> assignment._payload; - if (assignment._command == Assignment::RequestCommand) { in >> assignment._walletUUID; } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 2ca4e89c12..5f547ecaf3 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -247,13 +247,13 @@ void LimitedNodeList::collectPacketStats(const NLPacket& packet) { void LimitedNodeList::fillPacketHeader(const NLPacket& packet, const QUuid& connectionSecret) { if (!NON_SOURCED_PACKETS.contains(packet.getType())) { - const_cast(packet).writeSourceID(getSessionUUID()); + packet.writeSourceID(getSessionUUID()); } if (!connectionSecret.isNull() && !NON_SOURCED_PACKETS.contains(packet.getType()) && !NON_VERIFIED_PACKETS.contains(packet.getType())) { - const_cast(packet).writeVerificationHashGivenSecret(connectionSecret); + packet.writeVerificationHashGivenSecret(connectionSecret); } } diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index 146054ccc7..84330b0d77 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -198,7 +198,7 @@ void NLPacket::readSourceID() { } } -void NLPacket::writeSourceID(const QUuid& sourceID) { +void NLPacket::writeSourceID(const QUuid& sourceID) const { Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type)); auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion); @@ -207,7 +207,7 @@ void NLPacket::writeSourceID(const QUuid& sourceID) { _sourceID = sourceID; } -void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) { +void NLPacket::writeVerificationHashGivenSecret(const QUuid& connectionSecret) const { Q_ASSERT(!NON_SOURCED_PACKETS.contains(_type) && !NON_VERIFIED_PACKETS.contains(_type)); auto offset = Packet::totalHeaderSize(isPartOfMessage()) + sizeof(PacketType) + sizeof(PacketVersion) diff --git a/libraries/networking/src/NLPacket.h b/libraries/networking/src/NLPacket.h index 2303150e66..f5c08b308a 100644 --- a/libraries/networking/src/NLPacket.h +++ b/libraries/networking/src/NLPacket.h @@ -56,8 +56,8 @@ public: const QUuid& getSourceID() const { return _sourceID; } - void writeSourceID(const QUuid& sourceID); - void writeVerificationHashGivenSecret(const QUuid& connectionSecret); + void writeSourceID(const QUuid& sourceID) const; + void writeVerificationHashGivenSecret(const QUuid& connectionSecret) const; protected: @@ -80,7 +80,7 @@ protected: PacketType _type; PacketVersion _version; - QUuid _sourceID; + mutable QUuid _sourceID; }; #endif // hifi_NLPacket_h