mirror of
https://github.com/espressif/openthread.git
synced 2026-10-22 23:48:18 +00:00
[message] introduce RemoveFooter() (#10012)
This commit is contained in:
@@ -97,7 +97,7 @@ void Message::Finish(void)
|
||||
|
||||
if (GetHelpData().mPayloadMarkerSet && (GetHelpData().mHeaderLength == GetLength()))
|
||||
{
|
||||
IgnoreError(SetLength(GetLength() - 1));
|
||||
RemoveFooter(sizeof(uint8_t));
|
||||
}
|
||||
|
||||
WriteBytes(0, &GetHelpData().mHeader, GetOptionStart());
|
||||
|
||||
@@ -547,6 +547,8 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Message::RemoveFooter(uint16_t aLength) { IgnoreError(SetLength(GetLength() - Min(aLength, GetLength()))); }
|
||||
|
||||
void Message::GetFirstChunk(uint16_t aOffset, uint16_t &aLength, Chunk &aChunk) const
|
||||
{
|
||||
// This method gets the first message chunk (contiguous data
|
||||
|
||||
@@ -666,6 +666,17 @@ public:
|
||||
*/
|
||||
Error InsertHeader(uint16_t aOffset, uint16_t aLength);
|
||||
|
||||
/**
|
||||
* Removes footer bytes from the end of the message.
|
||||
*
|
||||
* The caller should ensure the message contains the bytes to be removed, otherwise as many bytes as available
|
||||
* will be removed.
|
||||
*
|
||||
* @param[in] aLength Number of footer bytes to remove from end of the `Message`.
|
||||
*
|
||||
*/
|
||||
void RemoveFooter(uint16_t aLength);
|
||||
|
||||
/**
|
||||
* Appends bytes to the end of the message.
|
||||
*
|
||||
|
||||
@@ -974,10 +974,7 @@ void Server::ProxyQueryInfo::ReadFrom(const ProxyQuery &aQuery)
|
||||
SuccessOrAssert(aQuery.Read(aQuery.GetLength() - sizeof(ProxyQueryInfo), *this));
|
||||
}
|
||||
|
||||
void Server::ProxyQueryInfo::RemoveFrom(ProxyQuery &aQuery) const
|
||||
{
|
||||
SuccessOrAssert(aQuery.SetLength(aQuery.GetLength() - sizeof(ProxyQueryInfo)));
|
||||
}
|
||||
void Server::ProxyQueryInfo::RemoveFrom(ProxyQuery &aQuery) const { aQuery.RemoveFooter(sizeof(ProxyQueryInfo)); }
|
||||
|
||||
void Server::ProxyQueryInfo::UpdateIn(ProxyQuery &aQuery) const
|
||||
{
|
||||
|
||||
@@ -465,10 +465,7 @@ void Mpl::Metadata::ReadFrom(const Message &aMessage)
|
||||
IgnoreError(aMessage.Read(length - sizeof(*this), *this));
|
||||
}
|
||||
|
||||
void Mpl::Metadata::RemoveFrom(Message &aMessage) const
|
||||
{
|
||||
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
|
||||
}
|
||||
void Mpl::Metadata::RemoveFrom(Message &aMessage) const { aMessage.RemoveFooter(sizeof(*this)); }
|
||||
|
||||
void Mpl::Metadata::UpdateIn(Message &aMessage) const { aMessage.Write(aMessage.GetLength() - sizeof(*this), *this); }
|
||||
|
||||
|
||||
@@ -2397,7 +2397,7 @@ Error Mle::ProcessMessageSecurity(Crypto::AesCcm::Mode aMode,
|
||||
if (aMode == Crypto::AesCcm::kDecrypt)
|
||||
{
|
||||
// Skip decrypting the message under fuzz build mode
|
||||
IgnoreError(aMessage.SetLength(aMessage.GetLength() - kMleSecurityTagSize));
|
||||
aMessage.RemoveFooter(kMleSecurityTagSize);
|
||||
ExitNow();
|
||||
}
|
||||
#endif
|
||||
@@ -2412,7 +2412,7 @@ Error Mle::ProcessMessageSecurity(Crypto::AesCcm::Mode aMode,
|
||||
else
|
||||
{
|
||||
VerifyOrExit(aMessage.Compare(aMessage.GetLength() - kMleSecurityTagSize, tag), error = kErrorSecurity);
|
||||
IgnoreError(aMessage.SetLength(aMessage.GetLength() - kMleSecurityTagSize));
|
||||
aMessage.RemoveFooter(kMleSecurityTagSize);
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -4423,10 +4423,7 @@ void Mle::DelayedResponseMetadata::ReadFrom(const Message &aMessage)
|
||||
IgnoreError(aMessage.Read(length - sizeof(*this), *this));
|
||||
}
|
||||
|
||||
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const
|
||||
{
|
||||
SuccessOrAssert(aMessage.SetLength(aMessage.GetLength() - sizeof(*this)));
|
||||
}
|
||||
void Mle::DelayedResponseMetadata::RemoveFrom(Message &aMessage) const { aMessage.RemoveFooter(sizeof(*this)); }
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// TxMessage
|
||||
|
||||
Reference in New Issue
Block a user