mirror of
https://github.com/espressif/openthread.git
synced 2026-09-09 02:30:11 +00:00
[core] add OffsetRange class (#10436)
This commit introduces the `OffsetRange` class, which represents a range of offsets within a `Message` or data buffer (i.e., a starting offset and a length indicating the number of bytes in the range). The class provides methods for common operations: - Getting the start or end offset, or the remaining length. - Checking if the range is empty or contains a certain number of bytes. - Advancing the start offset by a given amount, ensuring it never goes beyond the end offset. - Shrinking the range's length. The new `OffsetRange` class simplifies methods that previously used separate `aOffset` and `aLength` input parameters, improving code readability and maintainability. It also facilitates reading and processing content within a specified range. For example, `Tlv::FindTlvValueOffsetRange()` now directly returns an `OffsetRange` indicating the location of the TLV value. The `Message` class is also updated with new `Read()` and `Append()` method variants that accept `OffsetRange` arguments. These methods ensure that read content is contained within the specified `OffsetRange`.
This commit is contained in:
@@ -103,6 +103,7 @@ void TestIphcVector::GetUncompressedStream(Message &aMessage)
|
||||
static void Init(void)
|
||||
{
|
||||
otMeshLocalPrefix meshLocalPrefix = {{0xfd, 0x00, 0xca, 0xfe, 0xfa, 0xce, 0x12, 0x34}};
|
||||
OffsetRange offsetRange;
|
||||
|
||||
sInstance->Get<Mle::MleRouter>().SetMeshLocalPrefix(static_cast<Ip6::NetworkPrefix &>(meshLocalPrefix));
|
||||
|
||||
@@ -127,8 +128,10 @@ static void Init(void)
|
||||
|
||||
SuccessOrQuit(message->AppendBytes(mockNetworkData, sizeof(mockNetworkData)));
|
||||
|
||||
offsetRange.Init(2, 0x20);
|
||||
|
||||
IgnoreError(
|
||||
sInstance->Get<NetworkData::Leader>().SetNetworkData(0, 0, NetworkData::kStableSubset, *message, 2, 0x20));
|
||||
sInstance->Get<NetworkData::Leader>().SetNetworkData(0, 0, NetworkData::kStableSubset, *message, offsetRange));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user