mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 15:54:50 +02:00
put Packet templates in header
This commit is contained in:
parent
cf7ae5fbf5
commit
f6fbc14f5a
2 changed files with 8 additions and 11 deletions
|
@ -157,15 +157,6 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) {
|
|||
&seqNum, sizeof(seqNum));
|
||||
}
|
||||
|
||||
template<typename T> qint64 Packet::readPrimitive(T* data) {
|
||||
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> qint64 Packet::writePrimitive(const T& data) {
|
||||
static_assert(!std::is_pointer<T>::value, "T must not be a pointer");
|
||||
return QIODevice::write(reinterpret_cast<const char*>(&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
|
||||
|
|
|
@ -59,8 +59,14 @@ public:
|
|||
virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); }
|
||||
virtual qint64 size() const { return _capacity; }
|
||||
|
||||
template<typename T> qint64 readPrimitive(T* data);
|
||||
template<typename T> qint64 writePrimitive(const T& data);
|
||||
template<typename T> qint64 readPrimitive(T* data) {
|
||||
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> qint64 writePrimitive(const T& data) {
|
||||
static_assert(!std::is_pointer<T>::value, "T must not be a pointer");
|
||||
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||
}
|
||||
|
||||
protected:
|
||||
Packet(PacketType::Value type, int64_t size);
|
||||
|
|
Loading…
Reference in a new issue