30 if (urcsv != NULL && *urcsv != NULL) {
31 free((*urcsv)->buffer);
45 int urcsv_value(
char *dst, uint32_t size,
void *ptr,
int type,
int field_len)
53 written = snprintf(p, size,
"%" PRIu8, *(uint8_t*) ptr);
56 written = snprintf(p, size,
"%" PRIu16, *(uint16_t*) ptr);
59 written = snprintf(p, size,
"%" PRIu32, *(uint32_t*) ptr);
62 written = snprintf(p, size,
"%" PRIu64, *(uint64_t*) ptr);
65 written = snprintf(p, size,
"%" PRIi8, *(int8_t*) ptr);
68 written = snprintf(p, size,
"%" PRIi16, *(int16_t*) ptr);
71 written = snprintf(p, size,
"%" PRIi32, *(int32_t*) ptr);
74 written = snprintf(p, size,
"%" PRIi64, *(int64_t*) ptr);
77 written = snprintf(p, size,
"%c", *(
char*) ptr);
80 written = snprintf(p, size,
"%f", *(
float*) ptr);
83 written = snprintf(p, size,
"%f", *(
double*) ptr);
90 written = snprintf(p, size,
"%s", str);
98 written = snprintf(p, size,
"%s", str);
107 strftime(str, 39,
"%FT%T", gmtime(&sec));
108 written = snprintf(p, size,
"%s.%06i", str, usec);
114 strncpy(p,
"0x", size);
117 for (
int i = 0; i < field_len && written < size; i++) {
118 int w = snprintf(p, size - written,
"%02x", ((
unsigned char *) ptr)[i]);
145 while (fs-- && (written < size)) {
159 if (isprint(*data)) {
172 while (fs-- && (written < size)) {
173 int w = snprintf(p, size,
"%02x", *data++);
184 if (written + 2 < size) {
187 for (i = 0; i < elem_cnt; i++) {
188 int w =
urcsv_value(p, size - written, ((
char *) ptr) + i * elem_size, elem_type, array_len);
191 if (written + 1 >= size) {
195 if (i + 1 != elem_cnt) {
212 int i = 0, written = 0;
215 if (urcsv == NULL ||
rec == NULL) {
259 return strdup(urcsv->
buffer);
Definition of UniRec API to create CSV-like representation of UniRec data.
var-len fields (string where only printable characters are expected; '\0' at the end should NOT be in...
#define ur_get_type(field_id)
Get type of UniRec field Get type of any UniRec defined field.
char * urcsv_record(urcsv_t *urcsv, const void *rec)
*uint16_t * ur_get_ptr_by_id(tmplt2, buffer2, new_id))
char * urcsv_header(urcsv_t *urcsv)
INLINE void mac_to_str(const mac_addr_t *addr, char *str)
uint64_t ur_time_t
Type of timestamps used in UniRec Timestamps in UniRec are stored as number of seconds from Unix epoc...
#define ur_time_get_sec(time)
Get number of seconds from ur_time_t.
#define ur_get_len(tmplt, rec, field)
Get length of UniRec field Get actual length of fixed or variable-length UniRec field.
#define ur_array_get_elem_size(field_id)
Get size of a single element of UniRec field.
#define ur_is_present(tmplt, field_id)
Is given field present in given template? Return true (non-zero value) if given template contains fie...
#define UR_ITER_END
Last value in iterating through the fields.
#define ur_get_var_len(tmplt, rec, field_id)
Get size of a variable sized field in the record. Get size of a variable-length field in the record...
int16_t ur_field_id_t
Type of UniRec field identifiers.
#define ur_is_varlen(field_id)
Is given field variable-length? Return true (non-zero value) if given ID refers to a field with varia...
#define ur_array_get_elem_cnt(tmplt, rec, field_id)
Get number of elements stored in an UniRec array.
var-len fields (generic string of bytes)
INLINE void ip_to_str(const ip_addr_t *addr, char *str)
char * ur_template_string_delimiter(const ur_template_t *tmplt, int delimiter)
Get UniRec specifier of the tmplt template with delimiter between fields.
urcsv_t * urcsv_init(ur_template_t *tmplt, char delimiter)
int urcsv_value(char *dst, uint32_t size, void *ptr, int type, int field_len)
#define ur_time_get_usec(time)
Get number of microeconds from ur_time_t.
int urcsv_field(char *dst, uint32_t size, const void *rec, ur_field_type_t id, ur_template_t *tmplt)
UniRec template. It contains a table mapping a field to its position in an UniRec record...
void urcsv_free(urcsv_t **urcsv)
#define ur_array_get_elem_type(field_id)
Get type of an element stored in an UniRec array.
ur_iter_t ur_iter_fields_record_order(const ur_template_t *tmplt, int index)
Iterate over fields of a template This function can be used to iterate over all fields of a given tem...