mirror of
https://github.com/deavmi/doap
synced 2024-07-04 15:50:15 +02:00
Packet
- Added `setCode(Code)` Packet (unit tests) - Test the encoding of the request/response code
This commit is contained in:
parent
23994bb75b
commit
809ef394a0
|
@ -73,6 +73,11 @@ public class CoapPacket
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCode(Code code)
|
||||||
|
{
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
// public ubyte getVersion()
|
// public ubyte getVersion()
|
||||||
// {
|
// {
|
||||||
|
|
||||||
|
@ -96,10 +101,18 @@ version(unittest)
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
CoapPacket packet = new CoapPacket();
|
CoapPacket packet = new CoapPacket();
|
||||||
|
|
||||||
packet.setType(MessageType.RESET);
|
packet.setType(MessageType.RESET);
|
||||||
|
|
||||||
ubyte[] token = [0, 69];
|
ubyte[] token = [0, 69];
|
||||||
packet.setToken(token);
|
packet.setToken(token);
|
||||||
|
|
||||||
|
packet.setCode(Code.PONG);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ubyte[] encoded = packet.getBytes();
|
ubyte[] encoded = packet.getBytes();
|
||||||
|
|
||||||
ubyte firstByte = encoded[0];
|
ubyte firstByte = encoded[0];
|
||||||
|
@ -116,4 +129,17 @@ unittest
|
||||||
ubyte tklField = firstByte & 15;
|
ubyte tklField = firstByte & 15;
|
||||||
assert(tklField == token.length);
|
assert(tklField == token.length);
|
||||||
|
|
||||||
|
ubyte secondByte = encoded[1];
|
||||||
|
|
||||||
|
// Ensure the code is set to PONG
|
||||||
|
// Class is 7
|
||||||
|
// Code is 3
|
||||||
|
ubyte codeClass = cast(ubyte)(secondByte & 224) >> 5;
|
||||||
|
assert(codeClass == 7);
|
||||||
|
ubyte code = (secondByte & (~224));
|
||||||
|
assert(code == 3);
|
||||||
|
writeln(codeClass);
|
||||||
|
writeln(code);
|
||||||
|
assert(secondByte == Code.PONG);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user