CoapPacket

- Added decoding of 1-byte option length for 1-byte delta option encoding
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-29 09:10:32 +02:00
parent dd69be55ff
commit 8c2a4b3812
1 changed files with 23 additions and 2 deletions

View File

@ -433,8 +433,29 @@ public class CoapPacket
// Option length extended (8bit) (13)
else if(optLenType == OptionLenType._8BIT_EXTENDED)
{
// TODO: Implement me
assert(false);
// The total length is the extended value (which lacks 13 so we must add it)
writeln(data[idx..$]);
ubyte optLen8BitExt = data[idx];
ushort optLen = optLen8BitExt+13;
writeln("Option len: ", optLen);
// Jump over 8bit opt len ext
idx+=1;
// Grab the data from [idx, idx+optLen)
ubyte[] optionValue = data[idx..idx+optLen];
writeln("Option value: ", optionValue);
writeln("Option value: ", cast(string)optionValue);
// Jump over the option value
idx+=optLen;
// Create the option and add it to the list of options
CoapOption option;
option.value = optionValue;
option.id = delta;
writeln("Built option: ", option);
createdOptions ~= option;
}
// Option length extended (16bit) (14)
else if(optLenType == OptionLenType._12_BIT_EXTENDED)