mirror of
https://github.com/espressif/openthread.git
synced 2026-09-04 16:20:05 +00:00
[encoding] avoid the use of using for Big/LittleEndian functions (#9621)
This commit refactors the code to eliminate the use of `using` for `BigEndian` or `LittleEndian` functions like `HostSwap` and `ReadUint`. As these functions are frequently used in header files, using the direct namespace enhances code safety by mitigating potential conflicts arising from the order of included headers in the absence of explicit `using` declarations. Generally, avoiding the `using` keyword in headers is considered a recommended practice. Additionally, this commit removes the `Encoding` namespace to shorten the full function names.
This commit is contained in:
@@ -31,8 +31,6 @@
|
||||
|
||||
#include "test_util.hpp"
|
||||
|
||||
using ot::Encoding::BigEndian::ReadUint16;
|
||||
|
||||
namespace ot {
|
||||
namespace Ip4 {
|
||||
|
||||
@@ -91,7 +89,8 @@ void TestIp4Header(void)
|
||||
|
||||
// Verify the offsets to different fields.
|
||||
|
||||
VerifyOrQuit(ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, "kTotalLength is incorrect");
|
||||
VerifyOrQuit(BigEndian::ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength,
|
||||
"kTotalLength is incorrect");
|
||||
VerifyOrQuit(headerBytes[Header::kProtocolOffset] == kProtoIcmp, "kProtocol is incorrect");
|
||||
VerifyOrQuit(headerBytes[Header::kTtlOffset] == kTtl, "kTtl is incorrect");
|
||||
VerifyOrQuit(memcmp(&headerBytes[Header::kSourceAddressOffset], &source, sizeof(source)) == 0,
|
||||
@@ -116,7 +115,8 @@ void TestIp4Header(void)
|
||||
"Source address is incorrect");
|
||||
VerifyOrQuit(memcmp(&headerBytes[Header::kDestinationAddressOffset], &destination, sizeof(destination)) == 0,
|
||||
"Destination address is incorrect");
|
||||
VerifyOrQuit(ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength, "kTotalLength is incorrect");
|
||||
VerifyOrQuit(BigEndian::ReadUint16(headerBytes + Header::kTotalLengthOffset) == kTotalLength,
|
||||
"kTotalLength is incorrect");
|
||||
VerifyOrQuit(headerBytes[Header::kProtocolOffset] == kProtoIcmp, "kProtocol is incorrect");
|
||||
VerifyOrQuit(headerBytes[Header::kTtlOffset] == kTtl, "kTtl is incorrect");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user