diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index b7e0faaf0a..8a743ebc00 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -856,22 +856,22 @@ void AudioClient::handleAudioInput() { _audioPacket->reset(); // write sequence number - _audioPacket->write(reinterpret_cast(&_outgoingAvatarAudioSequenceNumber), sizeof(quint16)); + _audioPacket->write(_outgoingAvatarAudioSequenceNumber); if (_audioPacket->getPacketType() == PacketType::SilentAudioFrame) { // pack num silent samples quint16 numSilentSamples = numNetworkSamples; - _audioPacket->write(reinterpret_cast(&numSilentSamples), sizeof(quint16)); + _audioPacket->write(numSilentSamples); } else { // set the mono/stereo byte - _audioPacket->write(reinterpret_cast(&isStereo), sizeof(isStereo)); + _audioPacket->write(isStereo); } // pack the three float positions - _audioPacket->write(reinterpret_cast(&headPosition), sizeof(headPosition)); + _audioPacket->write(headPosition); // pack the orientation - _audioPacket->write(reinterpret_cast(&headOrientation), sizeof(headOrientation)); + _audioPacket->write(headOrientation); if (_audioPacket->getPacketType() != PacketType::SilentAudioFrame) { // audio samples have already been packed (written to networkAudioSamples) @@ -912,12 +912,12 @@ void AudioClient::sendMuteEnvironmentPacket() { auto mutePacket = NLPacket::create(PacketType::MuteEnvironment, dataSize); - float MUTE_RADIUS = 50; + const float MUTE_RADIUS = 50; glm::vec3 currentSourcePosition = _positionGetter(); - mutePacket->write(reinterpret_cast(¤tSourcePosition), sizeof(currentSourcePosition)); - mutePacket->write(reinterpret_cast(&MUTE_RADIUS), sizeof(MUTE_RADIUS)); + mutePacket->write(currentSourcePosition); + mutePacket->write(MUTE_RADIUS); // grab our audio mixer from the NodeList, if it exists SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer); diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index c23b5856a6..16a5bfc5e0 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -216,17 +216,17 @@ void AudioInjector::injectToMixer() { _loudness /= (float)(bytesToCopy / sizeof(int16_t)); audioPacket->seek(positionOptionOffset); - audioPacket->write(reinterpret_cast(&_options.position), sizeof(_options.position)); - audioPacket->write(reinterpret_cast(&_options.orientation), sizeof(_options.orientation)); + audioPacket->write(_options.position); + audioPacket->write(_options.orientation); volume = MAX_INJECTOR_VOLUME * _options.volume; audioPacket->seek(volumeOptionOffset); - audioPacket->write(reinterpret_cast(&volume), sizeof(volume)); + audioPacket->write(volume); audioPacket->seek(audioDataOffset); // pack the sequence number - audioPacket->write(reinterpret_cast(&outgoingInjectedAudioSequenceNumber), sizeof(quint16)); + audioPacket->write(outgoingInjectedAudioSequenceNumber); // copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy); diff --git a/libraries/networking/src/Packet.cpp b/libraries/networking/src/Packet.cpp index b11564428f..0a48ae9800 100644 --- a/libraries/networking/src/Packet.cpp +++ b/libraries/networking/src/Packet.cpp @@ -156,6 +156,14 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) { &seqNum, sizeof(seqNum)); } +template qint64 Packet::read(T* data) { + return QIODevice::read(reinterpret_cast(data), sizeof(T)); +} + +template qint64 Packet::write(const T& data) { + return QIODevice::write(reinterpret_cast(&data), sizeof(T)); +} + static const qint64 PACKET_WRITE_ERROR = -1; qint64 Packet::writeData(const char* data, qint64 maxSize) { // make sure we have the space required to write this block diff --git a/libraries/networking/src/Packet.h b/libraries/networking/src/Packet.h index 471237b212..f05feab2ea 100644 --- a/libraries/networking/src/Packet.h +++ b/libraries/networking/src/Packet.h @@ -59,6 +59,9 @@ public: virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); } virtual qint64 size() const { return _capacity; } + template qint64 read(T* data); + template qint64 write(const T& data); + protected: Packet(PacketType::Value type, int64_t size); Packet(const Packet& other); diff --git a/libraries/octree/src/JurisdictionSender.cpp b/libraries/octree/src/JurisdictionSender.cpp index 9493061354..b3c9794fcf 100644 --- a/libraries/octree/src/JurisdictionSender.cpp +++ b/libraries/octree/src/JurisdictionSender.cpp @@ -28,7 +28,6 @@ JurisdictionSender::JurisdictionSender(JurisdictionMap* map, NodeType_t type) : JurisdictionSender::~JurisdictionSender() { } - void JurisdictionSender::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) { if (packetTypeForPacket(packet) == PacketType::JurisdictionRequest) { if (sendingNode) {