Skip to content

Commit

Permalink
Remove changes to Decode
Browse files Browse the repository at this point in the history
Keep the other changes, and adjust the documentation.
  • Loading branch information
mlepage-google committed Jan 15, 2022
1 parent 31637e3 commit 1ecd2a4
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/app/data-model/DecodableList.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace DataModel {
* This class provides an iteratable decoder of list items within TLV payloads
* such that no memory has to be provided ahead of time to store the entirety of the decoded
* list contents.
*
*/
template <typename T>
class DecodableList
Expand All @@ -53,10 +52,7 @@ class DecodableList
/*
* @brief
*
* This call clears a TLV reader this class is to manage, for a list that is null valued.
*
* Specifically, the reader should have a `GetContainerType` that is `kTLVType_NotSpecified`
* (as if `OpenContainer` were never called).
* This call clears the TLV reader managed by this class, so it can be reused.
*/
void ClearReader() { mReader.Init(nullptr, 0); }

Expand All @@ -69,7 +65,7 @@ class DecodableList
* This reader should be pointing into the list just after
* having called `OpenContainer` on the list element, or should
* have a `kTLVType_NotSpecified` container type if there is
* no list element.
* no list.
*/
Iterator(const TLV::TLVReader & reader)
{
Expand All @@ -85,13 +81,12 @@ class DecodableList
* If an element does exist and was successfully decoded, this
* shall return true.
*
* Otherwise, if the end of list is reached, or there was no list
* (null valued list case), this call shall return false.
* Otherwise, if the end of list is reached, or there was no list,
* this call shall return false.
*
* If an error was encountered at any point during the iteration or decode,
* this shall return false as well. The caller is expected to invoke GetStatus()
* to retrieve the status of the operation.
*
*/
bool Next()
{
Expand Down Expand Up @@ -124,7 +119,6 @@ class DecodableList
*
* Notably, if the end-of-list was encountered in a previous call to Next,
* the status returned shall be CHIP_NO_ERROR.
*
*/
CHIP_ERROR GetStatus() const
{
Expand All @@ -150,8 +144,8 @@ class DecodableList
* Compute the size of the list. This can fail if the TLV is malformed. If
* this succeeds, that does not guarantee that the individual items can be
* successfully decoded; consumers should check Iterator::GetStatus() when
* actually decoding them. If there is no list (null valued list case) then
* the size is considered to be zero.
* actually decoding them. If there is no list then the size is considered
* to be zero.
*/
CHIP_ERROR ComputeSize(size_t * size) const
{
Expand All @@ -173,19 +167,11 @@ class DecodableList
template <typename X>
CHIP_ERROR Decode(TLV::TLVReader & reader, DecodableList<X> & x)
{
if (reader.GetType() == TLV::kTLVType_Null)
{
x.ClearReader();
}
else
{
VerifyOrReturnError(reader.GetType() == TLV::kTLVType_Array, CHIP_ERROR_SCHEMA_MISMATCH);
TLV::TLVType type;
ReturnErrorOnFailure(reader.EnterContainer(type));
x.SetReader(reader);
ReturnErrorOnFailure(reader.ExitContainer(type));
}

VerifyOrReturnError(reader.GetType() == TLV::kTLVType_Array, CHIP_ERROR_SCHEMA_MISMATCH);
TLV::TLVType type;
ReturnErrorOnFailure(reader.EnterContainer(type));
x.SetReader(reader);
ReturnErrorOnFailure(reader.ExitContainer(type));
return CHIP_NO_ERROR;
}

Expand Down

0 comments on commit 1ecd2a4

Please sign in to comment.