Skip to content

Commit

Permalink
Merge pull request #20004 from benpicco/coap_get_code_decimal
Browse files Browse the repository at this point in the history
nanocoap: rename coap_get_code() -> coap_get_code_decimal()
  • Loading branch information
benpicco authored Nov 28, 2023
2 parents 7790f85 + e2e5e03 commit a36817c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static inline unsigned coap_get_code_detail(const coap_pkt_t *pkt)
*
* @returns message code in decimal format
*/
static inline unsigned coap_get_code(const coap_pkt_t *pkt)
static inline unsigned coap_get_code_decimal(const coap_pkt_t *pkt)
{
return (coap_get_code_class(pkt) * 100) + coap_get_code_detail(pkt);
}
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/nanocoap/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
}

state = STATE_RESPONSE_OK;
DEBUG("nanocoap: response code=%i\n", coap_get_code(pkt));
DEBUG("nanocoap: response code=%i\n", coap_get_code_decimal(pkt));
switch (coap_get_type(pkt)) {
case COAP_TYPE_RST:
/* TODO: handle different? */
Expand Down
10 changes: 5 additions & 5 deletions tests/unittests/tests-gcoap/tests-gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(CONFIG_GCOAP_TOKENLEN, coap_get_token_len(&pdu));
TEST_ASSERT_EQUAL_INT(hdr_fixed_len + CONFIG_GCOAP_TOKENLEN,
coap_get_total_hdr_len(&pdu));
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(1, pdu.payload_len);
TEST_ASSERT_EQUAL_INT('1', (char)*pdu.payload);
}
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_CON, coap_get_type(&pdu));
TEST_ASSERT_EQUAL_INT(0, coap_get_token_len(&pdu));

Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(2, coap_get_token_len(&pdu));
TEST_ASSERT_EQUAL_INT(4 + 2, coap_get_total_hdr_len(&pdu));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pdu));
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_CON, coap_get_type(&pdu));
}

Expand Down
12 changes: 6 additions & 6 deletions tests/unittests/tests-nanocoap/tests-nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void test_nanocoap__get_req(void)

coap_pkt_init(&pkt, &buf[0], sizeof(buf), len);

TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code(&pkt));
TEST_ASSERT_EQUAL_INT(COAP_METHOD_GET, coap_get_code_decimal(&pkt));
TEST_ASSERT_EQUAL_INT(2, coap_get_token_len(&pkt));
TEST_ASSERT_EQUAL_INT(total_hdr_len, coap_get_total_hdr_len(&pkt));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pkt));
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(122, pkt.payload_len);

len = coap_opt_add_string(&pkt, COAP_OPT_URI_PATH, &path[0], '/');
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(2, coap_get_token_len(&pkt));
TEST_ASSERT_EQUAL_INT(4 + 2, coap_get_total_hdr_len(&pkt));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_NON, coap_get_type(&pkt));
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(COAP_TYPE_CON, coap_get_type(&pkt));
}

Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(23, coap_get_id(&pkt));
TEST_ASSERT_EQUAL_INT(strlen(token), coap_get_token_len(&pkt));
TEST_ASSERT_EQUAL_INT(0, memcmp(coap_get_token(&pkt), token, strlen(token)));
Expand Down Expand Up @@ -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));
TEST_ASSERT_EQUAL_INT(23, coap_get_id(&pkt));
TEST_ASSERT_EQUAL_INT(strlen(token), coap_get_token_len(&pkt));
TEST_ASSERT_EQUAL_INT(0, memcmp(coap_get_token(&pkt), token, strlen(token)));
Expand Down

0 comments on commit a36817c

Please sign in to comment.