[network/libktorrent] src: API/ABI break: port Packet constructor to use QByteArrayView
Jack Hill <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 575b957f4cf9e6b45346f3e14caeebd945d18264 by Jack Hill.
Committed on 15/08/2026 at 10:38.
Pushed by jackh into branch 'master'.
API/ABI break: port Packet constructor to use QByteArrayView
and propagate up to Peer::sendExtProtMsg and
PeerProtocolExtension::sendPacket.
No downstream changes required.
M +1 -1 src/download/packet.cpp
M +3 -1 src/download/packet.h
M +3 -2 src/download/tests/packettest.cpp
M +1 -1 src/peer/peer.cpp
M +2 -1 src/peer/peer.h
M +1 -1 src/peer/peerprotocolextension.cpp
M +3 -1 src/peer/peerprotocolextension.h
https://invent.kde.org/network/libktorrent/-/commit/575b957f4cf9e6b45346f3e14caeebd945d18264
diff --git a/src/download/packet.cpp b/src/download/packet.cpp
index f663291b..25e21cac 100644
--- a/src/download/packet.cpp
+++ b/src/download/packet.cpp
@@ -74,7 +74,7 @@ Packet Packet::create(Uint32 index, Uint32 begin, Uint32 len, Chunk *ch)
return pkt;
}
-Packet Packet::create(Uint8 ext_id, const QByteArray &ext_data)
+Packet Packet::create(Uint8 ext_id, QByteArrayView ext_data)
{
const Uint32 size = 6 + ext_data.size();
Packet pkt(size, EXTENDED);
diff --git a/src/download/packet.h b/src/download/packet.h
index 971590b0..042d439e 100644
--- a/src/download/packet.h
+++ b/src/download/packet.h
@@ -9,6 +9,8 @@
#include <cstddef>
#include <optional>
+#include <QByteArrayView>
+
#include <ktorrent_export.h>
#include <util/array.h>
#include <util/constants.h>
@@ -48,7 +50,7 @@ public:
static Packet create(const BitSet &bs);
static Packet create(const Request &req, Uint8 type);
static Packet create(Uint32 index, Uint32 begin, Uint32 len, Chunk *ch);
- static Packet create(Uint8 ext_id, const QByteArray &ext_data); // extension protocol packet
+ static Packet create(Uint8 ext_id, QByteArrayView ext_data); // extension protocol packet
//! Get the packet type
Uint8 getType() const
diff --git a/src/download/tests/packettest.cpp b/src/download/tests/packettest.cpp
index 8375c250..d04947b8 100644
--- a/src/download/tests/packettest.cpp
+++ b/src/download/tests/packettest.cpp
@@ -8,6 +8,7 @@
#include <cstring>
#include <vector>
+#include <QByteArrayView>
#include <QObject>
#include <QRandomGenerator>
#include <QTest>
@@ -180,7 +181,7 @@ private Q_SLOTS:
void testExtensionMessage()
{
constexpr uint8_t extension_id = 0;
- const auto message = QByteArrayLiteral("{'m': {'ut_metadata', 3}, 'metadata_size': 31235}");
+ constexpr QByteArrayView message = "{'m': {'ut_metadata', 3}, 'metadata_size': 31235}";
const auto packet = bt::Packet::create(extension_id, message);
QVERIFY(ComparePacketSize(packet, 1 + message.size()));
@@ -203,7 +204,7 @@ private Q_SLOTS:
void testSend()
{
constexpr uint8_t extension_id = 0;
- const auto message = QByteArrayLiteral("{'m': {'ut_metadata', 3}, 'metadata_size': 31235}");
+ constexpr QByteArrayView message = "{'m': {'ut_metadata', 3}, 'metadata_size': 31235}";
constexpr bt::Uint32 max_bytes_to_send = 10;
// In case the message is changed, ensure that the data is chunked
diff --git a/src/peer/peer.cpp b/src/peer/peer.cpp
index f10bf55e..a1fe62ed 100644
--- a/src/peer/peer.cpp
+++ b/src/peer/peer.cpp
@@ -855,7 +855,7 @@ bool Peer::sendChunk(Uint32 index, Uint32 begin, Uint32 len, Chunk *ch)
return true;
}
-void Peer::sendExtProtMsg(Uint8 id, const QByteArray &data)
+void Peer::sendExtProtMsg(Uint8 id, QByteArrayView data)
{
sock->addPacket(Packet::create(id, data));
}
diff --git a/src/peer/peer.h b/src/peer/peer.h
index ed7d4b7d..1ea6c335 100644
--- a/src/peer/peer.h
+++ b/src/peer/peer.h
@@ -9,6 +9,7 @@
#include "connectionlimit.h"
#include "peerid.h"
#include "peerprotocolextension.h"
+#include <QByteArrayView>
#include <QDateTime>
#include <QObject>
#include <interfaces/peerinterface.h>
@@ -299,7 +300,7 @@ public:
void sendSuggestPiece(Uint32 index);
//! Send an extended protocol message
- void sendExtProtMsg(Uint8 id, const QByteArray &data);
+ void sendExtProtMsg(Uint8 id, QByteArrayView data);
/*!
* Clear all pending piece uploads we are not in the progress of sending.
diff --git a/src/peer/peerprotocolextension.cpp b/src/peer/peerprotocolextension.cpp
index ea6c6f21..0b551816 100644
--- a/src/peer/peerprotocolextension.cpp
+++ b/src/peer/peerprotocolextension.cpp
@@ -20,7 +20,7 @@ PeerProtocolExtension::~PeerProtocolExtension()
{
}
-void PeerProtocolExtension::sendPacket(const QByteArray &data)
+void PeerProtocolExtension::sendPacket(QByteArrayView data)
{
peer->sendExtProtMsg(id, data);
}
diff --git a/src/peer/peerprotocolextension.h b/src/peer/peerprotocolextension.h
index ec4b4cab..d0caa3dc 100644
--- a/src/peer/peerprotocolextension.h
+++ b/src/peer/peerprotocolextension.h
@@ -7,6 +7,8 @@
#ifndef BT_PEERPROTOCOLEXTENSION_H
#define BT_PEERPROTOCOLEXTENSION_H
+#include <QByteArrayView>
+
#include <ktorrent_export.h>
#include <util/constants.h>
@@ -40,7 +42,7 @@ public:
virtual void handlePacket(const bt::Uint8 *packet, Uint32 size) = 0;
//! Send an extension protocol packet
- void sendPacket(const QByteArray &data);
+ void sendPacket(QByteArrayView data);
//! Change the ID
void changeID(Uint32 id);