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