Skip to content

Commit dafe868

Browse files
committed
Testing removing one of the template functions
1 parent 830bf53 commit dafe868

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/app/WriteClient.h

+11-16
Original file line numberDiff line numberDiff line change
@@ -254,28 +254,23 @@ class WriteClient : public Messaging::ExchangeDelegate
254254
/**
255255
* Encode an attribute value that can be directly encoded using DataModel::Encode.
256256
*/
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>
271258
CHIP_ERROR TryEncodeSingleAttributeDataIB(const ConcreteDataAttributePath & attributePath, const T & value)
272259
{
273260
chip::TLV::TLVWriter * writer = nullptr;
274261

275262
ReturnErrorOnFailure(PrepareAttributeIB(attributePath));
276263
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+
}
279274
ReturnErrorOnFailure(FinishAttributeIB());
280275

281276
return CHIP_NO_ERROR;

0 commit comments

Comments
 (0)