[metadata] enhance ReadFrom and RemoveFrom methods (#3786)

This commit is contained in:
Duda, Lukasz
2019-04-26 15:36:02 -07:00
committed by Jonathan Hui
parent 1bd5920186
commit 0208d10563
9 changed files with 63 additions and 76 deletions
+2 -3
View File
@@ -732,9 +732,8 @@ otError ResponsesQueue::GetMatchedResponseCopy(const Message & aRequest,
continue;
}
VerifyOrExit((*aResponse = message->Clone()) != NULL, error = OT_ERROR_NO_BUFS);
EnqueuedResponseHeader::RemoveFrom(**aResponse);
VerifyOrExit((*aResponse = message->Clone(message->GetLength() - sizeof(EnqueuedResponseHeader))) != NULL,
error = OT_ERROR_NO_BUFS);
error = OT_ERROR_NONE;
break;
+12 -25
View File
@@ -131,20 +131,20 @@ public:
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
*
*/
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); };
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); }
/**
* This method reads request data from the message.
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(const Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
};
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
* This method updates request data in the message.
@@ -167,7 +167,7 @@ public:
* @retval TRUE If the message shall be sent before the given time.
* @retval FALSE Otherwise.
*/
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mNextTimerShot) >= 0); };
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mNextTimerShot) >= 0); }
/**
* This method checks if the message shall be sent after the given time.
@@ -177,7 +177,7 @@ public:
* @retval TRUE If the message shall be sent after the given time.
* @retval FALSE Otherwise.
*/
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mNextTimerShot) < 0); };
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mNextTimerShot) < 0); }
private:
Ip6::Address mSourceAddress; ///< IPv6 address of the message source.
@@ -288,25 +288,12 @@ public:
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(const Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
}
/**
* This method removes metadata from the message.
*
* @param[in] aMessage A reference to the message.
*
*/
static void RemoveFrom(Message &aMessage)
{
otError error = aMessage.SetLength(aMessage.GetLength() - sizeof(EnqueuedResponseHeader));
assert(error == OT_ERROR_NONE);
OT_UNUSED_VARIABLE(error);
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
+8 -8
View File
@@ -163,12 +163,12 @@ public:
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
@@ -176,12 +176,12 @@ public:
*
* @param[in] aMessage A reference to the message.
*
* @retval OT_ERROR_NONE Successfully removed the header.
*
*/
static otError RemoveFrom(Message &aMessage)
static void RemoveFrom(Message &aMessage)
{
return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedJoinEntHeader));
otError error = aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedJoinEntHeader));
assert(error == OT_ERROR_NONE);
OT_UNUSED_VARIABLE(error);
}
/**
+10 -10
View File
@@ -61,7 +61,7 @@ public:
* Default constructor for the object.
*
*/
QueryMetadata(void) { memset(this, 0, sizeof(*this)); };
QueryMetadata(void) { memset(this, 0, sizeof(*this)); }
/**
* This constructor initializes the object with specific values.
@@ -75,7 +75,7 @@ public:
memset(this, 0, sizeof(*this));
mResponseHandler = aHandler;
mResponseContext = aContext;
};
}
/**
* This method appends request data to the message.
@@ -86,20 +86,20 @@ public:
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
*
*/
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); };
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); }
/**
* This method reads request data from the message.
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(const Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
};
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
* This method updates request data in the message.
@@ -122,7 +122,7 @@ public:
* @retval TRUE If the message shall be sent before the given time.
* @retval FALSE Otherwise.
*/
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) > 0); };
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) > 0); }
/**
* This method checks if the message shall be sent after the given time.
@@ -132,7 +132,7 @@ public:
* @retval TRUE If the message shall be sent after the given time.
* @retval FALSE Otherwise.
*/
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) < 0); };
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) < 0); }
private:
const char * mHostname; ///< A hostname to be find.
+1 -1
View File
@@ -393,7 +393,7 @@ void Mpl::HandleRetransmissionTimer(void)
}
// Remove the extra metadata from the MPL Data Message.
messageMetadata.RemoveFrom(*message);
MplBufferedMessageMetadata::RemoveFrom(*message);
Get<Ip6>().EnqueueDatagram(*message);
}
else
+14 -11
View File
@@ -271,30 +271,33 @@ public:
* @retval OT_ERROR_NO_BUFS Insufficient available buffers to grow the message.
*
*/
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); };
otError AppendTo(Message &aMessage) const { return aMessage.Append(this, sizeof(*this)); }
/**
* This method reads request data from the message.
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes that have been read.
*
*/
uint16_t ReadFrom(const Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
};
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
* This method removes MPL Buffered Message metadata from the message.
*
* @param[in] aMessage A reference to the message.
*
* @retval OT_ERROR_NONE Successfully removed the header.
*
*/
otError RemoveFrom(Message &aMessage) { return aMessage.SetLength(aMessage.GetLength() - sizeof(*this)); };
static void RemoveFrom(Message &aMessage)
{
otError error = aMessage.SetLength(aMessage.GetLength() - sizeof(MplBufferedMessageMetadata));
assert(error == OT_ERROR_NONE);
OT_UNUSED_VARIABLE(error);
}
/**
* This method updates MPL Buffered Message metadata in the message.
@@ -317,7 +320,7 @@ public:
* @retval TRUE If the message shall be sent before the given time.
* @retval FALSE Otherwise.
*/
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) > 0); };
bool IsEarlier(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) > 0); }
/**
* This method checks if the message shall be sent after the given time.
@@ -327,7 +330,7 @@ public:
* @retval TRUE If the message shall be sent after the given time.
* @retval FALSE Otherwise.
*/
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) < 0); };
bool IsLater(uint32_t aTime) const { return (static_cast<int32_t>(aTime - mTransmissionTime) < 0); }
/**
* This method returns the MPL Seed Id value.
+1 -3
View File
@@ -234,12 +234,10 @@ Message *Client::FindRelatedQuery(const Header &aResponseHeader, QueryMetadata &
while (message != NULL)
{
// Read originate timestamp.
uint16_t count = aQueryMetadata.ReadFrom(*message);
assert(count == sizeof(aQueryMetadata));
aQueryMetadata.ReadFrom(*message);
if (aQueryMetadata.mTransmitTimestamp == aResponseHeader.GetOriginateTimestampSeconds())
{
aQueryMetadata.ReadFrom(*message);
ExitNow();
}
+5 -5
View File
@@ -463,13 +463,13 @@ public:
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(const Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
};
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
* This method updates request data in the message.
+10 -10
View File
@@ -398,26 +398,26 @@ public:
*
* @param[in] aMessage A reference to the message.
*
* @returns The number of bytes read.
*
*/
uint16_t ReadFrom(Message &aMessage)
void ReadFrom(const Message &aMessage)
{
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
};
uint16_t length = aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
assert(length == sizeof(*this));
OT_UNUSED_VARIABLE(length);
}
/**
* This method removes delayed response header from the message.
*
* @param[in] aMessage A reference to the message.
*
* @retval OT_ERROR_NONE Successfully removed the header.
*
*/
static otError RemoveFrom(Message &aMessage)
static void RemoveFrom(Message &aMessage)
{
return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedResponseHeader));
};
otError error = aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedResponseHeader));
assert(error == OT_ERROR_NONE);
OT_UNUSED_VARIABLE(error);
}
/**
* This method returns a time when the message shall be sent.