mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 19:12:28 +02:00
add readWithoutCopy for clarity in Packet read
This commit is contained in:
parent
4696fc961a
commit
6860f3d126
10 changed files with 22 additions and 14 deletions
|
@ -203,7 +203,7 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
|
||||
void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer<NLPacket> packet) {
|
||||
// read out the sender ID
|
||||
QUuid senderID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid senderID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ int AudioMixerClientData::parseData(NLPacket& packet) {
|
|||
|
||||
// grab the stream identifier for this injected audio
|
||||
packet.seek(sizeof(quint16));
|
||||
QUuid streamIdentifier = QUuid::fromRfc4122(packet.read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid streamIdentifier = QUuid::fromRfc4122(packet.readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
bool isStereo;
|
||||
packet.readPrimitive(&isStereo);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet) {
|
||||
// compute the offset to the data payload
|
||||
return _avatar.parseDataFromBuffer(packet.read(packet.bytesLeftToRead()));
|
||||
return _avatar.parseDataFromBuffer(packet.readWithoutCopy(packet.bytesLeftToRead()));
|
||||
}
|
||||
|
||||
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
|
||||
|
|
|
@ -112,7 +112,7 @@ int InboundAudioStream::parseData(NLPacket& packet) {
|
|||
|
||||
// parse the info after the seq number and before the audio data (the stream properties)
|
||||
int prePropertyPosition = packet.pos();
|
||||
int propertyBytes = parseStreamProperties(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples);
|
||||
int propertyBytes = parseStreamProperties(packet.getType(), packet.readWithoutCopy(packet.bytesLeftToRead()), networkSamples);
|
||||
packet.seek(prePropertyPosition + propertyBytes);
|
||||
|
||||
// handle this packet based on its arrival status.
|
||||
|
@ -131,7 +131,7 @@ int InboundAudioStream::parseData(NLPacket& packet) {
|
|||
if (packet.getType() == PacketType::SilentAudioFrame) {
|
||||
writeDroppableSilentSamples(networkSamples);
|
||||
} else {
|
||||
parseAudioData(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples);
|
||||
parseAudioData(packet.getType(), packet.readWithoutCopy(packet.bytesLeftToRead()), networkSamples);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
|
|||
// enumerate over all of the avatars in this packet
|
||||
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
||||
while (packet->bytesLeftToRead()) {
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
int positionBeforeRead = packet->pos();
|
||||
|
||||
QByteArray byteArray = packet->read(packet->bytesLeftToRead());
|
||||
QByteArray byteArray = packet->readWithoutCopy(packet->bytesLeftToRead());
|
||||
|
||||
if (sessionUUID != _lastOwnerSessionUUID) {
|
||||
AvatarSharedPointer avatar = _avatarHash.value(sessionUUID);
|
||||
|
@ -114,14 +114,14 @@ void AvatarHashMap::processAvatarIdentityPacket(QSharedPointer<NLPacket> packet,
|
|||
}
|
||||
|
||||
void AvatarHashMap::processAvatarBillboardPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
AvatarSharedPointer avatar = _avatarHash.value(sessionUUID);
|
||||
if (!avatar) {
|
||||
avatar = addAvatar(sessionUUID, sendingNode);
|
||||
}
|
||||
|
||||
QByteArray billboard = packet->read(packet->bytesLeftToRead());
|
||||
QByteArray billboard = packet->readWithoutCopy(packet->bytesLeftToRead());
|
||||
if (avatar->getBillboard() != billboard) {
|
||||
avatar->setBillboard(billboard);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ void AvatarHashMap::processAvatarBillboardPacket(QSharedPointer<NLPacket> packet
|
|||
|
||||
void AvatarHashMap::processKillAvatar(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode) {
|
||||
// read the node id
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
removeAvatar(sessionUUID);
|
||||
}
|
||||
|
||||
|
|
|
@ -873,7 +873,7 @@ int EntityTree::processEraseMessage(NLPacket& packet, const SharedNodePointer& s
|
|||
break; // bail to prevent buffer overflow
|
||||
}
|
||||
|
||||
QUuid entityID = QUuid::fromRfc4122(packet.read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid entityID = QUuid::fromRfc4122(packet.readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
EntityItemID entityItemID(entityID);
|
||||
entityItemIDsToDelete << entityItemID;
|
||||
|
|
|
@ -397,7 +397,7 @@ void LimitedNodeList::killNodeWithUUID(const QUuid& nodeUUID) {
|
|||
|
||||
void LimitedNodeList::processKillNode(NLPacket& packet) {
|
||||
// read the node id
|
||||
QUuid nodeUUID = QUuid::fromRfc4122(packet.read(NUM_BYTES_RFC4122_UUID));
|
||||
QUuid nodeUUID = QUuid::fromRfc4122(packet.readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
// kill the node with this UUID, if it exists
|
||||
killNodeWithUUID(nodeUUID);
|
||||
|
|
|
@ -463,7 +463,7 @@ void NodeList::processDomainServerConnectionTokenPacket(QSharedPointer<NLPacket>
|
|||
return;
|
||||
}
|
||||
// read in the connection token from the packet, then send domain-server checkin
|
||||
_domainHandler.setConnectionToken(QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID)));
|
||||
_domainHandler.setConnectionToken(QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID)));
|
||||
sendDomainServerCheckIn();
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,13 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) {
|
|||
}
|
||||
|
||||
QByteArray Packet::read(qint64 maxSize) {
|
||||
qint64 sizeToRead = std::min(size() - pos(), maxSize);
|
||||
QByteArray data { getPayload() + pos(), (int) sizeToRead };
|
||||
seek(pos() + sizeToRead);
|
||||
return data;
|
||||
}
|
||||
|
||||
QByteArray Packet::readWithoutCopy(qint64 maxSize) {
|
||||
qint64 sizeToRead = std::min(size() - pos(), maxSize);
|
||||
QByteArray data { QByteArray::fromRawData(getPayload() + pos(), sizeToRead) };
|
||||
seek(pos() + sizeToRead);
|
||||
|
|
|
@ -81,7 +81,8 @@ public:
|
|||
|
||||
using QIODevice::read;
|
||||
QByteArray read(qint64 maxSize);
|
||||
|
||||
QByteArray readWithoutCopy(qint64 maxSize); // this can only be used if packet will stay in scope
|
||||
|
||||
template<typename T> qint64 peekPrimitive(T* data);
|
||||
template<typename T> qint64 readPrimitive(T* data);
|
||||
template<typename T> qint64 writePrimitive(const T& data);
|
||||
|
|
Loading…
Reference in a new issue