@@ -191,31 +191,32 @@ void NimBLEAdvertising::setURI(const std::string& uri) {
191191 * @brief Set the service data advertised for the UUID.
192192 * @param [in] uuid The UUID the service data belongs to.
193193 * @param [in] data The data to advertise.
194+ * @param [in] length The length of the data.
194195 * @note If data length is 0 the service data will not be advertised.
195196 */
196- void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const std::string& data) {
197+ void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const uint8_t * data, size_t length ) {
197198 switch (uuid.bitSize ()) {
198199 case 16 : {
199200 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 2 ).swap (m_svcData16);
200- m_svcData16.insert (m_svcData16.end (), data. begin () , data. end () );
201+ m_svcData16.insert (m_svcData16.end (), data, data + length );
201202 m_advData.svc_data_uuid16 = &m_svcData16[0 ];
202- m_advData.svc_data_uuid16_len = (data. length () > 0 ) ? m_svcData16.size () : 0 ;
203+ m_advData.svc_data_uuid16_len = (length > 0 ) ? m_svcData16.size () : 0 ;
203204 break ;
204205 }
205206
206207 case 32 : {
207208 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 4 ).swap (m_svcData32);
208- m_svcData32.insert (m_svcData32.end (), data. begin () , data. end () );
209+ m_svcData32.insert (m_svcData32.end (), data, data + length );
209210 m_advData.svc_data_uuid32 = &m_svcData32[0 ];
210- m_advData.svc_data_uuid32_len = (data. length () > 0 ) ? m_svcData32.size () : 0 ;
211+ m_advData.svc_data_uuid32_len = (length > 0 ) ? m_svcData32.size () : 0 ;
211212 break ;
212213 }
213214
214215 case 128 : {
215216 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 16 ).swap (m_svcData128);
216- m_svcData128.insert (m_svcData128.end (), data. begin () , data. end () );
217+ m_svcData128.insert (m_svcData128.end (), data, data + length );
217218 m_advData.svc_data_uuid128 = &m_svcData128[0 ];
218- m_advData.svc_data_uuid128_len = (data. length () > 0 ) ? m_svcData128.size () : 0 ;
219+ m_advData.svc_data_uuid128_len = (length > 0 ) ? m_svcData128.size () : 0 ;
219220 break ;
220221 }
221222
@@ -226,6 +227,26 @@ void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string
226227 m_advDataSet = false ;
227228} // setServiceData
228229
230+ /* *
231+ * @brief Set the service data advertised for the UUID.
232+ * @param [in] uuid The UUID the service data belongs to.
233+ * @param [in] data The data to advertise.
234+ * @note If data length is 0 the service data will not be advertised.
235+ */
236+ void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const std::vector<uint8_t >& data) {
237+ setServiceData (uuid, data.data (), data.size ());
238+ } // setServiceData
239+
240+ /* *
241+ * @brief Set the service data advertised for the UUID.
242+ * @param [in] uuid The UUID the service data belongs to.
243+ * @param [in] data The data to advertise.
244+ * @note If data length is 0 the service data will not be advertised.
245+ */
246+ void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const std::string& data) {
247+ setServiceData (uuid, reinterpret_cast <const uint8_t *>(data.data ()), data.length ());
248+ } // setServiceData
249+
229250/* *
230251 * @brief Set the type of connectable mode to advertise.
231252 * @param [in] mode The connectable mode:
0 commit comments