mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 16:04:56 +02:00
Move NLPacket to its own file
This commit is contained in:
parent
d87679f115
commit
91496d37c7
2 changed files with 80 additions and 0 deletions
48
libraries/networking/src/NLPacket.cpp
Normal file
48
libraries/networking/src/NLPacket.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
//
|
||||||
|
// NLPacket.cpp
|
||||||
|
// libraries/networking/src
|
||||||
|
//
|
||||||
|
// Created by Clement on 7/6/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "NLPacket.h"
|
||||||
|
|
||||||
|
int64_t NLPacket::headerSize(PacketType::Value type) {
|
||||||
|
int64_t size = ((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID) +
|
||||||
|
((NON_VERIFIED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t NLPacket::maxPayloadSize(PacketType::Value type) {
|
||||||
|
return Packet::maxPayloadSize(type) - headerSize(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<NLPacket> NLPacket::create(PacketType::Value type, int64_t size) {
|
||||||
|
if (size > maxPayloadSize(type)) {
|
||||||
|
return std::unique_ptr<NLPacket>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::unique_ptr<NLPacket>(new NLPacket(type, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, headerSize(type) + size) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void NLPacket::setSourceUuid(QUuid sourceUuid) {
|
||||||
|
auto type = getPacketType();
|
||||||
|
Q_ASSERT(!NON_SOURCED_PACKETS.contains(type));
|
||||||
|
auto offset = Packet::headerSize(type) + NLPacket::headerSize(type);
|
||||||
|
memcpy(_packet.get() + offset, sourceUuid.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NLPacket::setConnectionUuid(QUuid connectionUuid) {
|
||||||
|
auto type = getPacketType();
|
||||||
|
Q_ASSERT(!NON_VERIFIED_PACKETS.contains(type));
|
||||||
|
auto offset = Packet::headerSize(type) + NLPacket::headerSize(type) +
|
||||||
|
((NON_SOURCED_PACKETS.contains(type)) ? 0 : NUM_BYTES_RFC4122_UUID);
|
||||||
|
memcpy(_packet.get() + offset, connectionUuid.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID);
|
||||||
|
}
|
32
libraries/networking/src/NLPacket.h
Normal file
32
libraries/networking/src/NLPacket.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
//
|
||||||
|
// NLPacket.h
|
||||||
|
// libraries/networking/src
|
||||||
|
//
|
||||||
|
// Created by Clement on 7/6/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_NLPacket_h
|
||||||
|
#define hifi_NLPacket_h
|
||||||
|
|
||||||
|
#include "Packet.h"
|
||||||
|
|
||||||
|
class NLPacket : public Packet {
|
||||||
|
public:
|
||||||
|
static int64_t headerSize(PacketType::Value type);
|
||||||
|
static int64_t maxPayloadSize(PacketType::Value type);
|
||||||
|
|
||||||
|
static std::unique_ptr<NLPacket> create(PacketType::Value type, int64_t size = -1);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NLPacket(PacketType::Value type, int64_t size);
|
||||||
|
|
||||||
|
void setSourceUuid(QUuid sourceUuid);
|
||||||
|
void setConnectionUuid(QUuid connectionUuid);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_NLPacket_h
|
Loading…
Reference in a new issue