From 0e450556bee71f56f2254191763bc8c264488f0f Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 12 Sep 2023 18:47:50 +0200 Subject: [PATCH] Packet (unit tests) - Ensure the message ID is encoded properly in big endian format --- source/doap/packet.d | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/doap/packet.d b/source/doap/packet.d index efa44f2..8f35d8c 100644 --- a/source/doap/packet.d +++ b/source/doap/packet.d @@ -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); + } \ No newline at end of file