Skip to content

Commit

Permalink
[tlv] update and fix Tlv documentations (openthread#6776)
Browse files Browse the repository at this point in the history
This commit fixes errors in `Tlv` module documentations. It also moves
the private `Tlv::Find()` description to the `cpp` file.
  • Loading branch information
abtink authored Jun 30, 2021
1 parent 0a6a0b6 commit 8967d62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
9 changes: 9 additions & 0 deletions src/core/common/tlvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ Error Tlv::FindTlvValueOffset(const Message &aMessage, uint8_t aType, uint16_t &

Error Tlv::Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv)
{
// This static method searches within a `aMessage` for a TLV type
// `aType` and outputs the TLV offset, size, and whether or not it
// is an Extended TLV.
//
// A `nullptr` pointer can be used for output parameters `aOffset`,
// `aSize`, or `aIsExtendedTlv` if the parameter is not required.
//
// Returns `kErrorNone` when found, otherwise `kErrorNotFound`.

Error error = kErrorNotFound;
uint16_t offset = aMessage.GetOffset();
uint16_t remainingLen = aMessage.GetLength();
Expand Down
25 changes: 3 additions & 22 deletions src/core/common/tlvs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Tlv
/**
* This static method reads a simple TLV with a single integral value in a message at a given offset.
*
* @tparam UintTlvType The simple TLV type to read (must be a sub-class of `SimpleTlvInfo`).
* @tparam UintTlvType The simple TLV type to read (must be a sub-class of `UintTlvInfo`).
*
* @param[in] aMessage The message to read from.
* @param[in] aOffset The offset into the message pointing to the start of the TLV.
Expand Down Expand Up @@ -308,7 +308,6 @@ class Tlv
* @tparam TlvType The TLV type to find.
*
* @param[in] aMessage A reference to the message.
* @param[in] aType The TLV type to search for.
* @param[out] aValue A buffer to output the value (must contain at least @p aLength bytes).
* @param[in] aLength The expected (minimum) length of the TLV value.
*
Expand Down Expand Up @@ -438,25 +437,7 @@ class Tlv
};

private:
/**
* This private static method searches within a given message for TLV type and outputs the TLV offset, size and
* whether it is an Extended TLV.
*
* A nullptr pointer can be used for output parameters @p aOffset, @p aSize, or @p aIsExtendedTlv if the parameter
* is not required.
*
* @param[in] aMessage A reference to the message to search within.
* @param[in] aType The TLV type to search for.
* @param[out] aOffset A pointer to a variable to output the offset to the start of the TLV.
* @param[out] aSize A pointer to a variable to output the size (total number of bytes) of the TLV.
* @param[out] aIsExtendedTlv A pointer to a boolean variable to output whether the found TLV is extended or not.
*
* @retval kErrorNone Successfully found the TLV.
* @retval kErrorNotFound Could not find the TLV with Type @p aType.
*
*/
static Error Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv);

static Error FindTlv(const Message &aMessage, uint8_t aType, void *aValue, uint8_t aLength);
static Error AppendTlv(Message &aMessage, uint8_t aType, const void *aValue, uint8_t aLength);
template <typename UintType> static Error ReadUintTlv(const Message &aMessage, uint16_t aOffset, UintType &aValue);
Expand Down Expand Up @@ -512,7 +493,7 @@ template <uint8_t kTlvTypeValue> class TlvInfo
* This class defines constants and types for a simple TLV with an unsigned int value type.
*
* This class and its sub-classes are intended to be used as the template type in `Tlv::Append<UintTlvType>()`, and
* the related `Tlv::FindTlv()` and `Tlv::ReadTlv()`.
* the related `Tlv::Find<UintTlvType>()` and `Tlv::Read<UintTlvType>()`.
*
* @tparam kTlvTypeValue The TLV Type value.
* @tparam UintType The TLV Value's type (must be an unsigned int, i.e. uint8_t, uint16_t, or uint32_t).
Expand All @@ -532,7 +513,7 @@ template <uint8_t kTlvTypeValue, typename UintType> class UintTlvInfo : public T
* This class defines constants and types for a simple TLV with a single value.
*
* This class and its sub-classes are intended to be used as the template type in `Tlv::Append<SimpleTlvType>()`,
* and the related `Tlv::FindTlv()` and `Tlv::ReadTlv()`.
* and the related `Tlv::Find<SimpleTlvType>()` and `Tlv::Read<SimpleTlvType>()`.
*
* @tparam kTlvTypeValue The TLV Type value.
* @tparam TlvValueType The TLV Value's type (must not be an integral type).
Expand Down

0 comments on commit 8967d62

Please sign in to comment.