[srp-server] use Heap::Data to store TXT record data bytes (#7166)

This commit updates the `Srp::Server` to use the `Heap::Data` class
for storing the TXT record data bytes. This helps simplify the code.
This commit also adds a new helper method in `Heap::Data` to set
the data from a given number of bytes read from a `Message` at a
given offset. It also updates the unit test to cover the behavior
the new method.
This commit is contained in:
Abtin Keshavarzian
2021-11-16 12:23:25 -08:00
committed by GitHub
parent 19cd73d691
commit 75a46892ee
5 changed files with 60 additions and 37 deletions
+19
View File
@@ -203,6 +203,7 @@ void TestHeapData(void)
MessagePool * messagePool;
Message * message;
Heap::Data data;
uint16_t offset;
const uint8_t *oldBuffer;
static const uint8_t kData1[] = {10, 20, 3, 15, 100, 0, 60, 16};
@@ -261,6 +262,24 @@ void TestHeapData(void)
SuccessOrQuit(data.SetFrom(*message));
VerifyData(data, kData3);
SuccessOrQuit(message->Append(kData4));
offset = 0;
SuccessOrQuit(data.SetFrom(*message, offset, sizeof(kData2)));
VerifyData(data, kData2);
offset = sizeof(kData2);
SuccessOrQuit(data.SetFrom(*message, offset, sizeof(kData3)));
VerifyData(data, kData3);
offset += sizeof(kData3);
SuccessOrQuit(data.SetFrom(*message, offset, sizeof(kData4)));
VerifyData(data, kData4);
VerifyOrQuit(data.SetFrom(*message, offset, sizeof(kData4) + 1) == kErrorParse);
VerifyOrQuit(data.SetFrom(*message, 0, message->GetLength() + 1) == kErrorParse);
VerifyOrQuit(data.SetFrom(*message, 1, message->GetLength()) == kErrorParse);
printf("------------------------------------------------------------------------------------\n");
printf("Free()\n");