From 622e0a56a6bbcf664552c03d86cd7eeab6e1de29 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 19 Feb 2018 14:01:00 -0800 Subject: [PATCH] ircd::buffer: Add operator+ to compute a new buffer at offset. --- include/ircd/buffer.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/ircd/buffer.h b/include/ircd/buffer.h index e352911f8..b952ef5b2 100644 --- a/include/ircd/buffer.h +++ b/include/ircd/buffer.h @@ -61,6 +61,7 @@ namespace ircd::buffer template size_t size(const buffer &buffer); template const it &data(const buffer &buffer); template size_t consume(buffer &buffer, const size_t &bytes); + template buffer operator+(const buffer &buffer, const size_t &bytes); template it copy(it &dest, const it &stop, const const_buffer &); size_t copy(const mutable_buffer &dst, const const_buffer &src); size_t reverse(const mutable_buffer &dst, const const_buffer &src); @@ -564,6 +565,22 @@ ircd::buffer::copy(it &dest, return ret; } +template +ircd::buffer::buffer +ircd::buffer::operator+(const buffer &buffer, + const size_t &bytes) +{ + const size_t advance + { + std::min(bytes, size(buffer)) + }; + + return + { + begin(buffer) + advance, size(buffer) - advance + }; +} + template size_t ircd::buffer::consume(buffer &buffer,