Source
zbx_uint32_t zbx_service_serialize_event_severities(unsigned char **data, const zbx_vector_ptr_t *event_severities)
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
void zbx_service_serialize(unsigned char **data, size_t *data_alloc, size_t *data_offset, zbx_uint64_t eventid,
int clock, int ns, int value, int severity, const zbx_vector_ptr_t *tags, int suppressed)
{
zbx_uint32_t data_len = 0, *len = NULL;
int i;
unsigned char *ptr;
zbx_serialize_prepare_value(data_len, eventid);
zbx_serialize_prepare_value(data_len, clock);
zbx_serialize_prepare_value(data_len, ns);
zbx_serialize_prepare_value(data_len, value);
zbx_serialize_prepare_value(data_len, severity);
zbx_serialize_prepare_value(data_len, tags->values_num);
zbx_serialize_prepare_value(data_len, suppressed);
if (0 != tags->values_num)
{
len = (zbx_uint32_t *)zbx_malloc(NULL, sizeof(zbx_uint32_t) * 2 * (size_t)tags->values_num);
for (i = 0; i < tags->values_num; i++)
{
zbx_tag_t *tag = (zbx_tag_t *)tags->values[i];
zbx_serialize_prepare_str_len(data_len, tag->tag, len[i * 2]);
zbx_serialize_prepare_str_len(data_len, tag->value, len[i * 2 + 1]);
}
}
if (NULL != *data)
{
while (data_len > *data_alloc - *data_offset)
{
*data_alloc *= 2;
*data = (unsigned char *)zbx_realloc(*data, *data_alloc);
}
}
else
*data = (unsigned char *)zbx_malloc(NULL, (*data_alloc = MAX(1024, data_len)));