-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NanoCoAP: Add helper functions for NanoCBOR payloads #19997
base: master
Are you sure you want to change the base?
Conversation
e3abe4d
to
3d422d7
Compare
This now also supports non-block-wise packets. |
This adds 3 functions for adding entity-tags to coap packets. The first simply adds the option to the coap packet with the supplied etag value. The second functionallow for adding a dummy etag value which is to be replaced later by the last function. This allows for allocating space for the option up front when the etag value itself is generated based on the payload
This adds an internal function to find options in a CoAP packet without modifying the coap_pkt_t struct
This adds a module to easily generate CBOR payloads in block-wise requests and responses.
f62eb9f
to
a74eb64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! 🐪
I gave it a quick look. Do you still work on it or can I go ahead and test & review it properly?
@@ -339,7 +339,7 @@ static int _gcoap_forward_proxy_copy_options(coap_pkt_t *pkt, | |||
static const uint8_t tmp[COAP_ETAG_LENGTH_MAX] = { 0 }; | |||
/* add slack to maybe add an ETag on stale cache hit later, as is done in | |||
* gcoap_req_send() (which we circumvented in _gcoap_forward_proxy_via_coap()) */ | |||
if (coap_opt_add_opaque(pkt, COAP_OPT_ETAG, tmp, sizeof(tmp))) { | |||
if (coap_opt_add_etag(pkt, COAP_OPT_ETAG, tmp, sizeof(tmp))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh?
if (coap_opt_add_etag(pkt, COAP_OPT_ETAG, tmp, sizeof(tmp))) { | |
if (coap_opt_add_etag(pkt, tmp, sizeof(tmp))) { |
@@ -1117,6 +1117,35 @@ static void test_nanocoap__token_length_ext_269(void) | |||
TEST_ASSERT_EQUAL_INT(14, hdr->ver_t_tkl & 0xf); | |||
} | |||
|
|||
static void test_nanocoap__replace_etag(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function name does not explain your intend well enough. Remember to unit test behavior so ideally something along test_that_nanocoap_replaces_an_etag_within_a_prebuild_pkt_without_segfault
😈
} | ||
} | ||
|
||
static ssize_t _etag_finish(coap_pkt_t *pdu, coap_nanocbor_slicer_helper_t *helper) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are using a lot of 'private' functions in this PR with names I find hard to relate. I would appreciate if you could make them a bit more descriptive or add small comments?
Contribution description
This adds a module to easily generate CBOR payloads in block-wise requests and responses. It wraps NanoCoAP and gcoap around the NanoCBOR stream-like interface to generate sliced block-wise payloads automatically from nanocbor encoder serialization calls. The content is serialized for every individual block-wise request. This module supports both block1 and block2 payloads and will automatically generate and update the etag option in the packet.
This module assumes that the serialized content does not change between successive serializations. In case this happens it should be detected via the etag that can be included in the packet.
Testing procedure
I've extended the example gcoap_block_server with a CBOR encoded response leveraging this module.
Issues/PRs references
Needs #19980
and #19981