CoapOption

- Added `opCmp(CoapOption)`

CoapPacket

- `orderOptions()` now orders the options (duplicates, rders and returns a cpy)
This commit is contained in:
Tristan B. Velloza Kildaire 2023-10-16 17:13:59 +02:00
parent 5600836d2a
commit b01649337e
1 changed files with 23 additions and 14 deletions

View File

@ -26,10 +26,19 @@ public struct CoapOption
*/
public ubyte[] value;
// public int opCmp(CoapOption right)
// {
// return this.id-right.id;
// }
/**
* Compares this option with
* the provided one
*
* Params:
* right = the right-hand side
* `CoapOption` to compare to
* Returns: difference
*/
public int opCmp(CoapOption right)
{
return this.id-right.id;
}
// public bool opEquals(CoapOption right)
// {
@ -291,18 +300,18 @@ public class CoapPacket
return encoded;
}
// TODO: THIS IS WHAT NEEDS FINISHING!
/**
* Takes the currently set options
* and orders them and returns an ordered
* copy
*
* Returns: the ordered options array
*/
private CoapOption[] orderOptions()
{
// TODO: Implement ordering here
CoapOption[] sorted = this.options.dup;
// import std.algorithm.sorting : sort;
// import std.functional : binaryFun;
// import std.range : SortedRange;
// // alias optSort = optionSort;
// sort!("a<b")(sorted);
import std.algorithm.sorting : sort;
CoapOption[] sorted = sort!("a<b")( this.options.dup).release();
return sorted;
}