[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:
Abtin Keshavarzian
2021-09-20 19:13:00 -07:00
committed by GitHub
parent 0bb0896c98
commit d14acd4324
7 changed files with 71 additions and 45 deletions
+5 -1
View File
@@ -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));