mirror of
https://github.com/espressif/openthread.git
synced 2026-08-31 14:29:54 +00:00
[tlvs] use Tlv::Info for reading TLV values (#12322)
This change moves the TLV value reading logic from static methods in the `Tlv` class to member methods of the nested `Tlv::Info` class. The new methods `Tlv::Info::ReadValue()`, `Tlv::Info::ReadStringValue()`, `Tlv::Info::ReadUintValue()`, and the templated `Tlv::Info::Read<T>()` operate on an existing `Tlv::Info` object that has already parsed a TLV from a message. This improves the API design by having the read operations use the pre-parsed and validated state within a `Tlv::Info` instance. It avoids the need to pass the TLV offset to read functions and eliminates redundant re-parsing of the TLV header on each read, making the code cleaner and more efficient. The previous static methods `Tlv::Read<T>()`, `Tlv::ReadStringTlv()`, and `Tlv::ReadUintTlv()` are removed, and all call sites are updated to the new pattern.
This commit is contained in:
@@ -2731,14 +2731,13 @@ void Mle::HandleDiscoveryRequest(RxInfo &aRxInfo)
|
||||
switch (tlvInfo.GetType())
|
||||
{
|
||||
case MeshCoP::Tlv::kDiscoveryRequest:
|
||||
SuccessOrExit(error = Tlv::Read<MeshCoP::DiscoveryRequestTlv>(aRxInfo.mMessage, offsetRange.GetOffset(),
|
||||
discoveryRequestTlvValue));
|
||||
SuccessOrExit(error =
|
||||
tlvInfo.Read<MeshCoP::DiscoveryRequestTlv>(aRxInfo.mMessage, discoveryRequestTlvValue));
|
||||
parsedDiscoveryRequestTlv = true;
|
||||
break;
|
||||
|
||||
case MeshCoP::Tlv::kExtendedPanId:
|
||||
SuccessOrExit(
|
||||
error = Tlv::Read<MeshCoP::ExtendedPanIdTlv>(aRxInfo.mMessage, offsetRange.GetOffset(), extPanId));
|
||||
SuccessOrExit(error = tlvInfo.Read<MeshCoP::ExtendedPanIdTlv>(aRxInfo.mMessage, extPanId));
|
||||
VerifyOrExit(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId() != extPanId, error = kErrorDrop);
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user