net: buf: Add push functions for supported bit-variants

Add push functions for bit-widths supported by add and pull functions.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2019-12-27 17:44:54 +01:00 committed by Johan Hedberg
commit 8d2b9e6fef
2 changed files with 240 additions and 0 deletions

View file

@ -384,6 +384,94 @@ void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val);
*/ */
void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val); void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val);
/**
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le24(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be24(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le32(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be32(struct net_buf_simple *buf, u32_t val);
/**
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le48(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be48(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_le64(struct net_buf_simple *buf, u64_t val);
/**
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in big endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
void net_buf_simple_push_be64(struct net_buf_simple *buf, u64_t val);
/** /**
* @brief Remove data from the beginning of the buffer. * @brief Remove data from the beginning of the buffer.
* *
@ -1409,6 +1497,102 @@ static inline void *net_buf_user_data(const struct net_buf *buf)
*/ */
#define net_buf_push_u8(buf, val) net_buf_simple_push_u8(&(buf)->b, val) #define net_buf_push_u8(buf, val) net_buf_simple_push_u8(&(buf)->b, val)
/**
* @def net_buf_push_le24
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
#define net_buf_push_le24(buf, val) net_buf_simple_push_le24(&(buf)->b, val)
/**
* @def net_buf_push_be24
* @brief Push 24-bit value to the beginning of the buffer
*
* Adds 24-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 24-bit value to be pushed to the buffer.
*/
#define net_buf_push_be24(buf, val) net_buf_simple_push_be24(&(buf)->b, val)
/**
* @def net_buf_push_le32
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
#define net_buf_push_le32(buf, val) net_buf_simple_push_le32(&(buf)->b, val)
/**
* @def net_buf_push_be32
* @brief Push 32-bit value to the beginning of the buffer
*
* Adds 32-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 32-bit value to be pushed to the buffer.
*/
#define net_buf_push_be32(buf, val) net_buf_simple_push_be32(&(buf)->b, val)
/**
* @def net_buf_push_le48
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
#define net_buf_push_le48(buf, val) net_buf_simple_push_le48(&(buf)->b, val)
/**
* @def net_buf_push_be48
* @brief Push 48-bit value to the beginning of the buffer
*
* Adds 48-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 48-bit value to be pushed to the buffer.
*/
#define net_buf_push_be48(buf, val) net_buf_simple_push_be48(&(buf)->b, val)
/**
* @def net_buf_push_le64
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
#define net_buf_push_le64(buf, val) net_buf_simple_push_le64(&(buf)->b, val)
/**
* @def net_buf_push_be64
* @brief Push 64-bit value to the beginning of the buffer
*
* Adds 64-bit value in little endian format to the beginning of the
* buffer.
*
* @param buf Buffer to update.
* @param val 64-bit value to be pushed to the buffer.
*/
#define net_buf_push_be64(buf, val) net_buf_simple_push_be64(&(buf)->b, val)
/** /**
* @def net_buf_pull * @def net_buf_pull
* @brief Remove data from the beginning of the buffer. * @brief Remove data from the beginning of the buffer.

View file

@ -906,6 +906,62 @@ void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val)
*data = val; *data = val;
} }
void net_buf_simple_push_le24(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_le24(val, net_buf_simple_push(buf, 3));
}
void net_buf_simple_push_be24(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_be24(val, net_buf_simple_push(buf, 3));
}
void net_buf_simple_push_le32(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_le32(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_be32(struct net_buf_simple *buf, u32_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
sys_put_be32(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_le48(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_le48(val, net_buf_simple_push(buf, 6));
}
void net_buf_simple_push_be48(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_be48(val, net_buf_simple_push(buf, 6));
}
void net_buf_simple_push_le64(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_le64(val, net_buf_simple_push(buf, sizeof(val)));
}
void net_buf_simple_push_be64(struct net_buf_simple *buf, u64_t val)
{
NET_BUF_SIMPLE_DBG("buf %p val %" PRIu64, buf, val);
sys_put_be64(val, net_buf_simple_push(buf, sizeof(val)));
}
void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len) void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len)
{ {
NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len); NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len);