Skip to content

Commit 7f3f774

Browse files
committed
Stream server/client should pull template from base
1 parent c470cea commit 7f3f774

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/NimBLEStream.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,6 @@ void NimBLEStreamClient::deinit() {
468468
m_pChr = nullptr;
469469
}
470470

471-
size_t NimBLEStreamClient::write(const uint8_t* data, size_t len) {
472-
if (!m_pChr || !data || len == 0) {
473-
return 0;
474-
}
475-
return NimBLEStream::write(data, len);
476-
}
477-
478471
bool NimBLEStreamClient::send(const uint8_t* data, size_t len) {
479472
if (!m_pChr || !data || len == 0) {
480473
return false;

src/NimBLEStream.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class NimBLEStream : public Stream {
7373
virtual size_t write(uint8_t data) override { return write(&data, 1); }
7474

7575
// Template for other integral types (char, int, long, etc.)
76-
template <typename T>
77-
typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, uint8_t>::value, size_t>::type write(T data) {
76+
template <typename T, typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, uint8_t>::value, int>::type = 0>
77+
size_t write(T data) {
7878
return write(static_cast<uint8_t>(data));
7979
}
8080

@@ -138,6 +138,8 @@ class NimBLEStreamServer : public NimBLEStream {
138138
size_t getMaxLength() const { return m_charCallbacks.m_maxLen; }
139139
void setCallbacks(NimBLECharacteristicCallbacks* pCallbacks) { m_charCallbacks.m_userCallbacks = pCallbacks; }
140140

141+
using NimBLEStream::write; // Inherit template write overloads
142+
141143
private:
142144
bool send(const uint8_t* data, size_t len) override;
143145
bool isReady() const override { return hasSubscriber(); }
@@ -179,11 +181,12 @@ class NimBLEStreamClient : public NimBLEStream {
179181

180182
// Attach a discovered remote characteristic; app owns discovery/connection.
181183
// Set subscribeNotify=true to receive notifications into RX buffer.
182-
bool init(NimBLERemoteCharacteristic* pChr, bool subscribeNotify = false);
183-
void deinit();
184-
size_t write(const uint8_t* data, size_t len) override;
185-
void setWriteWithResponse(bool useWithRsp) { m_writeWithRsp = useWithRsp; }
186-
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
184+
bool init(NimBLERemoteCharacteristic* pChr, bool subscribeNotify = false);
185+
void deinit();
186+
void setWriteWithResponse(bool useWithRsp) { m_writeWithRsp = useWithRsp; }
187+
void setNotifyCallback(NimBLERemoteCharacteristic::notify_callback cb) { m_userNotifyCallback = cb; }
188+
189+
using NimBLEStream::write; // Inherit template write overloads
187190

188191
private:
189192
bool send(const uint8_t* data, size_t len) override;

0 commit comments

Comments
 (0)