util/{Const,Writable}Buffer: add method SetEnd()

This commit is contained in:
Max Kellermann 2018-08-21 08:20:17 +02:00
parent 4f2163e76c
commit 855750c784
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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