[core] adding FrameBuilder for constructing frames (#7935)

This commit adds a new class `FrameBuilder` which helps with
construction of frames in a given buffer. It provides helper methods
to append different items to the frame, e.g., bytes from a buffer or
`Message`, a `uint8`, `uint16` or `uint32` value assuming big or
little endian encoding, or a given object. It also provides methods
to overwrite previously appended content in the frame at a given
offset. This class is used in `Lowpan` (replacing `BufferWriter`)
which helps simplify the code. This commit also updates `Appender` to
use the `FrameBuilder` and adds a new unit test for `FrameBuidler`.
This commit is contained in:
Abtin Keshavarzian
2022-07-25 19:59:55 -07:00
committed by GitHub
parent 5bc71b2a4f
commit a282aa9f9b
15 changed files with 635 additions and 275 deletions
+7 -5
View File
@@ -171,20 +171,22 @@ static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress)
if (aCompress)
{
Lowpan::BufferWriter buffer(result, 127);
Message * compressedMsg;
Ip6::Ecn ecn;
FrameBuilder frameBuilder;
Message * compressedMsg;
Ip6::Ecn ecn;
frameBuilder.Init(result, 127);
VerifyOrQuit((message = sInstance->Get<MessagePool>().Allocate(Message::kTypeIp6)) != nullptr);
aVector.GetUncompressedStream(*message);
VerifyOrQuit(sLowpan->Compress(*message, aVector.mMacSource, aVector.mMacDestination, buffer) ==
VerifyOrQuit(sLowpan->Compress(*message, aVector.mMacSource, aVector.mMacDestination, frameBuilder) ==
aVector.mError);
if (aVector.mError == kErrorNone)
{
uint8_t compressBytes = static_cast<uint8_t>(buffer.GetWritePointer() - result);
uint16_t compressBytes = frameBuilder.GetLength();
// Append payload to the LOWPAN_IPHC.
message->ReadBytes(message->GetOffset(), result + compressBytes,