CoapPacket

- Now encodes the message ID in a platform independent manner. We will encode it into big endian seeing as it feels like it could be used in a number like fashion
- Added `setMessageId(ushort)` to set the message id
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-12 18:37:57 +02:00
parent 8a11f3d405
commit 4e99ab50d8
1 changed files with 21 additions and 1 deletions

View File

@ -38,8 +38,23 @@ public class CoapPacket
encoded ~= code;
// Set the message ID
version(LittleEndian)
{
ubyte* basePtr = cast(ubyte*)∣
ubyte lowByte = *basePtr;
ubyte hiByte = *(basePtr+1);
encoded ~= [hiByte, lowByte];
}
else version(BigEndian)
{
ubyte* basePtr = cast(ubyte*)∣
ubyte lowByte = *(basePtr+1);
ubyte hiByte = *(basePtr);
encoded ~= [hiByte, lowByte];
}
return encoded;
}
@ -78,6 +93,11 @@ public class CoapPacket
this.code = code;
}
public void setMessageId(ushort mid)
{
this.mid = mid;
}
// public ubyte getVersion()
// {