@@ -201,31 +201,32 @@ void NimBLEAdvertising::setURI(const std::string& uri) {
201201 * @brief Set the service data advertised for the UUID.
202202 * @param [in] uuid The UUID the service data belongs to.
203203 * @param [in] data The data to advertise.
204+ * @param [in] length The length of the data.
204205 * @note If data length is 0 the service data will not be advertised.
205206 */
206- void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const std::string& data) {
207+ void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const uint8_t * data, size_t length ) {
207208 switch (uuid.bitSize ()) {
208209 case 16 : {
209210 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 2 ).swap (m_svcData16);
210- m_svcData16.insert (m_svcData16.end (), data. begin () , data. end () );
211+ m_svcData16.insert (m_svcData16.end (), data, data + length );
211212 m_advData.svc_data_uuid16 = &m_svcData16[0 ];
212- m_advData.svc_data_uuid16_len = (data. length () > 0 ) ? m_svcData16.size () : 0 ;
213+ m_advData.svc_data_uuid16_len = (length > 0 ) ? m_svcData16.size () : 0 ;
213214 break ;
214215 }
215216
216217 case 32 : {
217218 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 4 ).swap (m_svcData32);
218- m_svcData32.insert (m_svcData32.end (), data. begin () , data. end () );
219+ m_svcData32.insert (m_svcData32.end (), data, data + length );
219220 m_advData.svc_data_uuid32 = &m_svcData32[0 ];
220- m_advData.svc_data_uuid32_len = (data. length () > 0 ) ? m_svcData32.size () : 0 ;
221+ m_advData.svc_data_uuid32_len = (length > 0 ) ? m_svcData32.size () : 0 ;
221222 break ;
222223 }
223224
224225 case 128 : {
225226 std::vector<uint8_t >(uuid.getValue (), uuid.getValue () + 16 ).swap (m_svcData128);
226- m_svcData128.insert (m_svcData128.end (), data. begin () , data. end () );
227+ m_svcData128.insert (m_svcData128.end (), data, data + length );
227228 m_advData.svc_data_uuid128 = &m_svcData128[0 ];
228- m_advData.svc_data_uuid128_len = (data. length () > 0 ) ? m_svcData128.size () : 0 ;
229+ m_advData.svc_data_uuid128_len = (length > 0 ) ? m_svcData128.size () : 0 ;
229230 break ;
230231 }
231232
@@ -236,6 +237,26 @@ void NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string
236237 m_advDataSet = false ;
237238} // setServiceData
238239
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::vector<uint8_t >& data) {
247+ setServiceData (uuid, data.data (), data.size ());
248+ } // setServiceData
249+
250+ /* *
251+ * @brief Set the service data advertised for the UUID.
252+ * @param [in] uuid The UUID the service data belongs to.
253+ * @param [in] data The data to advertise.
254+ * @note If data length is 0 the service data will not be advertised.
255+ */
256+ void NimBLEAdvertising::setServiceData (const NimBLEUUID& uuid, const std::string& data) {
257+ setServiceData (uuid, reinterpret_cast <const uint8_t *>(data.data ()), data.length ());
258+ } // setServiceData
259+
239260/* *
240261 * @brief Set the type of advertisement to use.
241262 * @param [in] adv_type:
0 commit comments