nanocoap: introduce coap_opt_remove()#17881
Conversation
chrysn
left a comment
There was a problem hiding this comment.
(Didn't look at the test yet, that's a bit hard to process.)
Anything I can do to make it better processable? |
I think not, I just had to bite through setup. What I think is worth covering is the removal of options with different deltas. An easy way to do this based on the existing code is to run test_nanocoap__option_remove several times with a "stride" parameter, where option |
That seems to remain at 2+data. From RFC 7252, section 3.1 I assume you meant 269? |
|
If of two delta=200 options the first is removed, the delta starts exceeding the 1+1+data range, and goes into the 1+2+data range. (Can also test with strides of 300 to test 1+2+data -> 1+2+data, but I expect that test to be less insightful). |
Ahh yeah, got it. Just got confused with the initial option length. |
|
Mh... not sure if this is right now. The returned lengths |
Done! |
sys/include/net/nanocoap.h
Outdated
| * @brief Removes an option previously added with another function in this | ||
| * [group](@ref net_nanocoap_opt_add) |
There was a problem hiding this comment.
| * @brief Removes an option previously added with another function in this | |
| * [group](@ref net_nanocoap_opt_add) | |
| * @brief Removes an option previously added with another function in [the | |
| * coap_opt_add_… group](@ref net_nanocoap_opt_add) |
|
For the public record (and especially implementers looking for that in this context): If an option is added where it is not known in advance how long it will be (i.e. when adding an option with some worst-case length for possible later removal), one might need a function, maybe called That function would share some properties with this one, but is generally easier to implement as the following option just needs to be moved (and not reencoded, possibly with a differently sized delta). The present function could be generalized, or a shortening function could be added -- but that is out of scope here. (miri64 might have pointers to a simplified special-case / limited length version she might have around later). |
chrysn
left a comment
There was a problem hiding this comment.
Fine with the code so far, now going through the test.
|
Test looks good and covers enough that I don't feel the need to give this any additional local testing. Please squash after addressing the comments. |
16e9d38 to
68f5514
Compare
Done |
chrysn
left a comment
There was a problem hiding this comment.
All looking good; the only review step I did not do is testing, but the provided test is thorough enough that I wouldn't know what else to test anyway, and it will be run by CI before merging.
Thanks, and ACK.
I set the appropriate labels ;-) |
|
Failing test is unrelated. |
Contribution description
In some cases it might be necessary to remove an already added option. In fact, due to the delta-based construction of the CoAP option header, it oftentimes is easier to add a later-to-be-added option with slack and then remove it if it isn't used after all (e.g. the ETag option). This PR provides a function to remove an option from a completed packet.
Testing procedure
A unittest is provided with
tests/unittestsso run:make -C tests/unittests/ tests-nanocoap flash-only testfor a board of your choice (preferably something else than
nativewhich I tested for)Issues/PRs references
None.