mirror of
https://github.com/deavmi/doap
synced 2024-07-02 13:07:19 +02:00
Packet
- Defined `CoapPacket` to represent a CoAP packet - Added the required fields - Constructor sets the version to `1` (the only version available) - `getBytes()` no encodes the first byte of the CoAP header (versio, type and token length)
This commit is contained in:
parent
ec4f57af5d
commit
d6a9f7d329
36
source/doap/packet.d
Normal file
36
source/doap/packet.d
Normal file
|
@ -0,0 +1,36 @@
|
|||
module doap.packet;
|
||||
|
||||
import doap.codes : Code;
|
||||
|
||||
/**
|
||||
* Represents a CoAP packet
|
||||
*/
|
||||
public class CoapPacket
|
||||
{
|
||||
private ubyte ver, type;
|
||||
private ubyte tokenLen;
|
||||
private Code code;
|
||||
private ushort mid;
|
||||
private ubyte[] token;
|
||||
private uint options;
|
||||
private ubyte[] payload;
|
||||
|
||||
this()
|
||||
{
|
||||
// Set the version (Default is 1)
|
||||
ver = 1;
|
||||
}
|
||||
|
||||
public ubyte[] getBytes()
|
||||
{
|
||||
ubyte[] encoded;
|
||||
|
||||
// Calculate the first byte (ver | type | tkl)
|
||||
ubyte firstByte = cast(ubyte)(ver << 6);
|
||||
firstByte = firstByte | cast(ubyte)(type << 4);
|
||||
firstByte = firstByte | tokenLen;
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user