Skip to content

nanocoap: Support adding opaque (blob / buffer) data#11386

Merged
kb2ma merged 2 commits intoRIOT-OS:masterfrom
chrysn-pull-requests:nanocoap-add-opaque
Apr 13, 2019
Merged

nanocoap: Support adding opaque (blob / buffer) data#11386
kb2ma merged 2 commits intoRIOT-OS:masterfrom
chrysn-pull-requests:nanocoap-add-opaque

Conversation

@chrysn
Copy link
Copy Markdown
Member

@chrysn chrysn commented Apr 12, 2019

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_option low-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.

chrysn added 2 commits April 12, 2019 11:04
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).
@kb2ma kb2ma added Area: CoAP Area: Constrained Application Protocol implementations Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Apr 12, 2019
@kb2ma
Copy link
Copy Markdown
Member

kb2ma commented Apr 12, 2019

Thanks, @chrysn. We definitely need this function. I don't have any concerns, just need to test.

@kb2ma kb2ma added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Apr 13, 2019
Copy link
Copy Markdown
Member

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests fine for me.

@kb2ma kb2ma merged commit a4b909d into RIOT-OS:master Apr 13, 2019
@chrysn chrysn deleted the nanocoap-add-opaque branch April 14, 2019 09:54
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: CoAP Area: Constrained Application Protocol implementations CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants