diff --git a/include/net/buf.h b/include/net/buf.h index 5429d22beac..0e5565b1cce 100644 --- a/include/net/buf.h +++ b/include/net/buf.h @@ -153,6 +153,19 @@ static inline void net_buf_simple_reset(struct net_buf_simple *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 * diff --git a/subsys/net/buf.c b/subsys/net/buf.c index e37e90647d3..6ecf649182f 100644 --- a/subsys/net/buf.c +++ b/subsys/net/buf.c @@ -760,6 +760,12 @@ size_t net_buf_append_bytes(struct net_buf *buf, size_t len, #define NET_BUF_SIMPLE_ASSERT(cond) #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) { u8_t *tail = net_buf_simple_tail(buf);