From 855750c784a391c3a5fe5658c61a67cceb18d676 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Aug 2018 08:20:17 +0200 Subject: [PATCH] util/{Const,Writable}Buffer: add method SetEnd() --- src/util/ConstBuffer.hxx | 13 +++++++++++++ src/util/WritableBuffer.hxx | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/util/ConstBuffer.hxx b/src/util/ConstBuffer.hxx index 74fe297b5..ad795911e 100644 --- a/src/util/ConstBuffer.hxx +++ b/src/util/ConstBuffer.hxx @@ -289,6 +289,19 @@ struct ConstBuffer { size = end() - new_data; data = new_data; } + + /** + * Move the end pointer to the given address (by adjusting the + * size). + */ + void SetEnd(pointer_type new_end) { +#ifndef NDEBUG + assert(IsNull() == (new_end == nullptr)); + assert(new_end >= begin()); +#endif + + size = new_end - data; + } }; #endif diff --git a/src/util/WritableBuffer.hxx b/src/util/WritableBuffer.hxx index 696ae8910..4919d8487 100644 --- a/src/util/WritableBuffer.hxx +++ b/src/util/WritableBuffer.hxx @@ -278,6 +278,19 @@ struct WritableBuffer { size = end() - new_data; data = new_data; } + + /** + * Move the end pointer to the given address (by adjusting the + * size). + */ + void SetEnd(pointer_type new_end) { +#ifndef NDEBUG + assert(IsNull() == (new_end == nullptr)); + assert(new_end >= begin()); +#endif + + size = new_end - data; + } }; #endif