Packet (unit tests)

- Ensure the message ID is encoded properly in big endian format
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-12 18:47:50 +02:00
parent edf7de3839
commit 0e450556be

View File

@ -37,7 +37,7 @@ public class CoapPacket
// Set the request/response code
encoded ~= code;
// Set the message ID
// Set the message ID (encoded as big endian)
version(LittleEndian)
{
ubyte* basePtr = cast(ubyte*)∣
@ -129,6 +129,8 @@ unittest
packet.setCode(Code.PONG);
packet.setMessageId(257);
@ -162,4 +164,9 @@ unittest
writeln(code);
assert(secondByte == Code.PONG);
// Ensure the message ID is 257
ubyte thirdByte = encoded[2], fourthByte = encoded[3];
assert(thirdByte == 1);
assert(fourthByte == 1);
}