mirror of
https://github.com/espressif/openthread.git
synced 2026-08-09 20:27:47 +00:00
[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user