Skip to content

Commit 3ff8865

Browse files
committed
Added more comments
1 parent 3d4ccf1 commit 3ff8865

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/app/codegen-interaction-model/Model_Read.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath
142142
return encoder.TriedEncode() ? std::make_optional(CHIP_NO_ERROR) : std::nullopt;
143143
}
144144

145+
/// Metadata of what a ember/pascal short string means (prepended by a u8 length)
145146
struct ShortPascalString
146147
{
147148
using LengthType = uint8_t;
148149
static constexpr LengthType kNullLength = 0xFF;
149150
};
150151

152+
/// Metadata of what a ember/pascal LONG string means (prepended by a u16 length)
151153
struct LongPascalString
152154
{
153155
using LengthType = uint16_t;
@@ -158,6 +160,9 @@ struct LongPascalString
158160
static_assert(sizeof(ShortPascalString::LengthType) == 1);
159161
static_assert(sizeof(LongPascalString::LengthType) == 2);
160162

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.
161166
template <class OUT, class ENCODING>
162167
std::optional<OUT> ExtractEmberString(ByteSpan data)
163168
{
@@ -175,6 +180,12 @@ std::optional<OUT> ExtractEmberString(ByteSpan data)
175180
return std::make_optional<OUT>(reinterpret_cast<typename OUT::pointer>(data.data() + sizeof(len)), len);
176181
}
177182

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.
178189
template <typename T, class ENCODING>
179190
CHIP_ERROR EncodeStringLike(ByteSpan data, bool isNullable, AttributeValueEncoder & encoder)
180191
{
@@ -192,6 +203,9 @@ CHIP_ERROR EncodeStringLike(ByteSpan data, bool isNullable, AttributeValueEncode
192203
return encoder.Encode(*value);
193204
}
194205

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.
195209
template <typename T>
196210
CHIP_ERROR EncodeFromSpan(ByteSpan data, bool isNullable, AttributeValueEncoder & encoder)
197211
{
@@ -214,6 +228,9 @@ CHIP_ERROR EncodeFromSpan(ByteSpan data, bool isNullable, AttributeValueEncoder
214228
}
215229

216230
/// 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`.
217234
CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * metadata, AttributeValueEncoder & encoder)
218235
{
219236
VerifyOrReturnError(metadata != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
@@ -279,6 +296,11 @@ CHIP_ERROR EncodeEmberValue(ByteSpan data, const EmberAfAttributeMetadata * meta
279296
} // namespace
280297

281298
/// 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
282304
CHIP_ERROR Model::ReadAttribute(const InteractionModel::ReadAttributeRequest & request, AttributeValueEncoder & encoder)
283305
{
284306
ChipLogDetail(DataManagement,

0 commit comments

Comments
 (0)