net: buf: Add net_buf_add_be32 helper

Add helper to add 32-bit big endian data to net_buf and
net_buf_simple.

Change-Id: Ib6359558abcbed824365928327277ad69aa51e99
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-07-15 14:56:36 +03:00
commit 1de77488ae
2 changed files with 33 additions and 0 deletions

View file

@ -162,6 +162,18 @@ void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val);
*/
void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val);
/**
* @brief Add 32-bit value at the end of the buffer
*
* Adds 32-bit value in big endian format at the end of buffer.
* Increments the data length of a buffer to account for more data
* at the end.
*
* @param buf Buffer to update.
* @param val 32-bit value to be added.
*/
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val);
/**
* @brief Push data to the beginning of the buffer.
*
@ -605,6 +617,19 @@ static inline void *net_buf_user_data(struct net_buf *buf)
*/
#define net_buf_add_le32(buf, val) net_buf_simple_add_le32(&(buf)->b, val)
/**
* @def net_buf_add_be32
* @brief Add 32-bit value at the end of the buffer
*
* Adds 32-bit value in big endian format at the end of buffer.
* Increments the data length of a buffer to account for more data
* at the end.
*
* @param buf Buffer to update.
* @param val 32-bit value to be added.
*/
#define net_buf_add_be32(buf, val) net_buf_simple_add_be32(&(buf)->b, val)
/**
* @def net_buf_push
* @brief Push data to the beginning of the buffer.

View file

@ -241,6 +241,14 @@ void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val)
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
}
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val)
{
NET_BUF_DBG("buf %p val %u\n", buf, val);
val = sys_cpu_to_be32(val);
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
}
void *net_buf_simple_push(struct net_buf_simple *buf, size_t len)
{
NET_BUF_DBG("buf %p len %u\n", buf, len);