-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I don't have any suggestions for this either.
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.
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_t
type to avoid ambiguity.Testing procedure
No functional changes.
Issues/PRs references