From 8c30637c1febcb6b75684b260fbf8a374750fabc Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 12 Sep 2023 19:23:20 +0200 Subject: [PATCH] CoapPacket - `getBytes()` now encodes the token Packet (unit tests) - Check the encoding of the token --- source/doap/packet.d | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/doap/packet.d b/source/doap/packet.d index 8f35d8c..b87c35a 100644 --- a/source/doap/packet.d +++ b/source/doap/packet.d @@ -54,6 +54,12 @@ public class CoapPacket ubyte hiByte = *(basePtr); encoded ~= [hiByte, lowByte]; } + + // Set the token (if any) + if(tokenLen) + { + encoded ~= token; + } return encoded; } @@ -169,4 +175,9 @@ unittest assert(thirdByte == 1); assert(fourthByte == 1); -} \ No newline at end of file + // Ensure the token is [0, 69] + ubyte fifthByte = encoded[4], sixthByte = encoded[5]; + assert(fifthByte == 0); + assert(sixthByte == 69); + +}