diff options
Diffstat (limited to 'modules/core')
-rw-r--r-- | modules/core/c++/buffer.hpp | 17 | ||||
-rw-r--r-- | modules/core/c++/common.hpp | 4 |
2 files changed, 21 insertions, 0 deletions
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<array_buffer> extract_front(uint64_t size) { + if(buffer_.empty()){ + return make_error<err::recoverable>("Chain Array buffer is empty."); + } + + auto& arr_front = buffer_.front(); + if(size != arr_front.size()){ + return make_error<err::invalid_state>("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__} {} |