[serialize] Add start_zerocopy()

This commit is contained in:
Behdad Esfahbod 2022-12-01 16:48:22 -07:00
parent a2681c37c1
commit 3843000660
1 changed files with 15 additions and 0 deletions

View File

@ -570,6 +570,21 @@ struct hb_serialize_context_t
return !bool ((errors = (errors | err_type)));
}
bool start_zerocopy (size_t size)
{
if (unlikely (in_error ())) return false;
if (unlikely (size > INT_MAX || this->tail - this->head < ptrdiff_t (size)))
{
err (HB_SERIALIZE_ERROR_OUT_OF_ROOM);
return false;
}
assert (this->current->head == this->head);
this->current->head = this->head = this->tail - size;
return true;
}
template <typename Type>
Type *allocate_size (size_t size, bool clear = true)
{