nanocoap: add coap_payload_put_char()
This commit is contained in:
parent
2751708341
commit
e5c20b143d
@ -78,6 +78,7 @@
|
|||||||
#define NET_NANOCOAP_H
|
#define NET_NANOCOAP_H
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -1511,6 +1512,21 @@ static inline void coap_payload_advance_bytes(coap_pkt_t *pkt, size_t len)
|
|||||||
*/
|
*/
|
||||||
ssize_t coap_payload_put_bytes(coap_pkt_t *pkt, const void *data, size_t len);
|
ssize_t coap_payload_put_bytes(coap_pkt_t *pkt, const void *data, size_t len);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add a single character to the payload data of the CoAP request
|
||||||
|
*
|
||||||
|
* This function is used to add single characters to a CoAP payload data. It
|
||||||
|
* checks whether the character can be added to the buffer and ignores if the
|
||||||
|
* payload area is already exhausted.
|
||||||
|
*
|
||||||
|
* @param[out] pkt pkt to add payload to
|
||||||
|
* @param[in] c character to write
|
||||||
|
*
|
||||||
|
* @returns number of payload bytes added on success (always one)
|
||||||
|
* @returns < 0 on error
|
||||||
|
*/
|
||||||
|
ssize_t coap_payload_put_char(coap_pkt_t *pkt, char c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create CoAP reply (convenience function)
|
* @brief Create CoAP reply (convenience function)
|
||||||
*
|
*
|
||||||
|
|||||||
@ -934,6 +934,18 @@ ssize_t coap_payload_put_bytes(coap_pkt_t *pkt, const void *data, size_t len)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t coap_payload_put_char(coap_pkt_t *pkt, char c)
|
||||||
|
{
|
||||||
|
if (pkt->payload_len < 1) {
|
||||||
|
return -ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pkt->payload++ = c;
|
||||||
|
pkt->payload_len--;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
void coap_block_object_init(coap_block1_t *block, size_t blknum, size_t blksize,
|
void coap_block_object_init(coap_block1_t *block, size_t blknum, size_t blksize,
|
||||||
int more)
|
int more)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user