-
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: rename coap_get_code() -> coap_get_code_decimal() #20004
Conversation
29b6c35
to
7a425c2
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.
Can't we just remove it?
All we had in terms of users in the code base are tests, and if we're happy with the breakage of the API change of the transitional period, let's get rid of it right away. (On the long run we might even reuse the coap_get_code
for coap_get_code_raw
, but that works best after a release that did not have that symbol, as just altering the behavior would lead to silent breakage with users.)
@@ -89,7 +89,7 @@ static void test_gcoap__client_get_req(void) | |||
len = gcoap_request(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, | |||
COAP_METHOD_GET, &path[0]); | |||
|
|||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_raw(&pdu)); |
@@ -157,7 +157,7 @@ static void test_gcoap__client_put_req(void) | |||
|
|||
coap_parse(&pdu, buf, len + 1); | |||
|
|||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code(&pdu)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_decimal(&pdu)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_decimal(&pdu)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_raw(&pdu)); |
@@ -223,7 +223,7 @@ static void test_gcoap__client_ping(void) | |||
NULL); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(COAP_CODE_EMPTY, coap_get_code(&pdu)); | |||
TEST_ASSERT_EQUAL_INT(COAP_CODE_EMPTY, coap_get_code_decimal(&pdu)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_CODE_EMPTY, coap_get_code_decimal(&pdu)); | |
TEST_ASSERT_EQUAL_INT(COAP_CODE_EMPTY, coap_get_code_raw(&pdu)); |
@@ -261,7 +261,7 @@ static void test_gcoap__server_get_req(void) | |||
int res = _read_cli_stats_req(&pdu, &buf[0]); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_raw(&pdu)); |
@@ -333,7 +333,7 @@ static void test_gcoap__server_con_req(void) | |||
int res = _read_cli_stats_req_con(&pdu, &buf[0]); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pdu)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pdu)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_raw(&pdu)); |
@@ -146,7 +146,7 @@ static void test_nanocoap__put_req(void) | |||
|
|||
coap_pkt_init(&pkt, &buf[0], sizeof(buf), len); | |||
|
|||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code(&pkt)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_decimal(&pkt)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_decimal(&pkt)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_PUT, coap_get_code_raw(&pkt)); |
@@ -683,7 +683,7 @@ static void test_nanocoap__server_get_req(void) | |||
int res = _read_riot_value_req(&pkt, &buf[0]); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pkt)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pkt)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pkt)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_raw(&pkt)); |
@@ -740,7 +740,7 @@ static void test_nanocoap__server_get_req_con(void) | |||
int res = _read_riot_value_req_con(&pkt, &buf[0]); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pkt)); | |||
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pkt)); |
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.
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pkt)); | |
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_raw(&pkt)); |
@@ -1081,7 +1081,7 @@ static void test_nanocoap__token_length_ext_16(void) | |||
int res = coap_parse(&pkt, buf, 21); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(204, coap_get_code(&pkt)); | |||
TEST_ASSERT_EQUAL_INT(204, coap_get_code_decimal(&pkt)); |
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.
TEST_ASSERT_EQUAL_INT(204, coap_get_code_decimal(&pkt)); | |
TEST_ASSERT_EQUAL_INT(COAP_CODE_CHANGED, coap_get_code_raw(&pkt)); |
@@ -1109,7 +1109,7 @@ static void test_nanocoap__token_length_ext_269(void) | |||
int res = coap_parse(&pkt, buf, 275); | |||
|
|||
TEST_ASSERT_EQUAL_INT(0, res); | |||
TEST_ASSERT_EQUAL_INT(204, coap_get_code(&pkt)); | |||
TEST_ASSERT_EQUAL_INT(204, coap_get_code_decimal(&pkt)); |
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.
TEST_ASSERT_EQUAL_INT(204, coap_get_code_decimal(&pkt)); | |
TEST_ASSERT_EQUAL_INT(COAP_CODE_CHANGED, coap_get_code_raw(&pkt)); |
I think it's still nicer to see e.g. Having it as a convenience function for that (with an explicit name) does no harm. |
I agree with this use case. I think it does make sense to give it a name that makes it a bit more clear that it is only meant for human readable output. |
If it is just about convenience when debugging, why not have it output a string directly? Something with the signiture, e.g., static inline char *coap_get_code(const coap_pkt_t *pkt, char *str); that you can just use it in a |
Why arbitrarily limit the possible use of the function like that? |
Because what else would you want to do with a function that behaves wrong? |
It's not behaving wrong, it just has the wrong name. |
Isn't it missing the decimal point for the decimal representation ;-)? |
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.
Let's get this in as is, as this beyond any doubt improves the status quo.
I do agree that 2.05
would be the right string and preferred over 205
. But we can continue the discussion after this is merged just as well and in the meantime have an improvement upstream.
7a425c2
to
e2e5e03
Compare
Contribution description
This avoids the confusion where
coap_get_code()
is used by default because of it's convenient name, but returns different values than those used to build the response.This also converts some unnecessary uses of this function to rather use
coap_get_code_raw()
- when processing the request method, both functions return the same result as the request class is 0.Testing procedure
Should not change any behavior.
Issues/PRs references