@@ -100,6 +100,19 @@ struct EndpointEntryCount : public PersistentData<kPersistentBufferEntryCountByt
100
100
}
101
101
};
102
102
103
+ // Prevent mutations from happening in TableEntryData::Serialize
104
+ template <typename T>
105
+ class ConstCorrectRef
106
+ {
107
+ T & mRef ;
108
+
109
+ public:
110
+ inline ConstCorrectRef (T & ref) : mRef(ref) {}
111
+
112
+ inline const T * operator ->() const { return &mRef ; }
113
+ inline T * operator ->() { return &mRef ; }
114
+ };
115
+
103
116
template <class StorageId , class StorageData >
104
117
struct TableEntryData : DataAccessor
105
118
{
@@ -110,7 +123,7 @@ struct TableEntryData : DataAccessor
110
123
FabricIndex fabric_index = kUndefinedFabricIndex ;
111
124
EntryIndex index = 0 ;
112
125
bool first = true ;
113
- Data::TableEntry<StorageId, StorageData> & mEntry ;
126
+ ConstCorrectRef< Data::TableEntry<StorageId, StorageData>> mEntry ;
114
127
115
128
TableEntryData (EndpointId endpoint, FabricIndex fabric, TableEntry & entry, EntryIndex idx = 0 ) :
116
129
endpoint_id (endpoint), fabric_index(fabric), index(idx), mEntry (entry)
@@ -124,16 +137,16 @@ struct TableEntryData : DataAccessor
124
137
return CHIP_NO_ERROR;
125
138
}
126
139
127
- void Clear () override { this ->mEntry . mStorageData .Clear (); }
140
+ void Clear () override { this ->mEntry -> mStorageData .Clear (); }
128
141
129
142
CHIP_ERROR Serialize (TLV::TLVWriter & writer) const override
130
143
{
131
144
TLV::TLVType container;
132
145
ReturnErrorOnFailure (writer.StartContainer (TLV::AnonymousTag (), TLV::kTLVType_Structure , container));
133
146
134
- ReturnErrorOnFailure (Serializer::SerializeId (writer, this ->mEntry . mStorageId ));
147
+ ReturnErrorOnFailure (Serializer::SerializeId (writer, this ->mEntry -> mStorageId ));
135
148
136
- ReturnErrorOnFailure (Serializer::SerializeData (writer, this ->mEntry . mStorageData ));
149
+ ReturnErrorOnFailure (Serializer::SerializeData (writer, this ->mEntry -> mStorageData ));
137
150
138
151
return writer.EndContainer (container);
139
152
}
@@ -145,9 +158,9 @@ struct TableEntryData : DataAccessor
145
158
TLV::TLVType container;
146
159
ReturnErrorOnFailure (reader.EnterContainer (container));
147
160
148
- ReturnErrorOnFailure (Serializer::DeserializeId (reader, this ->mEntry . mStorageId ));
161
+ ReturnErrorOnFailure (Serializer::DeserializeId (reader, this ->mEntry -> mStorageId ));
149
162
150
- ReturnErrorOnFailure (Serializer::DeserializeData (reader, this ->mEntry . mStorageData ));
163
+ ReturnErrorOnFailure (Serializer::DeserializeData (reader, this ->mEntry -> mStorageData ));
151
164
152
165
return reader.ExitContainer (container);
153
166
}
0 commit comments