nanocoap: Support adding opaque (blob / buffer) data#11386
Merged
kb2ma merged 2 commits intoRIOT-OS:masterfrom Apr 13, 2019
Merged
nanocoap: Support adding opaque (blob / buffer) data#11386kb2ma merged 2 commits intoRIOT-OS:masterfrom
kb2ma merged 2 commits intoRIOT-OS:masterfrom
Conversation
This option complements the existing coap_opt_add_{uint,string} and even
more special-purpose functions; its implementation is trivial given the
existing static _add_opt_pkt function.
The method is useful when working with ETags (ETag, If-Match options).
Member
|
Thanks, @chrysn. We definitely need this function. I don't have any concerns, just need to test. |
chrysn
added a commit
to RIOT-OS/rust-riot-sys
that referenced
this pull request
May 31, 2022
This depends on RIOT-OS/RIOT#11386, and should receive some simplification when stepping up to current riot master.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This adds a
coap_opt_add_opaque(...)function that adds binary data from a buffer as an option. The name stems from the RFC7252 name for such options.The ETag options (ETag, If-Match) are options of that form, and having a generic way of adding options also helps porting more high-level CoAP libraries to nanocoap / Gcoap. (My current use case involves using Rust CoAP abstractions on a gcoap handled server).
A follow-up commit adds const qualifiers to input data of the function itself, its internal helper (which does not modify the data in its original location) and the public
coap_put_optionlow-level function used by it (which does neither). The behavior of the functions, both in implementation and semantically, is already const, the declarations were just missing; adding them makes using it easier with const-heavy code.Testing procedure
None of the examples use the method, but the gcoap example can easily be made to, by adding in _riot_board_handler before (!) coap_opt_add_format:
gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); + coap_opt_add_opaque(pdu, 4, (uint8_t*)"etag", 4); coap_opt_add_format(pdu, COAP_FORMAT_TEXT);Then, a query to the riot/board resource can be verified using Wireshark to contain a 4-byte ETag option. (Tested using the native board).
Issues/PRs references
This was not reported as a dedicated issue as it's probably small enough to handle in a PR right away.