net/gcoap: Replace use of gcoap_finish() with coap_opt_finish() #10892
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
#9309 and API Options introduced the struct-based Options API for nanocoap and gcoap. As part of that work, this PR transitions gcoap to use coap_opt_finish() to mark completion of writing message metadata -- header, token, and options.
As we have developed and integrated Options, it became clear that gcoap_finish(), the original mechanism for closing a message, was not flexible enough. Once the payload is written, it becomes difficult and inefficient to attempt to insert Options in front of it. This PR fixes that rookie mistake. :-/ However, to be clear, the procedure to build a message with gcoap_finish() still works.
This PR includes gcoap's internal use of coap_opt_finish(), unit tests, and the module documentation. To limit the scope for a reviewer, we plan to update the gcoap and cord examples in a follow-up PR.
Testing procedure
The items below will exercise everything that has changed.
Issues/PRs references
Part of #9309 struct-based Options API