Skip to content

Commit

Permalink
nanocoap: use void * for payload bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Apr 22, 2022
1 parent d6bcc24 commit e39b510
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ void coap_block_slicer_init(coap_block_slicer_t *slicer, size_t blknum,
* @returns Number of bytes written to @p bufpos
*/
size_t coap_blockwise_put_bytes(coap_block_slicer_t *slicer, uint8_t *bufpos,
const uint8_t *c, size_t len);
const void *c, size_t len);

/**
* @brief Add a single character to a block2 reply.
Expand Down Expand Up @@ -1127,7 +1127,7 @@ static inline ssize_t coap_opt_add_format(coap_pkt_t *pkt, uint16_t format)
* @return <0 on error
* @return -ENOSPC if no available options
*/
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val, size_t val_len);
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const void *val, size_t val_len);

/**
* @brief Adds a single Uri-Query option in the form 'key=value' into pkt
Expand Down Expand Up @@ -1598,7 +1598,7 @@ size_t coap_put_block1_ok(uint8_t *pkt_pos, coap_block1_t *block1, uint16_t last
*
* @returns amount of bytes written to @p buf
*/
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const uint8_t *odata, size_t olen);
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const void *odata, size_t olen);

/**
* @brief Insert block1 option into buffer
Expand Down Expand Up @@ -1865,7 +1865,7 @@ ssize_t coap_reply_simple(coap_pkt_t *pkt,
unsigned code,
uint8_t *buf, size_t len,
unsigned ct,
const uint8_t *payload, uint8_t payload_len);
const void *payload, uint8_t payload_len);

/**
* @brief Reference to the default .well-known/core handler defined by the
Expand Down
12 changes: 6 additions & 6 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ ssize_t coap_reply_simple(coap_pkt_t *pkt,
unsigned code,
uint8_t *buf, size_t len,
unsigned ct,
const uint8_t *payload, uint8_t payload_len)
const void *payload, uint8_t payload_len)
{
uint8_t *payload_start = buf + coap_get_total_hdr_len(pkt);
uint8_t *bufpos = payload_start;
Expand Down Expand Up @@ -687,7 +687,7 @@ static unsigned _put_delta_optlen(uint8_t *buf, unsigned offset, unsigned shift,
return offset;
}

size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const uint8_t *odata, size_t olen)
size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, const void *odata, size_t olen)
{
assert(lastonum <= onum);

Expand Down Expand Up @@ -834,7 +834,7 @@ size_t coap_opt_put_uint(uint8_t *buf, uint16_t lastonum, uint16_t onum,
}

/* Common functionality for addition of an option */
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val,
static ssize_t _add_opt_pkt(coap_pkt_t *pkt, uint16_t optnum, const void *val,
size_t val_len)
{
if (pkt->options_len >= CONFIG_NANOCOAP_NOPTS_MAX) {
Expand Down Expand Up @@ -937,7 +937,7 @@ ssize_t coap_opt_add_uri_query2(coap_pkt_t *pkt, const char *key, size_t key_len
return _add_opt_pkt(pkt, COAP_OPT_URI_QUERY, (uint8_t *)qs, qs_len);
}

ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const uint8_t *val, size_t val_len)
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const void *val, size_t val_len)
{
return _add_opt_pkt(pkt, optnum, val, val_len);
}
Expand Down Expand Up @@ -1158,7 +1158,7 @@ size_t coap_blockwise_put_char(coap_block_slicer_t *slicer, uint8_t *bufpos, cha
}

size_t coap_blockwise_put_bytes(coap_block_slicer_t *slicer, uint8_t *bufpos,
const uint8_t *c, size_t len)
const void *c, size_t len)
{
size_t str_len = 0; /* Length of the string to copy */

Expand All @@ -1181,7 +1181,7 @@ size_t coap_blockwise_put_bytes(coap_block_slicer_t *slicer, uint8_t *bufpos,
}

/* Only copy the relevant part of the string to the buffer */
memcpy(bufpos, c + str_offset, str_len);
memcpy(bufpos, (uint8_t *)c + str_offset, str_len);
slicer->cur += len;
return str_len;
}
Expand Down

0 comments on commit e39b510

Please sign in to comment.