From 97997b6d0b42c9c3bd85b0a98d5377adb28ced1a Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Tue, 23 Nov 2021 14:56:12 +0100 Subject: [PATCH] buffer_pool: add helper to build byte_buffer from raw payload+len --- lib/include/srsran/common/buffer_pool.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/include/srsran/common/buffer_pool.h b/lib/include/srsran/common/buffer_pool.h index 407ca9201..8e270bc95 100644 --- a/lib/include/srsran/common/buffer_pool.h +++ b/lib/include/srsran/common/buffer_pool.h @@ -178,6 +178,23 @@ inline unique_byte_buffer_t make_byte_buffer(const char* debug_ctxt) noexcept return buffer; } +inline unique_byte_buffer_t make_byte_buffer(const uint8_t* payload, uint32_t len, const char* debug_ctxt) noexcept +{ + std::unique_ptr buffer(new (std::nothrow) byte_buffer_t()); + if (buffer == nullptr) { + srslog::fetch_basic_logger("POOL").error("Failed to allocate byte buffer in %s", debug_ctxt); + } else { + if (buffer->get_tailroom() >= len) { + memcpy(buffer->msg, payload, len); + buffer->N_bytes = len; + } else { + srslog::fetch_basic_logger("POOL").error( + "Failed to create byte buffer in %s. Payload too large (%d > %d)", debug_ctxt, len, buffer->get_tailroom()); + } + } + return buffer; +} + namespace detail { struct byte_buffer_pool_deleter {