mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 10:27:49 +00:00
[netdiag] use enum for IsLastFlag in AnswerTlv (#11808)
This commit replaces the boolean `aIsLast` parameter in the `AnswerTlv::Init()` method with an `enum IsLastFlag`. This change improves the readability and type-safety of the code when specifying whether an answer is the last one in a network diagnostic query.
This commit is contained in:
@@ -599,7 +599,7 @@ void Server::SendAnswer(const Ip6::Address &aDestination, const Message &aReques
|
||||
|
||||
SuccessOrExit(error = AppendRequestedTlvs(aRequest, *answer));
|
||||
|
||||
answerTlv.Init(0, /* aIsLast */ true);
|
||||
answerTlv.Init(0, AnswerTlv::kIsLast);
|
||||
SuccessOrExit(answer->Append(answerTlv));
|
||||
|
||||
PrepareMessageInfoForDest(aDestination, messageInfo);
|
||||
@@ -721,7 +721,7 @@ void Server::PrepareAndSendAnswers(const Ip6::Address &aDestination, const Messa
|
||||
SuccessOrExit(error = CheckAnswerLength(answer, info));
|
||||
}
|
||||
|
||||
answerTlv.Init(info.mAnswerIndex, /* aIsLast */ true);
|
||||
answerTlv.Init(info.mAnswerIndex, AnswerTlv::kIsLast);
|
||||
SuccessOrExit(error = answer->Append(answerTlv));
|
||||
|
||||
SendNextAnswer(*info.mFirstAnswer, aDestination);
|
||||
@@ -746,7 +746,7 @@ Error Server::CheckAnswerLength(Coap::Message *&aAnswer, AnswerInfo &aInfo)
|
||||
|
||||
VerifyOrExit(aAnswer->GetLength() >= kAnswerMessageLengthThreshold);
|
||||
|
||||
answerTlv.Init(aInfo.mAnswerIndex++, /* aIsLast */ false);
|
||||
answerTlv.Init(aInfo.mAnswerIndex++, AnswerTlv::kMoreToFollow);
|
||||
SuccessOrExit(error = aAnswer->Append(answerTlv));
|
||||
|
||||
error = AllocateAnswer(aAnswer, aInfo);
|
||||
|
||||
@@ -124,12 +124,12 @@ void RouterNeighborTlv::InitFrom(const Router &aRouter)
|
||||
|
||||
#endif // OPENTHREAD_FTD
|
||||
|
||||
void AnswerTlv::Init(uint16_t aIndex, bool aIsLast)
|
||||
void AnswerTlv::Init(uint16_t aIndex, IsLastFlag aIsLastFlag)
|
||||
{
|
||||
SetType(kAnswer);
|
||||
SetLength(sizeof(*this) - sizeof(Tlv));
|
||||
|
||||
SetFlagsIndex((aIndex & kIndexMask) | (aIsLast ? kIsLastFlag : 0));
|
||||
SetFlagsIndex((aIndex & kIndexMask) | (aIsLastFlag == kIsLast ? kIsLastFlag : 0));
|
||||
}
|
||||
|
||||
void MleCountersTlv::Init(const Mle::Counters &aMleCounters)
|
||||
|
||||
@@ -1019,18 +1019,24 @@ OT_TOOL_PACKED_BEGIN
|
||||
class AnswerTlv : public Tlv, public TlvInfo<Tlv::kAnswer>
|
||||
{
|
||||
public:
|
||||
enum IsLastFlag : uint8_t
|
||||
{
|
||||
kMoreToFollow, ///< More answer messages to follow.
|
||||
kIsLast, ///< This is the last answer for this query.
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*
|
||||
* @param[in] aIndex The index value.
|
||||
* @param[in] aIsLast The "IsLast" flag value.
|
||||
* @param[in] aIndex The index value.
|
||||
* @param[in] aIsLastFlag Indicates the `IsLastFlag` value.
|
||||
*/
|
||||
void Init(uint16_t aIndex, bool aIsLast);
|
||||
void Init(uint16_t aIndex, IsLastFlag aIsLastFlag);
|
||||
|
||||
/**
|
||||
* Indicates whether or not the "IsLast" flag is set
|
||||
*
|
||||
* @retval TRUE "IsLast" flag si set (this is the last answer for this query).
|
||||
* @retval TRUE "IsLast" flag is set (this is the last answer for this query).
|
||||
* @retval FALSE "IsLast" flag is not set (more answer messages are expected for this query).
|
||||
*/
|
||||
bool IsLast(void) const { return GetFlagsIndex() & kIsLastFlag; }
|
||||
|
||||
Reference in New Issue
Block a user