Commit 934cc322 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Feature: Added a way to push buffers into buffers

parent 71b156af
Pipeline #320 failed with stage
in 12 seconds
......@@ -264,6 +264,22 @@ int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap
return buffer_zerocopy_push_complete(buffer, ret);
}
int buffer_push_buffer(buffer_t *buffer, buffer_t *source)
{
const void *data;
size_t length;
int ret;
if (!buffer || !source)
return -1;
ret = buffer_get_data(source, &data, &length);
if (ret != 0)
return ret;
return buffer_push_data(buffer, data, length);
}
int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request)
{
if (!buffer || !data)
......
......@@ -153,6 +153,15 @@ int buffer_push_printf(buffer_t *buffer, const char *format, ...);
*/
int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap);
/* This pushes the content of another buffer to the end of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* source
* The buffer which's content is to be copied.
*/
int buffer_push_buffer(buffer_t *buffer, buffer_t *source);
/* This requests for a memory buffer that can be pushed to without the need for copy.
* Parameters:
* buffer
......
......@@ -303,6 +303,31 @@ static void test_printf(void)
ctest_test("un-referenced", refobject_unref(a) == 0);
}
static void test_push_buffer(void)
{
buffer_t *a;
buffer_t *b;
const char *pattern = "AABBBCC";
const char *match_a = "AABBBCCAABBBCC";
a = buffer_new_simple();
ctest_test("buffer a created", a != NULL);
b = buffer_new_simple();
ctest_test("buffer b created", b != NULL);
ctest_test("pushed string", buffer_push_string(a, pattern) == 0);
test__compare_to_string(a, "string matches input", pattern);
ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0);
test__compare_to_string(b, "string matches input", pattern);
ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0);
test__compare_to_string(b, "string matches pattern a", match_a);
ctest_test("un-referenced b", refobject_unref(b) == 0);
ctest_test("un-referenced a", refobject_unref(a) == 0);
}
int main (void)
{
ctest_init();
......@@ -322,6 +347,7 @@ int main (void)
test_length();
test_printf();
test_push_buffer();
ctest_fin();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment