[riot-notifications] [RIOT-OS/RIOT] net/nanocoap: iterate options (#12074)

Ken Bannister notifications at github.com
Thu Sep 12 12:52:14 CEST 2019


Thanks, @chrysn. Your comments forced me to think concretely about how we can evolve iteration with coap_opt_get_next(). I'm actually OK with it as is. Sorry this will be a little long winded.

I'm not concerned that we are packing the option number and the offset into a single parameter. We're trying to perform a task that's more complex than coap_opt_get_opaque() in a constrained environment. At the same time, the simplest case of just iterating through all of the options is easy, as in test_nanocoap__options_iterate().

I agree though that it's tricky to initialize the offset to get to a particular option from the result of coap_opt_get_opaque(). So, we could extend coap_opt_get next() so that the final parameter is `unsigned ` to provide more choices for initialization, where the choices are:

- COAP_OPTGET_FIRST -- get the first option
- COAP_OPTGET_NEXT -- goto offset in coap_opt_pos_t
- COAP_OPTGET_OPTNUM -- find opt_num in coap_opt_pos_t, internally with coap_find_option(). In this case, the output value of opt->opt_num still will be the delta from the previous option.

I am hesitant to add a coap_opt_seek() function because it's only paired with coap_opt_get_next(), and adds yet another function to an already large API.

As I think about OSCORE, it seems like we're going to need another function anyway. It may be that we want to read options from some buffer in a different location, like the inner options in the payload. In that case we can use something like:
```
ssize_t coap_opt_get_next_buf(uint8_t *buf, unsigned len, coap_optpos_t *opt, uint8_t **value, unsigned init_opt
```
So now the offset in the coap_optpos_t is relative to the start of some buffer rather than the start of the coap_pkt_t buffer, which is OK. In this case coap_opt_get_next() could probably become an inline function around coap_opt_get_next_buf().

At any rate, if this approach becomes too painful, we can always create a coap_opt_get_next2() with different parameters. ;-)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/12074#issuecomment-530772223
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190912/69d6f55d/attachment.htm>


More information about the notifications mailing list