diff --git a/source/doap/packet.d b/source/doap/packet.d new file mode 100644 index 0000000..182b005 --- /dev/null +++ b/source/doap/packet.d @@ -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; + } + +} \ No newline at end of file