Compare commits

...

6 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire a986a36c1d Merge branch 'master' into feature/options_full 2023-10-16 17:23:43 +02:00
Tristan B. Velloza Kildaire 61e8d51207 Pipelines
- Run package lists updates prior
2023-10-16 17:22:57 +02:00
Tristan B. Velloza Kildaire 963b53fcc8 CoapPacket
- Implemented `setOptions(CoapOption[] options)`
2023-10-16 17:22:12 +02:00
Tristan B. Velloza Kildaire 13b5e0a496 Packet
- Removed dead code
2023-10-16 17:20:05 +02:00
Tristan B. Velloza Kildaire 244f79f223 CoapOption
- Removed dead code
2023-10-16 17:19:49 +02:00
Tristan B. Velloza Kildaire 2017f6fd9a CoapPacket (unittests)
- Forcefully reverse the options we add so as to test the encoder's reordering mechanism
2023-10-16 17:18:58 +02:00
2 changed files with 24 additions and 16 deletions

View File

@ -26,6 +26,7 @@ jobs:
- name: Install Doveralls (code coverage tool)
run: |
dub fetch doveralls
sudo apt update
sudo apt install libcurl4-openssl-dev
- name: 'Build & Test'

View File

@ -39,20 +39,8 @@ public struct CoapOption
{
return this.id-right.id;
}
// public bool opEquals(CoapOption right)
// {
// return (this.id == right.id)
// }
}
private int optionSort(CoapOption left, CoapOption right)
{
return left.id-right.id;
}
// TODO: remove this
import std.stdio : writeln;
@ -300,7 +288,7 @@ public class CoapPacket
return encoded;
}
/**
* Takes the currently set options
* and orders them and returns an ordered
@ -495,9 +483,20 @@ public class CoapPacket
this.mid = mid;
}
public void setOptions()
/**
* Adds the provided options
*
* Params:
* options = the options to
* add
*/
public void setOptions(CoapOption[] options)
{
// FIXME: Implement me
// Add each option (duplication done in callee)
foreach(CoapOption option; options)
{
addOption(option);
}
}
/**
@ -1033,18 +1032,26 @@ unittest
CoapOption(65005, [1])
];
// Create a new packet
CoapPacket pack = new CoapPacket();
foreach(CoapOption option; expectedOptions)
// Create a copy of the options to add, reverse them in place
// ... (this is to test that the encoder orders them correctly)
import std.algorithm : reverse;
foreach(CoapOption option; reverse(expectedOptions.dup))
{
pack.addOption(option);
}
// Encode
ubyte[] encodedPacket = pack.getBytes();
// Now try decode the packet to we can see if it decodes
// ... the options correctly
CoapPacket actualPacket = CoapPacket.fromBytes(encodedPacket);
// Grab the options
CoapOption[] actualOptions = actualPacket.getOptions();
// We should have the same number of operations