Skip to content
Snippets Groups Projects
Commit c3329bf1 authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

libknot/rdataset: add knot_rdataset_gather()

parent f53b644a
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
#include "libknot/attribute.h"
#include "libknot/rdataset.h"
#include "libknot/errcode.h"
#include "contrib/macros.h"
#include "contrib/mempattern.h"
static knot_rdata_t *rr_seek(knot_rdata_t *d, size_t pos)
......@@ -240,6 +241,36 @@ int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, knot_mm_t *m
return add_rr_at(rrs, rr, rrs->rr_count, mm);
}
_public_
int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, int src_len,
knot_mm_t *mm)
{
if (unlikely(dst == NULL || src == NULL)) {
return KNOT_EINVAL;
}
int size = 0;
for (int i = 0; i < src_len; ++i) {
size += knot_rdata_array_size(knot_rdata_rdlen(src[i]));
}
knot_rdata_t *data = mm_alloc(mm, size);
if (unlikely(data == NULL)) {
return KNOT_ENOMEM;
}
mm_free(mm, dst->data);
dst->rr_count = src_len;
dst->data = data;
for (int i = 0; i < src_len; ++i) {
int len = knot_rdata_array_size(knot_rdata_rdlen(src[i]));
memcpy(data, src[i], len);
data += len;
}
return KNOT_EOK;
}
_public_
int knot_rdataset_reserve(knot_rdataset_t *rrs, size_t size, knot_mm_t *mm)
{
......
......@@ -71,6 +71,16 @@ int knot_rdataset_copy(knot_rdataset_t *dst, const knot_rdataset_t *src, knot_mm
*/
knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *rrs, size_t pos);
/*!
* \brief Makes RRS structure from a list of resource records (in the given order).
* \param dst RRS structure to write into.
* \param src Array of records to copy from.
* \param src_len The number of records to copy.
* \param mm Memory context.
*/
int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, int src_len,
knot_mm_t *mm);
/*!
* \brief Returns size of the structures holding the RR set.
* \param rrs RR array.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment