From c45d088ae7d8f67f9422abc19562a81307bf78a2 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Fri, 22 Jan 2016 11:43:30 -0800 Subject: Single encode function --- src/core/census/tag_set.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/core/census/tag_set.c b/src/core/census/tag_set.c index f573e909b3..b985eca52b 100644 --- a/src/core/census/tag_set.c +++ b/src/core/census/tag_set.c @@ -453,14 +453,21 @@ static size_t tag_set_encode(const struct tag_set *tags, char *buffer, return ENCODED_HEADER_SIZE + tags->kvm_used; } -size_t census_tag_set_encode_propagated(const census_tag_set *tags, - char *buffer, size_t buf_size) { - return tag_set_encode(&tags->tags[PROPAGATED_TAGS], buffer, buf_size); -} - -size_t census_tag_set_encode_propagated_binary(const census_tag_set *tags, - char *buffer, size_t buf_size) { - return tag_set_encode(&tags->tags[PROPAGATED_BINARY_TAGS], buffer, buf_size); +char *census_tag_set_encode(const census_tag_set *tags, char *buffer, + size_t *buf_size, size_t *bin_buf_size) { + size_t p_buf_size = + tag_set_encode(&tags->tags[PROPAGATED_TAGS], buffer, *buf_size); + if (p_buf_size == 0) { + return NULL; + } + char *b_buffer = buffer + p_buf_size; + *bin_buf_size = tag_set_encode(&tags->tags[PROPAGATED_BINARY_TAGS], b_buffer, + *buf_size - p_buf_size); + if (*bin_buf_size == 0) { + return NULL; + } + *buf_size = p_buf_size; + return b_buffer; } // Decode a tag set. -- cgit v1.2.3