Skip to content

Commit 57fa745

Browse files
Create super-class OperationalDatasetView out of OperationalDataset (project-chip#40346)
* Create super-class OperationalDatasetView out of OperationalDataset OperationalDatasetView does not copy or hold a buffer for the underlying dataset, and provides all the read-only methods that were present on OperationalDataset. OperationalDataset has its own buffer and copies the dataset as before. Also simplify some of the mechanics of updating values in the dataset, by replacing MakeRoom with InsertOrReplace that directly takes the required size of the value and handles updating both the tag and length of the TLV item as well as of the overall dataset, so the caller only has to fill in the value. * Avoid out of bounds access in IsValid * use EXPECT_STREQ instead of strncmp in test * Handle copy construction / assignment correctly * Fix test warning and use the view in TND server * Address review comments - Replace ThreadTLV::kMaxLength with kMaxDatasetElementLength outside of it, the TheadTLV helper does not need to know about kSizeOperationalDataset. - assert(aValueSize <= kMaxDatasetElementLength) in InsertOrReplace and document that callers (the various Set... methods) are responsible for checking the value size. - Check Channel Page == 0 in GetChannel and use BigEndian instead of math. - Tidy up method descriptions in the header. * Expand comment on self-assignments
1 parent 5be9f99 commit 57fa745

File tree

4 files changed

+584
-418
lines changed

4 files changed

+584
-418
lines changed

src/app/clusters/thread-network-directory-server/thread-network-directory-server.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void ThreadNetworkDirectoryServer::InvokeCommand(HandlerContext & ctx)
180180
void ThreadNetworkDirectoryServer::HandleAddNetworkRequest(HandlerContext & ctx,
181181
const ThreadNetworkDirectory::Commands::AddNetwork::DecodableType & req)
182182
{
183-
OperationalDataset dataset;
183+
OperationalDatasetView dataset;
184184
ByteSpan extendedPanIdSpan;
185185
uint64_t activeTimestamp;
186186
union
@@ -200,7 +200,6 @@ void ThreadNetworkDirectoryServer::HandleAddNetworkRequest(HandlerContext & ctx,
200200
CHIP_ERROR err;
201201
auto status = IMStatus::ConstraintError;
202202
const char * context = nullptr;
203-
// TODO: An immutable OperationalDatasetView on top of a ByteSpan (without copying) would be useful here.
204203
SuccessOrExitAction(err = dataset.Init(req.operationalDataset), context = "OperationalDataset");
205204
SuccessOrExitAction(err = dataset.GetExtendedPanIdAsByteSpan(extendedPanIdSpan), context = "ExtendedPanID");
206205
SuccessOrExitAction(err = dataset.GetActiveTimestamp(activeTimestamp), context = "ActiveTimestamp");

0 commit comments

Comments
 (0)