Added a method to bio_writer_t that allows to extract the internal buffer
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
* Copyright (C) 2010 Martin Willi
|
* Copyright (C) 2010 Martin Willi
|
||||||
* Copyright (C) 2010 revosec AG
|
* Copyright (C) 2010 revosec AG
|
||||||
*
|
*
|
||||||
@@ -205,6 +208,15 @@ METHOD(bio_writer_t, get_buf, chunk_t,
|
|||||||
return chunk_create(this->buf.ptr, this->used);
|
return chunk_create(this->buf.ptr, this->used);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(bio_writer_t, extract_buf, chunk_t,
|
||||||
|
private_bio_writer_t *this)
|
||||||
|
{
|
||||||
|
chunk_t buf = get_buf(this);
|
||||||
|
this->buf = chunk_empty;
|
||||||
|
this->used = 0;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(bio_writer_t, destroy, void,
|
METHOD(bio_writer_t, destroy, void,
|
||||||
private_bio_writer_t *this)
|
private_bio_writer_t *this)
|
||||||
{
|
{
|
||||||
@@ -236,6 +248,7 @@ bio_writer_t *bio_writer_create(u_int32_t bufsize)
|
|||||||
.wrap24 = _wrap24,
|
.wrap24 = _wrap24,
|
||||||
.wrap32 = _wrap32,
|
.wrap32 = _wrap32,
|
||||||
.get_buf = _get_buf,
|
.get_buf = _get_buf,
|
||||||
|
.extract_buf = _extract_buf,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.increase = bufsize ? max(bufsize, 4) : 32,
|
.increase = bufsize ? max(bufsize, 4) : 32,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
* Copyright (C) 2010 Martin Willi
|
* Copyright (C) 2010 Martin Willi
|
||||||
* Copyright (C) 2010 revosec AG
|
* Copyright (C) 2010 revosec AG
|
||||||
*
|
*
|
||||||
@@ -27,6 +30,8 @@ typedef struct bio_writer_t bio_writer_t;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffered output generator.
|
* Buffered output generator.
|
||||||
|
*
|
||||||
|
* @note Integers are converted to network byte order before writing.
|
||||||
*/
|
*/
|
||||||
struct bio_writer_t {
|
struct bio_writer_t {
|
||||||
|
|
||||||
@@ -127,6 +132,14 @@ struct bio_writer_t {
|
|||||||
*/
|
*/
|
||||||
chunk_t (*get_buf)(bio_writer_t *this);
|
chunk_t (*get_buf)(bio_writer_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the encoded data buffer and detach it from the writer (resets
|
||||||
|
* the internal buffer).
|
||||||
|
*
|
||||||
|
* @return chunk to internal buffer (has to be freed)
|
||||||
|
*/
|
||||||
|
chunk_t (*extract_buf)(bio_writer_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a bio_writer_t.
|
* Destroy a bio_writer_t.
|
||||||
*/
|
*/
|
||||||
@@ -136,6 +149,9 @@ struct bio_writer_t {
|
|||||||
/**
|
/**
|
||||||
* Create a bio_writer instance.
|
* Create a bio_writer instance.
|
||||||
*
|
*
|
||||||
|
* The size of the internal buffer is increased automatically by bufsize (or a
|
||||||
|
* default if not given) if the initial size does not suffice.
|
||||||
|
*
|
||||||
* @param bufsize initially allocated buffer size
|
* @param bufsize initially allocated buffer size
|
||||||
*/
|
*/
|
||||||
bio_writer_t *bio_writer_create(u_int32_t bufsize);
|
bio_writer_t *bio_writer_create(u_int32_t bufsize);
|
||||||
|
|||||||
Reference in New Issue
Block a user