CoapPacket

- Typo fix
- Added a `determineOptionType(size_t)`

CoapPacket (unit tests)

- Added a unit test for it
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-29 10:17:46 +02:00
parent 2fca10a7c4
commit 4b88e34d4b
1 changed files with 45 additions and 1 deletions

View File

@ -135,7 +135,7 @@ public class CoapPacket
}
/**
* Given a payload size this determins
* Given a payload size this determines
* the required type of option length
* encoding to be used.
*
@ -167,6 +167,39 @@ public class CoapPacket
}
}
/**
* Given an option ID this determines
* the required type of option id
* encoding to be used.
*
* If the size is unsupported then
* `OptionLenType.UPPER_PAYLOAD_MARKER`
* is returned.
*
* Params:
* id = the option id
* Returns: the `OptionDeltaType`
*/
private static OptionDeltaType determineOptionType(size_t id)
{
if(id >= 0 && id <= 12)
{
return OptionDeltaType.ZERO_TO_TWELVE;
}
else if(id >= 13 && id <= 268)
{
return OptionDeltaType._8BIT_EXTENDED;
}
else if(id >= 269 && id <= 65804)
{
return OptionDeltaType._12_BIT_EXTENDED;
}
else
{
return OptionDeltaType.UPPER_PAYLOAD_MARKER;
}
}
public void setType(MessageType type)
{
@ -742,6 +775,17 @@ unittest
assert(CoapPacket.determineLenType(65804+1) == OptionLenType.UPPER_PAYLOAD_MARKER);
}
/**
* Tests `CoapPacket`'s `determineOptionType(size_t)'
*/
unittest
{
assert(CoapPacket.determineOptionType(12) == OptionDeltaType.ZERO_TO_TWELVE);
assert(CoapPacket.determineOptionType(268) == OptionDeltaType._8BIT_EXTENDED);
assert(CoapPacket.determineOptionType(65804) == OptionDeltaType._12_BIT_EXTENDED);
assert(CoapPacket.determineOptionType(65804+1) == OptionDeltaType.UPPER_PAYLOAD_MARKER);
}
/**
* Encoding tests
*