From 35119a9d3750bf786e841c25a46cd59ea2117462 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sat, 20 Jul 2024 19:37:39 +0200 Subject: wip --- modules/core/c++/buffer.hpp | 17 +++++++++++++++++ modules/core/c++/common.hpp | 4 ++++ 2 files changed, 21 insertions(+) (limited to 'modules/core/c++') diff --git a/modules/core/c++/buffer.hpp b/modules/core/c++/buffer.hpp index f62e7ad..87c54a6 100644 --- a/modules/core/c++/buffer.hpp +++ b/modules/core/c++/buffer.hpp @@ -194,5 +194,22 @@ public: const uint8_t &write(size_t i = 0) const override; error write_require_length(size_t bytes) override; + + /** + */ + error_or extract_front(uint64_t size) { + if(buffer_.empty()){ + return make_error("Chain Array buffer is empty."); + } + + auto& arr_front = buffer_.front(); + if(size != arr_front.size()){ + return make_error("Can't extract array buffer. Size doesn't match. Use view and copy."); + } + + auto arr = std::move(buffer_.front()); + buffer_.pop_front(); + return std::move(arr); + } }; } // namespace saw diff --git a/modules/core/c++/common.hpp b/modules/core/c++/common.hpp index ebca498..f63c531 100644 --- a/modules/core/c++/common.hpp +++ b/modules/core/c++/common.hpp @@ -46,6 +46,10 @@ private: T* ptr_; public: + ptr(): + ptr_{nullptr} + {} + ptr(T& ptr__): ptr_{&ptr__} {} -- cgit v1.2.3