mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 14:47:46 +00:00
[message] update Message::Chunk definitions to use Data (#7019)
This commit updates the `Message::Chunk` type to use `Data` as its base class (thus inheriting the common helper methods from it) which helps simplify its use. This commit also adds couple of new methods in `Data` class (method `SetLength()` to change the `Data` length, and `MatchesBytesIn()` to compare the `Data` content with bytes from a given buffer). The `test_data` unit test is also updated to check the newly added `Data` methods.
This commit is contained in:
@@ -66,6 +66,7 @@ template <DataLengthType kDataLengthType> void TestData(void)
|
||||
data.CopyBytesTo(buffer);
|
||||
VerifyOrQuit(memcmp(buffer, kData, sizeof(kData)) == 0);
|
||||
VerifyOrQuit(buffer[sizeof(kData)] == 0);
|
||||
VerifyOrQuit(data.MatchesBytesIn(buffer));
|
||||
|
||||
data2.InitFrom(kDataCopy);
|
||||
VerifyOrQuit(data2.GetLength() == sizeof(kDataCopy));
|
||||
@@ -74,7 +75,10 @@ template <DataLengthType kDataLengthType> void TestData(void)
|
||||
VerifyOrQuit(data.StartsWith(data2));
|
||||
VerifyOrQuit(data2.StartsWith(data));
|
||||
|
||||
data2.Init(kDataCopy, sizeof(kDataCopy) - 1);
|
||||
data2.SetLength(sizeof(kDataCopy) - 1);
|
||||
VerifyOrQuit(data2.GetLength() == sizeof(kDataCopy) - 1);
|
||||
VerifyOrQuit(data2.GetBytes() == &kDataCopy[0]);
|
||||
VerifyOrQuit(data2.MatchesBytesIn(kDataCopy));
|
||||
VerifyOrQuit(data != data2);
|
||||
VerifyOrQuit(data.StartsWith(data2));
|
||||
VerifyOrQuit(!data2.StartsWith(data));
|
||||
|
||||
Reference in New Issue
Block a user