@@ -142,12 +142,14 @@ std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath
142
142
return encoder.TriedEncode () ? std::make_optional (CHIP_NO_ERROR) : std::nullopt;
143
143
}
144
144
145
+ // / Metadata of what a ember/pascal short string means (prepended by a u8 length)
145
146
struct ShortPascalString
146
147
{
147
148
using LengthType = uint8_t ;
148
149
static constexpr LengthType kNullLength = 0xFF ;
149
150
};
150
151
152
+ // / Metadata of what a ember/pascal LONG string means (prepended by a u16 length)
151
153
struct LongPascalString
152
154
{
153
155
using LengthType = uint16_t ;
@@ -158,6 +160,9 @@ struct LongPascalString
158
160
static_assert (sizeof (ShortPascalString::LengthType) == 1 );
159
161
static_assert (sizeof (LongPascalString::LengthType) == 2 );
160
162
163
+ // / Given a ByteSpan containing data from ember, interpret it
164
+ // / as a span of type OUT (i.e. ByteSpan or CharSpan) given a ENCODING
165
+ // / where ENCODING is Short or Long pascal strings.
161
166
template <class OUT , class ENCODING >
162
167
std::optional<OUT> ExtractEmberString (ByteSpan data)
163
168
{
@@ -175,6 +180,12 @@ std::optional<OUT> ExtractEmberString(ByteSpan data)
175
180
return std::make_optional<OUT>(reinterpret_cast <typename OUT::pointer>(data.data () + sizeof (len)), len);
176
181
}
177
182
183
+ // / Encode a value inside `encoder`
184
+ // /
185
+ // / The value encoded will be of type T (e.g. CharSpan or ByteSpan) and it will be decoded
186
+ // / via the given ENCODING (i.e. ShortPascalString or LongPascalString)
187
+ // /
188
+ // / isNullable defines if the value of NULL is allowed to be encoded.
178
189
template <typename T, class ENCODING >
179
190
CHIP_ERROR EncodeStringLike (ByteSpan data, bool isNullable, AttributeValueEncoder & encoder)
180
191
{
@@ -192,6 +203,9 @@ CHIP_ERROR EncodeStringLike(ByteSpan data, bool isNullable, AttributeValueEncode
192
203
return encoder.Encode (*value);
193
204
}
194
205
206
+ // / Encodes a numeric data value of type T from the given ember-encoded buffer `data`.
207
+ // /
208
+ // / isNullable defines if the value of NULL is allowed to be encoded.
195
209
template <typename T>
196
210
CHIP_ERROR EncodeFromSpan (ByteSpan data, bool isNullable, AttributeValueEncoder & encoder)
197
211
{
@@ -214,6 +228,9 @@ CHIP_ERROR EncodeFromSpan(ByteSpan data, bool isNullable, AttributeValueEncoder
214
228
}
215
229
216
230
// / Converts raw ember data from `data` into the encoder
231
+ // /
232
+ // / Uses the attribute `metadata` to determine how the data is encoded into `data` and
233
+ // / write a suitable value into `encoder`.
217
234
CHIP_ERROR EncodeEmberValue (ByteSpan data, const EmberAfAttributeMetadata * metadata, AttributeValueEncoder & encoder)
218
235
{
219
236
VerifyOrReturnError (metadata != nullptr , CHIP_ERROR_INVALID_ARGUMENT);
@@ -279,6 +296,11 @@ CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * meta
279
296
} // namespace
280
297
281
298
// / separated-out ReadAttribute implementation (given existing complexity)
299
+ // /
300
+ // / Generally will:
301
+ // / - validate ACL (only for non-internal requests)
302
+ // / - Try to read attribute via the AttributeAccessInterface
303
+ // / - Try to read the value from ember RAM storage
282
304
CHIP_ERROR Model::ReadAttribute (const InteractionModel::ReadAttributeRequest & request, AttributeValueEncoder & encoder)
283
305
{
284
306
ChipLogDetail (DataManagement,
0 commit comments