net: buf: Add net_buf_simple_clone
Provides a way to clone a net_buf_simple without altering the state of the original buffer. The primary usage scenario is for manipulating a previously allocated PDU inside a buffer without altering the length and offset of the buffer. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
9fdefc7d73
commit
3d201b45f9
2 changed files with 19 additions and 0 deletions
|
@ -153,6 +153,19 @@ static inline void net_buf_simple_reset(struct net_buf_simple *buf)
|
||||||
buf->data = buf->__buf;
|
buf->data = buf->__buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone buffer state, using the same data buffer.
|
||||||
|
*
|
||||||
|
* Initializes a buffer to point to the same data as an existing buffer.
|
||||||
|
* Allows operations on the same data without altering the length and
|
||||||
|
* offset of the original.
|
||||||
|
*
|
||||||
|
* @param original Buffer to clone.
|
||||||
|
* @param clone The new clone.
|
||||||
|
*/
|
||||||
|
void net_buf_simple_clone(const struct net_buf_simple *original,
|
||||||
|
struct net_buf_simple *clone);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prepare data to be added at the end of the buffer
|
* @brief Prepare data to be added at the end of the buffer
|
||||||
*
|
*
|
||||||
|
|
|
@ -760,6 +760,12 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len,
|
||||||
#define NET_BUF_SIMPLE_ASSERT(cond)
|
#define NET_BUF_SIMPLE_ASSERT(cond)
|
||||||
#endif /* CONFIG_NET_BUF_SIMPLE_LOG */
|
#endif /* CONFIG_NET_BUF_SIMPLE_LOG */
|
||||||
|
|
||||||
|
void net_buf_simple_clone(const struct net_buf_simple *original,
|
||||||
|
struct net_buf_simple *clone)
|
||||||
|
{
|
||||||
|
memcpy(clone, original, sizeof(struct net_buf_simple));
|
||||||
|
}
|
||||||
|
|
||||||
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
|
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
|
||||||
{
|
{
|
||||||
u8_t *tail = net_buf_simple_tail(buf);
|
u8_t *tail = net_buf_simple_tail(buf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue