mirror of https://github.com/deavmi/doap
Packet
- Added `setTokenLength(ulong)` which returns `false` if the token length is above 15, else sets the token length (<=15) and returns `true` - Added `setToken(ubyte[])` which sets the token (and length) and checks that the length is fine Exceptions - Added new exception time `CoapException`
This commit is contained in:
parent
64e22741dd
commit
f7f928023d
|
@ -0,0 +1,9 @@
|
|||
module doap.exceptions;
|
||||
|
||||
public class CoapException : Exception
|
||||
{
|
||||
this(string msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ module doap.packet;
|
|||
|
||||
import doap.types : MessageType;
|
||||
import doap.codes : Code;
|
||||
import doap.exceptions : CoapException;
|
||||
|
||||
/**
|
||||
* Represents a CoAP packet
|
||||
|
@ -47,6 +48,31 @@ public class CoapPacket
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public void setToken(ubyte[] token)
|
||||
{
|
||||
if(setTokenLength(token.length))
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CoapException("Token length above 15 bytes not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
private bool setTokenLength(ulong tkl)
|
||||
{
|
||||
if(tkl > 15)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.tokenLen = cast(ubyte)tkl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// public ubyte getVersion()
|
||||
// {
|
||||
|
||||
|
|
Loading…
Reference in New Issue