[network/libktorrent] src/peer: API/ABI break: port PeerProtocolExtension to use QByteArrayView

Jack Hill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a3e123ff7c894bb171a64e3865199df499563cd3 by Jack Hill.
Committed on 15/08/2026 at 10:38.
Pushed by jackh into branch 'master'.

API/ABI break: port PeerProtocolExtension to use QByteArrayView

We already use it internally, so may as well use it for the API.

No downstream changes required.

M  +1    -1    src/peer/peer.cpp
M  +1    -1    src/peer/peerprotocolextension.h
M  +3    -3    src/peer/utmetadata.cpp
M  +1    -1    src/peer/utmetadata.h
M  +3    -4    src/peer/utpex.cpp
M  +1    -1    src/peer/utpex.h

https://invent.kde.org/network/libktorrent/-/commit/a3e123ff7c894bb171a64e3865199df499563cd3

diff --git a/src/peer/peer.cpp b/src/peer/peer.cpp
index a1fe62ed..8c80d6f5 100644
--- a/src/peer/peer.cpp
+++ b/src/peer/peer.cpp
@@ -375,7 +375,7 @@ void Peer::handleExtendedPacket(const Uint8 *packet, Uint32 size)
 
     PeerProtocolExtension *ext = extensions.find(packet[1]);
     if (ext) {
-        ext->handlePacket(packet, size);
+        ext->handlePacket(QByteArrayView{packet, size});
     } else if (packet[1] == 0) {
         handleExtendedHandshake(packet, size);
     }
diff --git a/src/peer/peerprotocolextension.h b/src/peer/peerprotocolextension.h
index d0caa3dc..307a4aeb 100644
--- a/src/peer/peerprotocolextension.h
+++ b/src/peer/peerprotocolextension.h
@@ -39,7 +39,7 @@ public:
     }
 
     //! Handle a packet
-    virtual void handlePacket(const bt::Uint8 *packet, Uint32 size) = 0;
+    virtual void handlePacket(QByteArrayView packet) = 0;
 
     //! Send an extension protocol packet
     void sendPacket(QByteArrayView data);
diff --git a/src/peer/utmetadata.cpp b/src/peer/utmetadata.cpp
index 388564a3..eb138d61 100644
--- a/src/peer/utmetadata.cpp
+++ b/src/peer/utmetadata.cpp
@@ -28,14 +28,14 @@ UTMetaData::~UTMetaData()
 {
 }
 
-void UTMetaData::handlePacket(const bt::Uint8 *packet, Uint32 size)
+void UTMetaData::handlePacket(QByteArrayView packet)
 {
-    if (size <= 2) {
+    if (packet.size() <= 2) {
         return;
     }
 
-    const auto tmp = QByteArrayView{packet, size}.sliced(2);
     try {
+        const auto tmp = packet.sliced(2);
         BDecoder dec(tmp, false);
         const std::unique_ptr<BDictNode> dict = dec.decodeDict();
         if (!dict) {
diff --git a/src/peer/utmetadata.h b/src/peer/utmetadata.h
index c643b631..34adaf03 100644
--- a/src/peer/utmetadata.h
+++ b/src/peer/utmetadata.h
@@ -29,7 +29,7 @@ public:
     /*!
         Handle a metadata packet
     */
-    void handlePacket(const bt::Uint8 *packet, Uint32 size) override;
+    void handlePacket(QByteArrayView packet) override;
 
     /*!
         Set the reported metadata size
diff --git a/src/peer/utpex.cpp b/src/peer/utpex.cpp
index 4f9f8492..aaa525f4 100644
--- a/src/peer/utpex.cpp
+++ b/src/peer/utpex.cpp
@@ -28,15 +28,14 @@ UTPex::~UTPex()
 {
 }
 
-void UTPex::handlePacket(const Uint8 *packet, Uint32 size)
+void UTPex::handlePacket(QByteArrayView packet)
 {
-    if (size <= 2 || packet[1] != 1) {
+    if (packet.size() <= 2 || packet[1] != 1) {
         return;
     }
 
-    const auto tmp = QByteArrayView{packet, size}.sliced(2);
     try {
-        BDecoder dec(tmp, false);
+        BDecoder dec(packet.sliced(2), false);
         const std::unique_ptr<BDictNode> dict = dec.decodeDict();
         if (dict) {
             // ut_pex packet, emit signal to notify PeerManager
diff --git a/src/peer/utpex.h b/src/peer/utpex.h
index dca29f57..c0177370 100644
--- a/src/peer/utpex.h
+++ b/src/peer/utpex.h
@@ -35,7 +35,7 @@ public:
      * \param packet The packet
      * \param size The size of the packet
      */
-    void handlePacket(const Uint8 *packet, Uint32 size) override;
+    void handlePacket(QByteArrayView packet) override;
 
     //! Do we need to update PEX (should happen every minute)
     [[nodiscard]] bool needsUpdate() const override;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.