Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Jan 23, 2024
1 parent 6c28aef commit 4b79b85
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
15 changes: 6 additions & 9 deletions src/app/data-model/FabricScopedPreEncodedValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "FabricScopedPreEncodedValue.h"
#include <lib/core/TLVReader.h>
#include <lib/support/CodeUtils.h>

#include <optional>
Expand All @@ -24,17 +25,12 @@ namespace chip {
namespace app {
namespace DataModel {

FabricScopedPreEncodedValue::FabricScopedPreEncodedValue(const ByteSpan & aData)
{
mReader.Init(aData);
}
FabricScopedPreEncodedValue::FabricScopedPreEncodedValue(const ByteSpan & aData) : mData(aData) {}

CHIP_ERROR FabricScopedPreEncodedValue::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aFabricIndex) const
{
// Clone our reader, since we need to do Next() to move to its first element
// but not change our state. And CopyElement needs a non-const reader
// anyway since it also changes reader state.
TLV::TLVReader reader(mReader);
TLV::TLVReader reader;
reader.Init(mData);

ReturnErrorOnFailure(reader.Next());

Expand All @@ -43,7 +39,8 @@ CHIP_ERROR FabricScopedPreEncodedValue::EncodeForRead(TLV::TLVWriter & aWriter,

FabricIndex FabricScopedPreEncodedValue::GetFabricIndex() const
{
TLV::TLVReader reader(mReader);
TLV::TLVReader reader;
reader.Init(mData);
CHIP_ERROR err = reader.Next();
if (err != CHIP_NO_ERROR)
{
Expand Down
3 changes: 1 addition & 2 deletions src/app/data-model/FabricScopedPreEncodedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <lib/core/CHIPError.h>
#include <lib/core/DataModelTypes.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVWriter.h>

Expand Down Expand Up @@ -51,7 +50,7 @@ class FabricScopedPreEncodedValue
FabricIndex GetFabricIndex() const;

private:
TLV::TLVReader mReader;
const ByteSpan mData;
};

} // namespace DataModel
Expand Down
12 changes: 4 additions & 8 deletions src/app/data-model/PreEncodedValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,19 @@
*/

#include "PreEncodedValue.h"
#include <lib/core/TLVReader.h>
#include <lib/support/CodeUtils.h>

namespace chip {
namespace app {
namespace DataModel {

PreEncodedValue::PreEncodedValue(const ByteSpan & aData)
{
mReader.Init(aData);
}
PreEncodedValue::PreEncodedValue(const ByteSpan & aData) : mData(aData) {}

CHIP_ERROR PreEncodedValue::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
// Clone our reader, since we need to do Next() to move to its first element
// but not change our state. And CopyElement needs a non-const reader
// anyway since it also changes reader state.
TLV::TLVReader reader(mReader);
TLV::TLVReader reader;
reader.Init(mData);

ReturnErrorOnFailure(reader.Next());

Expand Down
3 changes: 1 addition & 2 deletions src/app/data-model/PreEncodedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

#include <lib/core/CHIPError.h>
#include <lib/core/TLVReader.h>
#include <lib/core/TLVTags.h>
#include <lib/core/TLVWriter.h>

Expand Down Expand Up @@ -45,7 +44,7 @@ class PreEncodedValue
CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;

private:
TLV::TLVReader mReader;
const ByteSpan mData;
};

} // namespace DataModel
Expand Down

0 comments on commit 4b79b85

Please sign in to comment.