From 1a47cc2e867e3ea476ff696899cf7ae5af008355 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 27 Jan 2023 09:14:38 -0800 Subject: [PATCH] [ntcore] Use full handle when subscribing (#5013) Just using the index is insufficient because of Subscriber overlap with MultiSubscriber. --- ntcore/src/main/native/cpp/net/WireEncoder.cpp | 5 ++--- ntcore/src/test/native/cpp/net/WireEncoderTest.cpp | 5 +++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ntcore/src/main/native/cpp/net/WireEncoder.cpp b/ntcore/src/main/native/cpp/net/WireEncoder.cpp index 143fe0dc056..e51970213ad 100644 --- a/ntcore/src/main/native/cpp/net/WireEncoder.cpp +++ b/ntcore/src/main/native/cpp/net/WireEncoder.cpp @@ -142,10 +142,9 @@ bool nt::net::WireEncodeText(wpi::raw_ostream& os, const ClientMessage& msg) { } else if (auto m = std::get_if(&msg.contents)) { WireEncodeSetProperties(os, m->name, m->update); } else if (auto m = std::get_if(&msg.contents)) { - WireEncodeSubscribe(os, Handle{m->subHandle}.GetIndex(), m->topicNames, - m->options); + WireEncodeSubscribe(os, m->subHandle, m->topicNames, m->options); } else if (auto m = std::get_if(&msg.contents)) { - WireEncodeUnsubscribe(os, Handle{m->subHandle}.GetIndex()); + WireEncodeUnsubscribe(os, m->subHandle); } else { return false; } diff --git a/ntcore/src/test/native/cpp/net/WireEncoderTest.cpp b/ntcore/src/test/native/cpp/net/WireEncoderTest.cpp index 9cc31878652..883b15e1dd6 100644 --- a/ntcore/src/test/native/cpp/net/WireEncoderTest.cpp +++ b/ntcore/src/test/native/cpp/net/WireEncoderTest.cpp @@ -172,14 +172,15 @@ TEST_F(WireEncoderTextTest, MessageSubscribe) { ASSERT_TRUE(net::WireEncodeText(os, msg)); ASSERT_EQ(os.str(), "{\"method\":\"subscribe\",\"params\":{" - "\"options\":{},\"topics\":[\"a\",\"b\"],\"subuid\":5}}"); + "\"options\":{},\"topics\":[\"a\",\"b\"],\"subuid\":402653189}}"); } TEST_F(WireEncoderTextTest, MessageUnsubscribe) { net::ClientMessage msg{ net::UnsubscribeMsg{Handle{0, 5, Handle::kSubscriber}}}; ASSERT_TRUE(net::WireEncodeText(os, msg)); - ASSERT_EQ(os.str(), "{\"method\":\"unsubscribe\",\"params\":{\"subuid\":5}}"); + ASSERT_EQ(os.str(), + "{\"method\":\"unsubscribe\",\"params\":{\"subuid\":402653189}}"); } TEST_F(WireEncoderTextTest, MessageAnnounce) {