@@ -254,28 +254,23 @@ class WriteClient : public Messaging::ExchangeDelegate
254
254
/* *
255
255
* Encode an attribute value that can be directly encoded using DataModel::Encode.
256
256
*/
257
- template <class T , std::enable_if_t <!DataModel::IsFabricScoped<T>::value, int > = 0 >
258
- CHIP_ERROR TryEncodeSingleAttributeDataIB (const ConcreteDataAttributePath & attributePath, const T & value)
259
- {
260
- chip::TLV::TLVWriter * writer = nullptr ;
261
-
262
- ReturnErrorOnFailure (PrepareAttributeIB (attributePath));
263
- VerifyOrReturnError ((writer = GetAttributeDataIBTLVWriter ()) != nullptr , CHIP_ERROR_INCORRECT_STATE);
264
- ReturnErrorOnFailure (DataModel::Encode (*writer, chip::TLV::ContextTag (chip::app::AttributeDataIB::Tag::kData ), value));
265
- ReturnErrorOnFailure (FinishAttributeIB ());
266
-
267
- return CHIP_NO_ERROR;
268
- }
269
-
270
- template <class T , std::enable_if_t <DataModel::IsFabricScoped<T>::value, int > = 0 >
257
+ template <class T >
271
258
CHIP_ERROR TryEncodeSingleAttributeDataIB (const ConcreteDataAttributePath & attributePath, const T & value)
272
259
{
273
260
chip::TLV::TLVWriter * writer = nullptr ;
274
261
275
262
ReturnErrorOnFailure (PrepareAttributeIB (attributePath));
276
263
VerifyOrReturnError ((writer = GetAttributeDataIBTLVWriter ()) != nullptr , CHIP_ERROR_INCORRECT_STATE);
277
- ReturnErrorOnFailure (
278
- DataModel::EncodeForWrite (*writer, chip::TLV::ContextTag (chip::app::AttributeDataIB::Tag::kData ), value));
264
+ // Use if constexpr to make compile-time decision on which encoding method to use
265
+ if constexpr (DataModel::IsFabricScoped<T>::value)
266
+ {
267
+ ReturnErrorOnFailure (
268
+ DataModel::EncodeForWrite (*writer, chip::TLV::ContextTag (chip::app::AttributeDataIB::Tag::kData ), value));
269
+ }
270
+ else
271
+ {
272
+ ReturnErrorOnFailure (DataModel::Encode (*writer, chip::TLV::ContextTag (chip::app::AttributeDataIB::Tag::kData ), value));
273
+ }
279
274
ReturnErrorOnFailure (FinishAttributeIB ());
280
275
281
276
return CHIP_NO_ERROR;
0 commit comments