mirror of
https://github.com/espressif/openthread.git
synced 2026-08-24 11:19:51 +00:00
[tlv] remove unused Tlv::FindTlv() method variations (#13105)
This commit removes the legacy `Tlv::FindTlv()` method variations that read a TLV into a local buffer. These methods are no longer used across the codebase, having been replaced by safer and more efficient alternatives such as `Tlv::Find<TlvType>()`, `Tlv::FindTlvValueOffsetRange()`, or `Tlv::Info::FindIn()`. The removed methods were prone to misuse, as they did not always handle Extended TLVs correctly if the caller provided a fixed-size buffer. Removing these variations forces new code to use the modern helper functions, which provide better validation and correctly handle the decoupling of the TLV header from its value.
This commit is contained in:
@@ -57,28 +57,6 @@ const uint8_t *Tlv::GetValue(void) const
|
||||
|
||||
Error Tlv::AppendTo(Message &aMessage) const { return aMessage.AppendBytes(this, static_cast<uint16_t>(GetSize())); }
|
||||
|
||||
Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv)
|
||||
{
|
||||
uint16_t offset;
|
||||
|
||||
return FindTlv(aMessage, aType, aMaxSize, aTlv, offset);
|
||||
}
|
||||
|
||||
Error Tlv::FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv, uint16_t &aOffset)
|
||||
{
|
||||
Error error;
|
||||
Info info;
|
||||
|
||||
SuccessOrExit(error = info.FindIn(aMessage, aType));
|
||||
|
||||
info.mTlvOffsetRange.ShrinkLength(aMaxSize);
|
||||
aMessage.ReadBytes(info.mTlvOffsetRange, &aTlv);
|
||||
aOffset = info.GetTlvOffset();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Tlv::FindTlvValueOffsetRange(const Message &aMessage, uint8_t aType, OffsetRange &aOffsetRange)
|
||||
{
|
||||
Error error;
|
||||
|
||||
@@ -439,74 +439,6 @@ public:
|
||||
OffsetRange mValueOffsetRange;
|
||||
};
|
||||
|
||||
/**
|
||||
* Searches for and reads a requested TLV out of a given message.
|
||||
*
|
||||
* Can be used independent of whether the read TLV (from message) is an Extended TLV or not.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[in] aMaxSize Maximum number of bytes to read.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
*
|
||||
* @retval kErrorNone Successfully copied the TLV.
|
||||
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||
*/
|
||||
static Error FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv);
|
||||
|
||||
/**
|
||||
* Searches for and reads a requested TLV out of a given message.
|
||||
*
|
||||
* Can be used independent of whether the read TLV (from message) is an Extended TLV or not.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aType The Type value to search for.
|
||||
* @param[in] aMaxSize Maximum number of bytes to read.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
* @param[out] aOffset A reference to return the offset to start of the TLV in @p aMessage.
|
||||
*
|
||||
* @retval kErrorNone Successfully copied the TLV.
|
||||
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||
*/
|
||||
static Error FindTlv(const Message &aMessage, uint8_t aType, uint16_t aMaxSize, Tlv &aTlv, uint16_t &aOffset);
|
||||
|
||||
/**
|
||||
* Searches for and reads a requested TLV out of a given message.
|
||||
*
|
||||
* Can be used independent of whether the read TLV (from message) is an Extended TLV or not.
|
||||
*
|
||||
* @tparam TlvType The TlvType to search for (must be a sub-class of `Tlv`).
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
*
|
||||
* @retval kErrorNone Successfully copied the TLV.
|
||||
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||
*/
|
||||
template <typename TlvType> static Error FindTlv(const Message &aMessage, TlvType &aTlv)
|
||||
{
|
||||
return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for and reads a requested TLV out of a given message.
|
||||
*
|
||||
* Can be used independent of whether the read TLV (from message) is an Extended TLV or not.
|
||||
*
|
||||
* @tparam TlvType The TlvType to search for (must be a sub-class of `Tlv`).
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[out] aTlv A reference to the TLV that will be copied to.
|
||||
* @param[out] aOffset A reference to return the offset to start of the TLV in @p aMessage.
|
||||
*
|
||||
* @retval kErrorNone Successfully copied the TLV.
|
||||
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
|
||||
*/
|
||||
template <typename TlvType> static Error FindTlv(const Message &aMessage, TlvType &aTlv, uint16_t &aOffset)
|
||||
{
|
||||
return FindTlv(aMessage, TlvType::kType, sizeof(TlvType), aTlv, aOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the offset range of the TLV value for a given TLV type within @p aMessage.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user