Implement BB_Yield_Blob
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/1345f69f Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/1345f69f Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/1345f69f Branch: refs/heads/master Commit: 1345f69f26fdec9c5845e8ab759b098451ea2c9e Parents: 1357cc1 Author: Nick Wellnhofer <[email protected]> Authored: Mon May 4 17:08:56 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Tue May 5 11:15:12 2015 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/ByteBuf.c | 10 ++++++++++ runtime/core/Clownfish/ByteBuf.cfh | 5 +++++ 2 files changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1345f69f/runtime/core/Clownfish/ByteBuf.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/ByteBuf.c b/runtime/core/Clownfish/ByteBuf.c index 739d764..d7439f5 100644 --- a/runtime/core/Clownfish/ByteBuf.c +++ b/runtime/core/Clownfish/ByteBuf.c @@ -24,6 +24,7 @@ #include "Clownfish/Class.h" #include "Clownfish/ByteBuf.h" +#include "Clownfish/Blob.h" #include "Clownfish/Err.h" #include "Clownfish/Util/Memory.h" @@ -182,6 +183,15 @@ BB_Grow_IMP(ByteBuf *self, size_t size) { return self->buf; } +Blob* +BB_Yield_Blob_IMP(ByteBuf *self) { + Blob *blob = Blob_new_steal(self->buf, self->size); + self->buf = NULL; + self->size = 0; + self->cap = 0; + return blob; +} + int BB_compare(const void *va, const void *vb) { ByteBuf *a = *(ByteBuf**)va; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/1345f69f/runtime/core/Clownfish/ByteBuf.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/ByteBuf.cfh b/runtime/core/Clownfish/ByteBuf.cfh index 65178db..b5aa406 100644 --- a/runtime/core/Clownfish/ByteBuf.cfh +++ b/runtime/core/Clownfish/ByteBuf.cfh @@ -106,6 +106,11 @@ class Clownfish::ByteBuf nickname BB inherits Clownfish::Obj { nullable char* Grow(ByteBuf *self, size_t size); + /** Return the content of the ByteBuf as Blob and clear the ByteBuf. + */ + incremented Blob* + Yield_Blob(ByteBuf *self); + /** Test whether the ByteBuf matches the passed-in bytes. */ bool
