nanocoap: introduce coap_get_method()#20191
Conversation
| */ | ||
| static inline coap_method_t coap_get_method(const coap_pkt_t *pkt) | ||
| { | ||
| return pkt->hdr->code; |
There was a problem hiding this comment.
Would it make sense to check whether the packet is actually a request and not a response? Something along the lines of (pkt->hdr->code & 0b11100000) == 0. Otherwise this could return values with are actually not part of the enum coap_method_t.
There was a problem hiding this comment.
True, I'm not sure how to handle this though - slapping an assert() on there is a bad idea because the source of pkt is a network packet and we don't want to crash on a failed assertion when badly crafted packet arrives that would otherwise gracefully be ignored by not being part of a e.g. switch case.
There was a problem hiding this comment.
I see, I don't have any suggestions for this either.
There was a problem hiding this comment.
How about another enum for coap_method_t? COAP_METHOD_INVALID?
e3efe7f to
446509c
Compare
Contribution description
This is just an alias for
coap_get_code_raw().When writing a CoAP handler function, it's very unintuitive that the 'raw Code' is needed to obtain the request method.
This also gives us the opportunity to use the
coap_method_ttype to avoid ambiguity.Testing procedure
No functional changes.
Issues/PRs references