@@ -147,9 +147,9 @@ class AttributeValueEncoder
147
147
{}
148
148
149
149
/* *
150
- * Encode builds a single AttributeReportIB in AttributeReportIBs.
151
- * When we are encoding a single element in the list, the actual path in the report contains a null list index as "append"
152
- * operation .
150
+ * Encode a single value. This value will not be chunked; it will either be
151
+ * entirely encoded or fail to be encoded. Consumers are allowed to make
152
+ * either one call to Encode or one call to EncodeList to handle a read .
153
153
*/
154
154
template <typename ... Ts>
155
155
CHIP_ERROR Encode (Ts &&... aArgs)
@@ -158,6 +158,15 @@ class AttributeValueEncoder
158
158
return EncodeAttributeReportIB (std::forward<Ts>(aArgs)...);
159
159
}
160
160
161
+ /* *
162
+ * Encode an explicit null value.
163
+ */
164
+ CHIP_ERROR EncodeNull ()
165
+ {
166
+ // Doesn't matter what type Nullable we use here.
167
+ return Encode (DataModel::Nullable<uint8_t >());
168
+ }
169
+
161
170
/* *
162
171
* aCallback is expected to take a const auto & argument and Encode() on it as many times as needed to encode all the list
163
172
* elements one by one. If any of those Encode() calls returns failure, aCallback must stop encoding and return failure. When
@@ -181,11 +190,7 @@ class AttributeValueEncoder
181
190
// EmptyList acts as the beginning of the whole array type attribute report.
182
191
// An empty list is encoded iff both mCurrentEncodingListIndex and mEncodeState.mCurrentEncodingListIndex are invalid
183
192
// values. After encoding the empty list, mEncodeState.mCurrentEncodingListIndex and mCurrentEncodingListIndex are set to 0.
184
- mPath .mListOp = ConcreteDataAttributePath::ListOperation::ReplaceAll;
185
193
ReturnErrorOnFailure (EncodeEmptyList ());
186
- // For all elements in the list, a report with append operation will be generated. This will not be changed during encoding
187
- // of each report since the users cannot access mPath.
188
- mPath .mListOp = ConcreteDataAttributePath::ListOperation::AppendItem;
189
194
ReturnErrorOnFailure (aCallback (ListEncodeHelper (*this )));
190
195
// The Encode procedure finished without any error, clear the state.
191
196
mEncodeState = AttributeEncodeState ();
@@ -239,12 +244,16 @@ class AttributeValueEncoder
239
244
}
240
245
241
246
/* *
242
- * Actual logic for encoding a single AttributeReportIB in AttributeReportIBs.
247
+ * Builds a single AttributeReportIB in AttributeReportIBs. The caller is
248
+ * responsible for setting up mPath correctly.
249
+ *
250
+ * In particular, when we are encoding a single element in the list, mPath
251
+ * must indicate a null list index to represent an "append" operation.
252
+ * operation.
243
253
*/
244
254
template <typename ... Ts>
245
255
CHIP_ERROR EncodeAttributeReportIB (Ts &&... aArgs)
246
256
{
247
- mTriedEncode = true ;
248
257
AttributeReportBuilder builder;
249
258
250
259
ReturnErrorOnFailure (builder.PrepareAttribute (mAttributeReportIBsBuilder , mPath , mDataVersion ));
@@ -258,6 +267,10 @@ class AttributeValueEncoder
258
267
*
259
268
* If internal state indicates we have already encoded the empty list, this function will encode nothing, set
260
269
* mCurrentEncodingListIndex to 0 and return CHIP_NO_ERROR.
270
+ *
271
+ * In all cases this function guarantees that mPath.mListOp is AppendItem
272
+ * after it returns, because at that point we will be encoding the list
273
+ * items.
261
274
*/
262
275
CHIP_ERROR EncodeEmptyList ();
263
276
0 commit comments