UniRec  2.9.3
Macros | Functions | Variables
UniRec templates and fields

Macros

#define ur_template_string(tmplt)   ur_template_string_delimiter(tmplt, ',')
 Get string of a template Get names and sizes of fields separated by comma. Return string has to be freed by user. More...
 
#define ur_size_of(type)   ur_field_type_size[type]
 Get size of UniRec type Get size of fixed-length UniRec type. For variable-length type return value < 0. More...
 
#define ur_get_name(field_id)   ur_field_specs.ur_field_names[field_id]
 Get name of UniRec field Get name of any UniRec defined field. More...
 
#define ur_get_type(field_id)   ur_field_specs.ur_field_types[field_id]
 Get type of UniRec field Get type of any UniRec defined field. More...
 
#define ur_get_size(field_id)   ur_field_specs.ur_field_sizes[field_id]
 Get size of UniRec field Get size of a fixed-length UniRec field. When variable-length field is passed, return value < 0. To get real length of a variable-length field use ur_get_var_len. More...
 
#define ur_get(tmplt, data, field_id)   (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]))
 Get value of UniRec field Get value of a fixed-length UniRec field. For variable-length fields, use ur_get_ptr or ur_get_ptr_by_id. More...
 
#define ur_get_ptr(tmplt, data, field_id)
 Get pointer to UniRec field Get pointer to fixed or varible length statically defined UniRec field. For dynamically defined fields, use ur_get_ptr_by_id. More...
 
#define ur_get_ptr_by_id(tmplt, data, field_id)
 Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_get_ptr, field_id may be a variable (not only F_ token). Returned pointer is always void *. More...
 
#define ur_set(tmplt, data, field_id, value)   (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]) = (value))
 Set value of UniRec (static) field Set value of a fixed-length UniRec field. For variable-length fields, use ur_set_var. More...
 
#define ur_get_var_offset(tmplt, rec, field_id)   *((uint16_t *)((char *) rec + tmplt->offset[field_id]))
 Get offset of variable-length field in the record. Get offset of a specified variable-length field in the record. Given field has to be part of the record. More...
 
#define ur_get_var_len(tmplt, rec, field_id)   *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2))
 Get size of a variable sized field in the record. Get size of a variable-length field in the record. Given field has to be part of the record. More...
 
#define ur_set_var_len(tmplt, rec, field_id, len)   *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) = (uint16_t) len
 Set size of variable-length field in the record. Set size of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record. More...
 
#define ur_set_var_offset(tmplt, rec, field_id, offset_val)   *((uint16_t *)((char *) rec + tmplt->offset[field_id])) = (uint16_t) offset_val
 Set offset of variable-length field in the record. Set offset of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record. More...
 
#define ur_get_len(tmplt, rec, field)   ur_is_static(field) ? ur_get_size(field) : ur_get_var_len(tmplt, rec, field)
 Get length of UniRec field Get actual length of fixed or variable-length UniRec field. More...
 
#define ur_set_string(tmplt, rec, field_id, str)   ur_set_var(tmplt, rec, field_id, str, strlen(str))
 Set variable-length field to given string. Set contents of a variable-length field in the record. Field has to be part of the record. It copies string terminated with \0 and safely moves other variable-length records. More...
 
#define ur_is_array(field_id)   (ur_field_type_size[ur_get_type(field_id)] < 0 ? 1 : 0)
 
#define ur_array_get_elem_size(field_id)   (ur_field_type_size[ur_get_type(field_id)] < 0 ? -ur_field_type_size[ur_get_type(field_id)] : ur_field_type_size[ur_get_type(field_id)])
 Get size of a single element of UniRec field. More...
 
#define ur_array_get_elem_cnt(tmplt, rec, field_id)   (ur_get_var_len(tmplt, rec, field_id) / ur_array_get_elem_size(field_id))
 Get number of elements stored in an UniRec array. More...
 
#define ur_array_get_elem_type(field_id)   ur_field_array_elem_type[ur_get_type(field_id)]
 Get type of an element stored in an UniRec array. More...
 
#define ur_array_set(tmplt, rec, field_id, index, element)
 Set element to array at given index. Automatically resizes array when index is out of array bounds. Set contents of a variable-length field in the record. Field has to be part of the record. More...
 
#define ur_array_append(tmplt, rec, field_id, element)
 Set element to array at last position. Automatically resizes array. More...
 
#define ur_array_clear(tmplt, rec, field_id)   ur_array_resize(tmplt, rec, field_id, 0)
 Clear contents of an UniRec array. Array is resized to 0 elements. More...
 
#define ur_array_get(tmplt, rec, field_id, index)   ((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index]
 Get element of an array field at given index. More...
 
#define ur_array_allocate(tmplt, rec, field_id, elem_cnt)   ur_array_resize(tmplt, rec, field_id, (elem_cnt) * ur_array_get_elem_size(field_id))
 Preallocates UniRec array field to have requested number of elements. More...
 
#define ur_is_present(tmplt, field_id)   ((tmplt)->offset_size > (field_id) && (tmplt)->offset[(field_id)] != UR_INVALID_OFFSET)
 Is given field present in given template? Return true (non-zero value) if given template contains field with given ID. More...
 
#define ur_is_varlen(field_id)   (ur_field_specs.ur_field_sizes[field_id] < 0)
 Is given field variable-length? Return true (non-zero value) if given ID refers to a field with variable length. More...
 
#define ur_is_dynamic(field_id)   ur_is_varlen(field_id)
 Alias for ur_is_varlen (for backwards compatibility only) More...
 
#define ur_is_fixlen(field_id)   (ur_field_specs.ur_field_sizes[field_id] >= 0)
 Is given field fixed-length? Return true (non-zero value) if given ID refers to a field with fixed length. More...
 
#define ur_is_static(field_id)   ur_is_fixlen(field_id)
 Alias for ur_is_fixlen (for backwards compatibility only) More...
 
#define ur_rec_fixlen_size(tmplt)   ((tmplt)->static_size)
 Get size of fixed-length part of UniRec record Get total size of UniRec record except variable-length fields. More...
 
#define ur_rec_size(tmplt, rec)   (ur_rec_fixlen_size(tmplt) + ur_rec_varlen_size(tmplt, rec))
 Get size of UniRec record (static and variable length) Get total size of whole UniRec record. More...
 
#define ur_create_input_template(ifc, fields, errstr)   ur_ctx_create_input_template(trap_get_global_ctx(), ifc, fields, errstr);
 Create UniRec template and set it to input interface Creates UniRec template (same like ur_create_template) and set this template to input interface of a module. More...
 
#define ur_create_output_template(ifc, fields, errstr)   ur_ctx_create_output_template(trap_get_global_ctx(), ifc, fields, errstr);
 Create UniRec template and set it to output interface Creates UniRec template (same like ur_create_template) and set this template to ouput interface of a module. More...
 
#define ur_set_output_template(ifc, tmplt)   ur_ctx_set_output_template(trap_get_global_ctx(), ifc, tmplt)
 Set UniRec template to ouput interface. More...
 
#define ur_set_input_template(ifc, tmplt)   ur_ctx_set_input_template(trap_get_global_ctx(), ifc, tmplt)
 Set UniRec template to input interface. More...
 
#define ur_create_bidirectional_template(ifc_in, ifc_out, fields, errstr)   ur_ctx_create_bidirectional_template(trap_get_global_ctx(), ifc_in, ifc_out, fields, errstr);
 Create UniRec template and set it to input and output interface Creates UniRec template (same like ur_create_template) and set this template to input and ouput interface of a module. More...
 
#define UR_MAX_SIZE   0xffff
 
#define ur_cpy(tmplt, src, dst)   (memcpy(dst,src,ur_rec_size(tmplt,src)))
 Copy data from one UniRec to another. Procedure gets template and void pointer of source and destination. Then it copies the data defined by the given template. The destination pointer must have required space allocated. More...
 
#define ur_values_get_name(field, value)   ur_values_get_name_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)
 Returns name of specified value This function returns name of specified value and field, which is defined in values file. More...
 
#define ur_values_get_description(field, value)   ur_values_get_description_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)
 Returns description of specified value This function returns description of specified value and field, which is defined in values file. More...
 

Functions

char * ur_template_string_delimiter (const ur_template_t *tmplt, int delimiter)
 Get UniRec specifier of the tmplt template with delimiter between fields. More...
 
int ur_get_field_type_from_str (const char *type)
 
char * ur_array_append_get_ptr (const ur_template_t *tmplt, void *rec, int field_id)
 Allocate new element at the end of array and return its pointer. More...
 
int ur_init (ur_static_field_specs_t field_specs_static)
 Initialize UniRec structures Initialize UniRec structures. Function is called during defining first own field. More...
 
int ur_get_empty_id ()
 Return first empty id for new UniRec field Return first empty id for new UniRec field. If there is no space in the UniRec structures, it will increase space in the existing structures. More...
 
int ur_define_field (const char *name, ur_field_type_t type)
 Define new UniRec field Define new UniRec field at run-time. It adds new field into existing structures. If the field already exists (name and type are equal) it only returns its ID. More...
 
int ur_define_set_of_fields (const char *ifc_data_fmt)
 Define set of new UniRec fields Define new UniRec fields at run-time. It adds new fields into existing structures. If the field already exists and type is equal nothing will happen. If the type is not equal an error will be returned. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2". More...
 
int ur_undefine_field_by_id (ur_field_id_t field_id)
 Undefine UniRec field by its id Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated. More...
 
int ur_undefine_field (const char *name)
 Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated. More...
 
void ur_finalize ()
 Deallocate UniRec structures Deallocate UniRec structures at the end of a program. This function SHOULD be called after all UniRec functions and macros invocations, typically during a cleanup phase before the program's end. This function has to be called if some fields are defined during run-time, otherwise this function is needless. More...
 
int ur_get_id_by_name (const char *name)
 Get ID of a field by its name Get ID of a field by its name. More...
 
int compare_fields (const void *field1, const void *field2)
 Compare fields Compare two fields. This function is for sorting the fields in the right order. First by sizes (larger first) and then by names. More...
 
ur_template_tur_create_template (const char *fields, char **errstr)
 Create UniRec template Create new UniRec template specified by a string containing names of its fields separated by commas. Example spec-string: "SRC_IP,DST_IP,SRC_PORT,DST_PORT,PROTOCOL,PACKETS" Order of fields is not important (templates with the same set of fields are equivalent). Template created by this function should be destroyed by ur_free_template. More...
 
ur_template_tur_ctx_create_output_template (trap_ctx_t *ctx, int ifc, const char *fields, char **errstr)
 Create UniRec template and set it to output interface on specified context Creates UniRec template, same like ur_create_output_template, but context is specified. More...
 
ur_template_tur_ctx_create_input_template (trap_ctx_t *ctx, int ifc, const char *fields, char **errstr)
 Create UniRec template and set it to input interface on specified context Creates UniRec template, same like ur_create_input_template, but context is specified. More...
 
int ur_ctx_set_output_template (trap_ctx_t *ctx, int ifc, ur_template_t *tmplt)
 Set UniRec template to ouput interface on specified context. More...
 
int ur_ctx_set_input_template (trap_ctx_t *ctx, int ifc, ur_template_t *tmplt)
 Set UniRec template to input interface on specified context. More...
 
ur_template_tur_ctx_create_bidirectional_template (trap_ctx_t *ctx, int ifc_in, int ifc_out, const char *fields, char **errstr)
 Create UniRec template and set it to input and output interface on specified context Creates UniRec template, same like ur_create_bidirectional_template, but context is specified. More...
 
ur_template_tur_expand_template (const char *ifc_data_fmt, ur_template_t *tmplt)
 Expand UniRec template Expand existing UniRec template by a string containing types and names of its fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned. More...
 
ur_template_tur_define_fields_and_update_template (const char *ifc_data_fmt, ur_template_t *tmplt)
 Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields) and create new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned. More...
 
ur_template_tur_create_template_from_ifc_spec (const char *ifc_data_fmt)
 Create UniRec template from data format string. Creates new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent).. More...
 
void ur_free_template (ur_template_t *tmplt)
 Destroy UniRec template Free all memory allocated for a template created previously by ur_create_template. More...
 
int ur_template_compare (const ur_template_t *tmpltA, const ur_template_t *tmpltB)
 Compares fields of two UniRec templates Function compares only sets of UniRec fields (direction is not compared). More...
 
void ur_print_template (ur_template_t *tmplt)
 Print UniRec template Print static_size, first_dynamic and table of offsets to stdout (for debugging). If template does not contain any dynamic fields, print '-' instead. param[in] tmplt pointer to the template. More...
 
int ur_set_var (const ur_template_t *tmplt, void *rec, int field_id, const void *val_ptr, int val_len)
 Set content of variable-length UniRec field Copy given data into variable-length UniRec field, set its offset and length in a record and move data which are behind this field. For better performance use function ur_clear_varlen, before setting all variable fields in record. More...
 
int ur_array_resize (const ur_template_t *tmplt, void *rec, int field_id, int len)
 Change length of a array field. More...
 
void ur_clear_varlen (const ur_template_t *tmplt, void *rec)
 Clear variable-length part of a record. For better performance of setting content to variable-length fields, use this function before setting of all the variable-length fields. This function will clear all the variable-length fields, so they don't have to be moved in memory during setting of them. More...
 
uint16_t ur_rec_varlen_size (const ur_template_t *tmplt, const void *rec)
 Get size of variable sized part of UniRec record Get total size of all variable-length fields in an UniRec record. More...
 
void * ur_create_record (const ur_template_t *tmplt, uint16_t max_var_size)
 
void ur_free_record (void *record)
 
char * ur_get_var_as_str (const ur_template_t *tmplt, const void *rec, ur_field_id_t field_id)
 Get variable-length UniRec field as a C string Copy data of a variable-length field from UniRec record and append '\0' character. The function allocates new memory space for the string, it must be freed using free()! More...
 
void ur_copy_fields (const ur_template_t *dst_tmplt, void *dst, const ur_template_t *src_tmplt, const void *src)
 Copy data from one UniRec record to another. Copies all fields present in both templates from src to dst. The function compares src_tmplt and dst_tmplt and for each field present in both templates it sets the value of field in dst to a corresponding value in src. "dst" must point to a memory of enough size. More...
 
void * ur_clone_record (const ur_template_t *tmplt, const void *src)
 Create new UniRec and copy the source UniRec into it. Function creates new UniRec record and fills it with the data given by parameter. More...
 
ur_iter_t ur_iter_fields (const ur_template_t *tmplt, ur_iter_t id)
 Iterate over fields of a template in order of a record This function can be used to iterate over all fields of a given template. It returns ID of the next field present in the template after a given ID. If ID is set to UR_ITER_BEGIN, it returns the first fields. If no more fields are present, UR_ITER_END is returned. Example usage: ur_field_id_t id = UR_ITER_BEGIN while ((id = ur_iter_fields(&tmplt, id)) != UR_ITER_END) { ... } The order of fields is given by the order in which they are defined. More...
 
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 template. It returns n-th ID of a record specified by index. If the return value is UR_ITER_END. The index is higher than count of fields in the template. Example usage: int i = 0; while ((id = ur_iter_fields(&tmplt, i++)) != UR_ITER_END) { ... } The order of fields is given by the order in the record. More...
 
int ur_set_array_from_string (const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v)
 Set value of a UniRec array field. More...
 
int ur_set_from_string (const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v)
 Set value of a UniRec field. More...
 
char * ur_ifc_data_fmt_to_field_names (const char *ifc_data_fmt)
 Parses field names from data format Function parses field names from data format and returns pointer to new allocated string. Example: "type1 name1,type2 name2" => "name1,name2" New string has to be freed by user. More...
 
char * ur_cpy_string (const char *str)
 Duplicates given string. Helper function which returns pointer to duplicated string. New string has to be freed by user. More...
 
const char * ur_values_get_name_start_end (uint32_t start, uint32_t end, int32_t value)
 Returns name of specified value (Helper function) Helper function for ur_values_get_name. This function returns name of specified value and field, which is defined in values file. Function needs start and end index of a field. More...
 
const char * ur_values_get_description_start_end (uint32_t start, uint32_t end, int32_t value)
 Returns description of specified value (Helper function) Helper function for ur_values_get_description. This function returns description of specified value and field, which is defined in values file. Function needs start and end index of a field. More...
 

Variables

const int ur_field_type_size []
 Sizes of UniRec data types. More...
 
const char * ur_field_type_str []
 UniRec data types. More...
 
int ur_field_array_elem_type []
 UniRec array element types. More...
 
ur_field_specs_t ur_field_specs
 Structure that lists UniRec field specifications such as names, types, id. More...
 
ur_static_field_specs_t UR_FIELD_SPECS_STATIC
 Structure that lists staticaly defined UniRec field specifications such as names, types, id (using UR_FIELDS()). More...
 

Detailed Description

Macro Definition Documentation

◆ ur_array_allocate

#define ur_array_allocate (   tmplt,
  rec,
  field_id,
  elem_cnt 
)    ur_array_resize(tmplt, rec, field_id, (elem_cnt) * ur_array_get_elem_size(field_id))

Preallocates UniRec array field to have requested number of elements.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]elem_cntNumber of elements to be in resized array.
Returns
UR_OK if there is no problem. UR_E_INVALID_FIELD_ID if the ID is not in the template.

Definition at line 629 of file unirec.h.

◆ ur_array_append

#define ur_array_append (   tmplt,
  rec,
  field_id,
  element 
)
Value:
if (ur_array_resize(tmplt, rec, field_id, (ur_array_get_elem_cnt(tmplt, rec, field_id) + 1) * ur_array_get_elem_size(field_id)) == UR_OK) { \
(((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[ur_array_get_elem_cnt(tmplt, rec, field_id) - 1] = (element)); \
}
#define ur_get_ptr_by_id(tmplt, data, field_id)
Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_ge...
Definition: unirec.h:442
#define UR_OK
No problem.
Definition: unirec.h:90
void * rec
#define ur_array_get_elem_size(field_id)
Get size of a single element of UniRec field.
Definition: unirec.h:535
#define ur_array_get_elem_cnt(tmplt, rec, field_id)
Get number of elements stored in an UniRec array.
Definition: unirec.h:546
int ur_array_resize(const ur_template_t *tmplt, void *rec, int field_id, int len)
Change length of a array field.
Definition: unirec.c:1170

Set element to array at last position. Automatically resizes array.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]elementArray element.

Definition at line 581 of file unirec.h.

◆ ur_array_clear

#define ur_array_clear (   tmplt,
  rec,
  field_id 
)    ur_array_resize(tmplt, rec, field_id, 0)

Clear contents of an UniRec array. Array is resized to 0 elements.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
UR_OK if there is no problem. UR_E_INVALID_FIELD_ID if the ID is not in the template.

Definition at line 604 of file unirec.h.

◆ ur_array_get

#define ur_array_get (   tmplt,
  rec,
  field_id,
  index 
)    ((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index]

Get element of an array field at given index.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]indexElement index in array.
[in]elementArray element.
Returns
Specified field in an array.

Definition at line 617 of file unirec.h.

◆ ur_array_get_elem_cnt

#define ur_array_get_elem_cnt (   tmplt,
  rec,
  field_id 
)    (ur_get_var_len(tmplt, rec, field_id) / ur_array_get_elem_size(field_id))

Get number of elements stored in an UniRec array.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
Number of elements stored in an UniRec array field.

Definition at line 546 of file unirec.h.

◆ ur_array_get_elem_size

#define ur_array_get_elem_size (   field_id)    (ur_field_type_size[ur_get_type(field_id)] < 0 ? -ur_field_type_size[ur_get_type(field_id)] : ur_field_type_size[ur_get_type(field_id)])

Get size of a single element of UniRec field.

Parameters
[in]field_idIdentifier of a field.
Returns
Size of a static field or size of a single element in an array field.

Definition at line 535 of file unirec.h.

◆ ur_array_get_elem_type

#define ur_array_get_elem_type (   field_id)    ur_field_array_elem_type[ur_get_type(field_id)]

Get type of an element stored in an UniRec array.

Parameters
[in]field_idIdentifier of a field.
Returns
UR_TYPE_* value.

Definition at line 555 of file unirec.h.

◆ ur_array_set

#define ur_array_set (   tmplt,
  rec,
  field_id,
  index,
  element 
)
Value:
if ((index) * ur_array_get_elem_size(field_id) < ur_get_var_len(tmplt, rec, field_id) || ur_array_resize(tmplt, rec, field_id, (index + 1) * ur_array_get_elem_size(field_id)) == UR_OK) { \
(((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index] = (element)); \
}
#define ur_get_ptr_by_id(tmplt, data, field_id)
Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_ge...
Definition: unirec.h:442
#define UR_OK
No problem.
Definition: unirec.h:90
void * rec
#define ur_array_get_elem_size(field_id)
Get size of a single element of UniRec field.
Definition: unirec.h:535
#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...
Definition: unirec.h:474
int ur_array_resize(const ur_template_t *tmplt, void *rec, int field_id, int len)
Change length of a array field.
Definition: unirec.c:1170

Set element to array at given index. Automatically resizes array when index is out of array bounds. Set contents of a variable-length field in the record. Field has to be part of the record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]indexElement index in array.
[in]elementArray element.

Definition at line 568 of file unirec.h.

◆ ur_cpy

#define ur_cpy (   tmplt,
  src,
  dst 
)    (memcpy(dst,src,ur_rec_size(tmplt,src)))

Copy data from one UniRec to another. Procedure gets template and void pointer of source and destination. Then it copies the data defined by the given template. The destination pointer must have required space allocated.

Parameters
[in]tmpltPointer to UniRec template
[in]srcPointer to source data
[out]dstPointer to destination of copy

Definition at line 1056 of file unirec.h.

◆ ur_create_bidirectional_template

#define ur_create_bidirectional_template (   ifc_in,
  ifc_out,
  fields,
  errstr 
)    ur_ctx_create_bidirectional_template(trap_get_global_ctx(), ifc_in, ifc_out, fields, errstr);

Create UniRec template and set it to input and output interface Creates UniRec template (same like ur_create_template) and set this template to input and ouput interface of a module.

Parameters
[in]ifc_ininput interface number
[in]ifc_outoutput interface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 890 of file unirec.h.

◆ ur_create_input_template

#define ur_create_input_template (   ifc,
  fields,
  errstr 
)    ur_ctx_create_input_template(trap_get_global_ctx(), ifc, fields, errstr);

Create UniRec template and set it to input interface Creates UniRec template (same like ur_create_template) and set this template to input interface of a module.

Parameters
[in]ifcinterface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 793 of file unirec.h.

◆ ur_create_output_template

#define ur_create_output_template (   ifc,
  fields,
  errstr 
)    ur_ctx_create_output_template(trap_get_global_ctx(), ifc, fields, errstr);

Create UniRec template and set it to output interface Creates UniRec template (same like ur_create_template) and set this template to ouput interface of a module.

Parameters
[in]ifcinterface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 806 of file unirec.h.

◆ ur_get

#define ur_get (   tmplt,
  data,
  field_id 
)    (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]))

Get value of UniRec field Get value of a fixed-length UniRec field. For variable-length fields, use ur_get_ptr or ur_get_ptr_by_id.

Parameters
[in]tmpltPointer to UniRec template
[in]dataPointer to the beginning of a record
[in]field_idIdentifier of a field. It must be a token beginning with F_, not a numeric ID (e.g. F_SRC_IP for source IP defined in UR_FIELDS as SRC_IP).
Returns
Value of the field. Data type depends on the type of the field.

Definition at line 418 of file unirec.h.

◆ ur_get_len

#define ur_get_len (   tmplt,
  rec,
  field 
)    ur_is_static(field) ? ur_get_size(field) : ur_get_var_len(tmplt, rec, field)

Get length of UniRec field Get actual length of fixed or variable-length UniRec field.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]fieldIdentifier of a field - e.g. F_SRC_IP for source IP defined in UR_FIELDS as SRC_IP.
Returns
Length of the field in bytes.

Definition at line 506 of file unirec.h.

◆ ur_get_name

#define ur_get_name (   field_id)    ur_field_specs.ur_field_names[field_id]

Get name of UniRec field Get name of any UniRec defined field.

Parameters
[in]field_idID of a field.
Returns
pointer to name (char *).

Definition at line 380 of file unirec.h.

◆ ur_get_ptr

#define ur_get_ptr (   tmplt,
  data,
  field_id 
)
Value:
(field_id ## _T*)((char *) (ur_is_static(field_id) ? ((char *)(data) + (tmplt)->offset[field_id]) : \
(char *)(data) + (tmplt)->static_size + (*((uint16_t *)((char *)(data) + (tmplt)->offset[field_id])))))
#define ur_is_static(field_id)
Alias for ur_is_fixlen (for backwards compatibility only)
Definition: unirec.h:662

Get pointer to UniRec field Get pointer to fixed or varible length statically defined UniRec field. For dynamically defined fields, use ur_get_ptr_by_id.

Parameters
[in]tmpltPointer to UniRec template
[in]dataPointer to the beginning of a record
[in]field_idIdentifier of a field. It must be a token beginning with F_, not a numeric ID.
Returns
Pointer to the field. Pointer type depends on the type of the field.

Definition at line 430 of file unirec.h.

◆ ur_get_ptr_by_id

#define ur_get_ptr_by_id (   tmplt,
  data,
  field_id 
)
Value:
(void *)((char *) (ur_is_static(field_id) ? ((char *)(data) + (tmplt)->offset[field_id]) : \
(char *)(data) + (tmplt)->static_size + (*((uint16_t *)((char *)(data) + (tmplt)->offset[field_id])))))
#define ur_is_static(field_id)
Alias for ur_is_fixlen (for backwards compatibility only)
Definition: unirec.h:662

Get pointer to UniRec field Get pointer to fixed or varible length UniRec field. In contrast to ur_get_ptr, field_id may be a variable (not only F_ token). Returned pointer is always void *.

Parameters
[in]tmpltPointer to UniRec template
[in]dataPointer to the beginning of a record
[in]field_idIdentifier of a field. Token beginning with F_ or a numeric ID.
Returns
Pointer to the field (void *).

Definition at line 442 of file unirec.h.

◆ ur_get_size

#define ur_get_size (   field_id)    ur_field_specs.ur_field_sizes[field_id]

Get size of UniRec field Get size of a fixed-length UniRec field. When variable-length field is passed, return value < 0. To get real length of a variable-length field use ur_get_var_len.

Parameters
[in]field_idID of a field.
Returns
Size of the field in bytes or -1 if the field is variable-length.

Definition at line 405 of file unirec.h.

◆ ur_get_type

#define ur_get_type (   field_id)    ur_field_specs.ur_field_types[field_id]

Get type of UniRec field Get type of any UniRec defined field.

Parameters
[in]field_idID of a field.
Returns
Type of the field (ur_field_type_t).

Definition at line 388 of file unirec.h.

◆ ur_get_var_len

#define ur_get_var_len (   tmplt,
  rec,
  field_id 
)    *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2))

Get size of a variable sized field in the record. Get size of a variable-length field in the record. Given field has to be part of the record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
Length of the field in the record in bytes.

Definition at line 474 of file unirec.h.

◆ ur_get_var_offset

#define ur_get_var_offset (   tmplt,
  rec,
  field_id 
)    *((uint16_t *)((char *) rec + tmplt->offset[field_id]))

Get offset of variable-length field in the record. Get offset of a specified variable-length field in the record. Given field has to be part of the record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
Offset of the field in the record relative to the beginning of the record.

Definition at line 464 of file unirec.h.

◆ ur_is_array

#define ur_is_array (   field_id)    (ur_field_type_size[ur_get_type(field_id)] < 0 ? 1 : 0)

Check if field is an array.

Parameters
[in]field_idIdentifier of a field.
Returns
1 if field is an array, 0 otherwise.

Definition at line 526 of file unirec.h.

◆ ur_is_dynamic

#define ur_is_dynamic (   field_id)    ur_is_varlen(field_id)

Alias for ur_is_varlen (for backwards compatibility only)

Definition at line 650 of file unirec.h.

◆ ur_is_fixlen

#define ur_is_fixlen (   field_id)    (ur_field_specs.ur_field_sizes[field_id] >= 0)

Is given field fixed-length? Return true (non-zero value) if given ID refers to a field with fixed length.

Parameters
[in]field_idIdentifier of a field.
Returns
non-zero if field is fixed-length, zero otherwise

Definition at line 658 of file unirec.h.

◆ ur_is_present

#define ur_is_present (   tmplt,
  field_id 
)    ((tmplt)->offset_size > (field_id) && (tmplt)->offset[(field_id)] != UR_INVALID_OFFSET)

Is given field present in given template? Return true (non-zero value) if given template contains field with given ID.

Parameters
[in]tmpltPointer to UniRec template
[in]field_idIdentifier of a field.
Returns
non-zero if field is present, zero otherwise

Definition at line 638 of file unirec.h.

◆ ur_is_static

#define ur_is_static (   field_id)    ur_is_fixlen(field_id)

Alias for ur_is_fixlen (for backwards compatibility only)

Definition at line 662 of file unirec.h.

◆ ur_is_varlen

#define ur_is_varlen (   field_id)    (ur_field_specs.ur_field_sizes[field_id] < 0)

Is given field variable-length? Return true (non-zero value) if given ID refers to a field with variable length.

Parameters
[in]field_idIdentifier of a field.
Returns
non-zero if field is variable-length, zero otherwise

Definition at line 646 of file unirec.h.

◆ UR_MAX_SIZE

#define UR_MAX_SIZE   0xffff

Definition at line 1013 of file unirec.h.

◆ ur_rec_fixlen_size

#define ur_rec_fixlen_size (   tmplt)    ((tmplt)->static_size)

Get size of fixed-length part of UniRec record Get total size of UniRec record except variable-length fields.

Parameters
[in]tmpltPointer to UniRec template
Returns
Size of the static part of UniRec record.

Definition at line 671 of file unirec.h.

◆ ur_rec_size

#define ur_rec_size (   tmplt,
  rec 
)    (ur_rec_fixlen_size(tmplt) + ur_rec_varlen_size(tmplt, rec))

Get size of UniRec record (static and variable length) Get total size of whole UniRec record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
Returns
Size of the UniRec record.

Definition at line 680 of file unirec.h.

◆ ur_set

#define ur_set (   tmplt,
  data,
  field_id,
  value 
)    (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]) = (value))

Set value of UniRec (static) field Set value of a fixed-length UniRec field. For variable-length fields, use ur_set_var.

Parameters
[in]tmpltPointer to UniRec template
[in]dataPointer to the beginning of a record
[in]field_idIdentifier of a field. It must be a token beginning with F_, not a numeric ID.
[in]valueThe value the field should be set to.

Definition at line 454 of file unirec.h.

◆ ur_set_input_template

#define ur_set_input_template (   ifc,
  tmplt 
)    ur_ctx_set_input_template(trap_get_global_ctx(), ifc, tmplt)

Set UniRec template to input interface.

Parameters
[in]ifcinterface number
[in]tmpltpointer to a template
Returns
UR_OK if there is no problem. UR_E_MEMORY if the ID is not in the template.

Definition at line 863 of file unirec.h.

◆ ur_set_output_template

#define ur_set_output_template (   ifc,
  tmplt 
)    ur_ctx_set_output_template(trap_get_global_ctx(), ifc, tmplt)

Set UniRec template to ouput interface.

Parameters
[in]ifcinterface number
[in]tmpltpointer to a template
Returns
UR_OK if there is no problem. UR_E_MEMORY if the ID is not in the template.

Definition at line 847 of file unirec.h.

◆ ur_set_string

#define ur_set_string (   tmplt,
  rec,
  field_id,
  str 
)    ur_set_var(tmplt, rec, field_id, str, strlen(str))

Set variable-length field to given string. Set contents of a variable-length field in the record. Field has to be part of the record. It copies string terminated with \0 and safely moves other variable-length records.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]strString terminated with \0, which will be copied

Definition at line 517 of file unirec.h.

◆ ur_set_var_len

#define ur_set_var_len (   tmplt,
  rec,
  field_id,
  len 
)    *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) = (uint16_t) len

Set size of variable-length field in the record. Set size of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]lenThe value the length should be set to.

Definition at line 485 of file unirec.h.

◆ ur_set_var_offset

#define ur_set_var_offset (   tmplt,
  rec,
  field_id,
  offset_val 
)    *((uint16_t *)((char *) rec + tmplt->offset[field_id])) = (uint16_t) offset_val

Set offset of variable-length field in the record. Set offset of specified variable-length field in the record. Field has to be part of the record. It does not move other variable sized records. It just sets given value to the right position in the record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
[in]offset_valThe value the offset should be set to.

Definition at line 496 of file unirec.h.

◆ ur_size_of

#define ur_size_of (   type)    ur_field_type_size[type]

Get size of UniRec type Get size of fixed-length UniRec type. For variable-length type return value < 0.

Parameters
[in]typeEnum value of type.
Returns
Size of the field in bytes.

Definition at line 372 of file unirec.h.

◆ ur_template_string

#define ur_template_string (   tmplt)    ur_template_string_delimiter(tmplt, ',')

Get string of a template Get names and sizes of fields separated by comma. Return string has to be freed by user.

See also
ur_template_string_delimiter()
Parameters
[in]tmpltPointer to UniRec template
Returns
String containing list of fields and their types.
Note
Caller must free the returned memory.

Definition at line 364 of file unirec.h.

◆ ur_values_get_description

#define ur_values_get_description (   field,
  value 
)    ur_values_get_description_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)

Returns description of specified value This function returns description of specified value and field, which is defined in values file.

Parameters
[in]fieldName of field to search value in
[in]valueValue of an item to find
Returns
Pointer to string or NULL if the value was not found

Definition at line 1186 of file unirec.h.

◆ ur_values_get_name

#define ur_values_get_name (   field,
  value 
)    ur_values_get_name_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)

Returns name of specified value This function returns name of specified value and field, which is defined in values file.

Parameters
[in]fieldName of field to search value in
[in]valueValue of an item to find
Returns
Pointer to string or NULL if the value was not found

Definition at line 1176 of file unirec.h.

Function Documentation

◆ compare_fields()

int compare_fields ( const void *  field1,
const void *  field2 
)

Compare fields Compare two fields. This function is for sorting the fields in the right order. First by sizes (larger first) and then by names.

Parameters
[in]field1Pointer to first field (field_spec_t)
[in]field2Pointer to second field (field_spec_t)
Returns
-1 if f1 should go before f2, 0 if f1 is the same as f2, 1 otherwise

Definition at line 785 of file unirec.c.

◆ ur_array_append_get_ptr()

char* ur_array_append_get_ptr ( const ur_template_t tmplt,
void *  rec,
int  field_id 
)

Allocate new element at the end of array and return its pointer.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
Pointer to allocated element at the end or NULL if allocation failed.

Definition at line 1184 of file unirec.c.

◆ ur_array_resize()

int ur_array_resize ( const ur_template_t tmplt,
void *  rec,
int  field_id,
int  len 
)

Change length of a array field.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record.
[in]field_idIdentifier of a field.
[in]lenLength of the copied data in bytes.
Returns
UR_OK if there is no problem. UR_E_INVALID_FIELD_ID if the ID is not in the template.

Definition at line 1170 of file unirec.c.

◆ ur_clear_varlen()

void ur_clear_varlen ( const ur_template_t tmplt,
void *  rec 
)

Clear variable-length part of a record. For better performance of setting content to variable-length fields, use this function before setting of all the variable-length fields. This function will clear all the variable-length fields, so they don't have to be moved in memory during setting of them.

Parameters
[in]tmpltPointer to UniRec template.
[in]recPointer to the beginning of a record.

Definition at line 1195 of file unirec.c.

◆ ur_clone_record()

void* ur_clone_record ( const ur_template_t tmplt,
const void *  src 
)
inline

Create new UniRec and copy the source UniRec into it. Function creates new UniRec record and fills it with the data given by parameter.

Parameters
[in]tmpltPointer to UniRec template
[in]srcPointer to source data (UniRec record of the same template)
Returns
Pointer to a new UniRec

Definition at line 1243 of file unirec.c.

◆ ur_copy_fields()

void ur_copy_fields ( const ur_template_t dst_tmplt,
void *  dst,
const ur_template_t src_tmplt,
const void *  src 
)

Copy data from one UniRec record to another. Copies all fields present in both templates from src to dst. The function compares src_tmplt and dst_tmplt and for each field present in both templates it sets the value of field in dst to a corresponding value in src. "dst" must point to a memory of enough size.

Parameters
[in]dst_tmpltPointer to destination UniRec template
[in]dstPointer to destination record
[in]src_tmpltPointer to source UniRec template
[in]srcPointer to source record

Definition at line 1253 of file unirec.c.

◆ ur_cpy_string()

char* ur_cpy_string ( const char *  str)

Duplicates given string. Helper function which returns pointer to duplicated string. New string has to be freed by user.

Parameters
[in]strPointer to the string to duplicate
Returns
Pointer to duplicated string on NULL.

Definition at line 1655 of file unirec.c.

◆ ur_create_record()

void* ur_create_record ( const ur_template_t tmplt,
uint16_t  max_var_size 
)

Create UniRec record. Allocate and zero memory for a record with given template. It allocates N+M bytes, where N is the size of static part of the record (inferred from template), and M is the size of variable part (variable-length fields), which must be provided by caller. No more than 65535 bytes is allocated (even if N+M is greater), since this is the maximal possible size of UniRec record.

Parameters
[in]tmpltPointer to UniRec template.
[in]max_var_sizeSize of variable-length part, i.e. sum of lengths of all variable-length fields. If it is not known at the time of record creation, use UR_MAX_SIZE, which allocates enough memory to hold the largest possible UniRec record (65535 bytes). Set to 0 if there are no variable-length fields in the template.

Definition at line 1214 of file unirec.c.

◆ ur_create_template()

ur_template_t* ur_create_template ( const char *  fields,
char **  errstr 
)

Create UniRec template Create new UniRec template specified by a string containing names of its fields separated by commas. Example spec-string: "SRC_IP,DST_IP,SRC_PORT,DST_PORT,PROTOCOL,PACKETS" Order of fields is not important (templates with the same set of fields are equivalent). Template created by this function should be destroyed by ur_free_template.

Parameters
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 900 of file unirec.c.

◆ ur_create_template_from_ifc_spec()

ur_template_t* ur_create_template_from_ifc_spec ( const char *  ifc_data_fmt)

Create UniRec template from data format string. Creates new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent)..

Parameters
[in]ifc_data_fmtString with types and names of fields delimited by commas
Returns
Pointer to the new template or NULL in case of error.

Definition at line 625 of file unirec.c.

◆ ur_ctx_create_bidirectional_template()

ur_template_t* ur_ctx_create_bidirectional_template ( trap_ctx_t *  ctx,
int  ifc_in,
int  ifc_out,
const char *  fields,
char **  errstr 
)

Create UniRec template and set it to input and output interface on specified context Creates UniRec template, same like ur_create_bidirectional_template, but context is specified.

Parameters
[in]ctxspecified context
[in]ifc_ininput interface number
[in]ifc_outoutput interface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 875 of file unirec.c.

◆ ur_ctx_create_input_template()

ur_template_t* ur_ctx_create_input_template ( trap_ctx_t *  ctx,
int  ifc,
const char *  fields,
char **  errstr 
)

Create UniRec template and set it to input interface on specified context Creates UniRec template, same like ur_create_input_template, but context is specified.

Parameters
[in]ctxspecified context
[in]ifcinterface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 798 of file unirec.c.

◆ ur_ctx_create_output_template()

ur_template_t* ur_ctx_create_output_template ( trap_ctx_t *  ctx,
int  ifc,
const char *  fields,
char **  errstr 
)

Create UniRec template and set it to output interface on specified context Creates UniRec template, same like ur_create_output_template, but context is specified.

Parameters
[in]ctxspecified context
[in]ifcinterface number
[in]fieldsString with names of fields delimited by comma
[in]errstrPointer to char * string where the error message will be allocated and written in case of error. NULL if you don't need error message. In case of error, function will allocate string, which has to be freed by user.
Returns
Pointer to newly created template or NULL in case of error.

Definition at line 817 of file unirec.c.

◆ ur_ctx_set_input_template()

int ur_ctx_set_input_template ( trap_ctx_t *  ctx,
int  ifc,
ur_template_t tmplt 
)

Set UniRec template to input interface on specified context.

Parameters
[in]ctxspecified context
[in]ifcinterface number
[in]tmpltpointer to a template
Returns
UR_OK if there is no problem. UR_E_MEMORY if the ID is not in the template.

Definition at line 856 of file unirec.c.

◆ ur_ctx_set_output_template()

int ur_ctx_set_output_template ( trap_ctx_t *  ctx,
int  ifc,
ur_template_t tmplt 
)

Set UniRec template to ouput interface on specified context.

Parameters
[in]ctxspecified context
[in]ifcinterface number
[in]tmpltpointer to a template
Returns
UR_OK if there is no problem. UR_E_MEMORY if the ID is not in the template.

Definition at line 836 of file unirec.c.

◆ ur_define_field()

int ur_define_field ( const char *  name,
ur_field_type_t  type 
)

Define new UniRec field Define new UniRec field at run-time. It adds new field into existing structures. If the field already exists (name and type are equal) it only returns its ID.

Parameters
[in]nameString with name of field.
[in]typeType of field (specified by UR_TYPE_*).
Returns
ID of created or existing field. UR_E_MEMORY if there is an allocation problem. UR_E_INVALID_NAME if the name value is empty. UR_E_TYPE_MISMATCH if the name already exists, but the type is different.

Definition at line 636 of file unirec.c.

◆ ur_define_fields_and_update_template()

ur_template_t* ur_define_fields_and_update_template ( const char *  ifc_data_fmt,
ur_template_t tmplt 
)

Defined new fields and expand an UniRec template Define new fields (function ur_define_set_of_fields) and create new UniRec template (function ur_create_template_from_ifc_spec). The string describing fields contain types and names of fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned.

Parameters
[in]ifc_data_fmtString with types and names of fields delimited by commas
[in]tmpltPointer to an existing template.
Returns
Pointer to the updated template or NULL in case of error.

Definition at line 610 of file unirec.c.

◆ ur_define_set_of_fields()

int ur_define_set_of_fields ( const char *  ifc_data_fmt)

Define set of new UniRec fields Define new UniRec fields at run-time. It adds new fields into existing structures. If the field already exists and type is equal nothing will happen. If the type is not equal an error will be returned. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2".

Parameters
[in]ifc_data_fmtString containing types and names of fields delimited by comma.
Returns
UR_OK on success UR_E_MEMORY if there is an allocation problem. UR_E_INVALID_NAME if the name value is empty. UR_E_INVALID_TYPE if the type does not exist. UR_E_TYPE_MISMATCH if the name already exists, but the type is different.

Definition at line 558 of file unirec.c.

◆ ur_expand_template()

ur_template_t* ur_expand_template ( const char *  ifc_data_fmt,
ur_template_t tmplt 
)

Expand UniRec template Expand existing UniRec template by a string containing types and names of its fields separated by commas. Example ifc_data_fmt: "uint32 FOO,uint8 BAR,float FOO2" Order of fields is not important (templates with the same set of fields are equivalent). In case of success the given template will be destroyed and new template will be returned.

Parameters
[in]ifc_data_fmtString with types and names of fields delimited by commas
[in]tmpltPointer to an existing template.
Returns
Pointer to the updated template or NULL in case of error.

Definition at line 486 of file unirec.c.

◆ ur_finalize()

void ur_finalize ( )

Deallocate UniRec structures Deallocate UniRec structures at the end of a program. This function SHOULD be called after all UniRec functions and macros invocations, typically during a cleanup phase before the program's end. This function has to be called if some fields are defined during run-time, otherwise this function is needless.

Definition at line 734 of file unirec.c.

◆ ur_free_record()

void ur_free_record ( void *  record)

Free UniRec record. Free memory allocated for UniRec record. You can call system free() on the record as well, this function is there just for completeness.

Parameters
[in]recordPointer to the record to free.

Definition at line 1223 of file unirec.c.

◆ ur_free_template()

void ur_free_template ( ur_template_t tmplt)

Destroy UniRec template Free all memory allocated for a template created previously by ur_create_template.

Parameters
[in]tmpltPointer to the template.

Definition at line 1088 of file unirec.c.

◆ ur_get_empty_id()

int ur_get_empty_id ( )

Return first empty id for new UniRec field Return first empty id for new UniRec field. If there is no space in the UniRec structures, it will increase space in the existing structures.

Returns
ID for new field. UR_E_MEMORY (negative value) if there is an allocation problem.

Definition at line 288 of file unirec.c.

◆ ur_get_field_type_from_str()

int ur_get_field_type_from_str ( const char *  type)

Lookup a field type for its textual representation.

Parameters
[in]typeUniRec type in string format, e.g. "ipaddr" or "uint8"
Returns
Index into ur_field_type_str and ur_field_type_size arrays or UR_E_INVALID_TYPE if the type is not found.

Definition at line 355 of file unirec.c.

◆ ur_get_id_by_name()

int ur_get_id_by_name ( const char *  name)

Get ID of a field by its name Get ID of a field by its name.

Parameters
[in]nameString with name of a field.
Returns
ID of a field. UR_E_INVALID_NAME (negative value) if the name is not known.

Definition at line 774 of file unirec.c.

◆ ur_get_var_as_str()

char* ur_get_var_as_str ( const ur_template_t tmplt,
const void *  rec,
ur_field_id_t  field_id 
)

Get variable-length UniRec field as a C string Copy data of a variable-length field from UniRec record and append '\0' character. The function allocates new memory space for the string, it must be freed using free()!

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record
[in]field_idIdentifier of a field.
Returns
Requested field as a string (char *) or NULL on malloc error. It should be freed using free().

Definition at line 1229 of file unirec.c.

◆ ur_ifc_data_fmt_to_field_names()

char* ur_ifc_data_fmt_to_field_names ( const char *  ifc_data_fmt)

Parses field names from data format Function parses field names from data format and returns pointer to new allocated string. Example: "type1 name1,type2 name2" => "name1,name2" New string has to be freed by user.

Parameters
[in]ifc_data_fmtPointer to the string containing data format
Returns
Pointer to string with names of fields

Definition at line 434 of file unirec.c.

◆ ur_init()

int ur_init ( ur_static_field_specs_t  field_specs_static)

Initialize UniRec structures Initialize UniRec structures. Function is called during defining first own field.

Parameters
[in]field_specs_staticStructure of statically-known UniRec fields.
Returns
UR_E_MEMORY if there is an allocation problem, UR_OK otherwise.

Definition at line 206 of file unirec.c.

◆ ur_iter_fields()

ur_iter_t ur_iter_fields ( const ur_template_t tmplt,
ur_iter_t  id 
)

Iterate over fields of a template in order of a record This function can be used to iterate over all fields of a given template. It returns ID of the next field present in the template after a given ID. If ID is set to UR_ITER_BEGIN, it returns the first fields. If no more fields are present, UR_ITER_END is returned. Example usage: ur_field_id_t id = UR_ITER_BEGIN while ((id = ur_iter_fields(&tmplt, id)) != UR_ITER_END) { ... } The order of fields is given by the order in which they are defined.

Parameters
[in]tmpltTemplate to iterate over.
[in]idField ID returned in last iteration or UR_ITER_BEGIN to get first value.
Returns
ID of the next field or UR_ITER_END if no more fields are present.

Definition at line 1286 of file unirec.c.

◆ ur_iter_fields_record_order()

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 template. It returns n-th ID of a record specified by index. If the return value is UR_ITER_END. The index is higher than count of fields in the template. Example usage: int i = 0; while ((id = ur_iter_fields(&tmplt, i++)) != UR_ITER_END) { ... } The order of fields is given by the order in the record.

Parameters
[in]tmpltTemplate to iterate over.
[in]indexField ID returned in last iteration or UR_ITER_BEGIN to get first value.
Returns
Field ID of the next field or UR_ITER_END if no more fields are present.

Definition at line 1306 of file unirec.c.

◆ ur_print_template()

void ur_print_template ( ur_template_t tmplt)

Print UniRec template Print static_size, first_dynamic and table of offsets to stdout (for debugging). If template does not contain any dynamic fields, print '-' instead. param[in] tmplt pointer to the template.

Definition at line 1115 of file unirec.c.

◆ ur_rec_varlen_size()

uint16_t ur_rec_varlen_size ( const ur_template_t tmplt,
const void *  rec 
)

Get size of variable sized part of UniRec record Get total size of all variable-length fields in an UniRec record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the record
Returns
Size of the variable part of UniRec record.

Definition at line 1204 of file unirec.c.

◆ ur_set_array_from_string()

int ur_set_array_from_string ( const ur_template_t tmpl,
void *  data,
ur_field_id_t  f_id,
const char *  v 
)

Set value of a UniRec array field.

Parameters
[in]tmplPointer to UniRec template
[out]dataPointer to the beginning of a record
[in]f_idIdentifier of a field. It must be a constant beginning with UR_, not its numeric value.
[in]vThe value the field should be set to, array of fields with ' ' space delimiter.
Returns
0 on success, non-zero otherwise.

Definition at line 1315 of file unirec.c.

◆ ur_set_from_string()

int ur_set_from_string ( const ur_template_t tmpl,
void *  data,
ur_field_id_t  f_id,
const char *  v 
)

Set value of a UniRec field.

Parameters
[in]tmplPointer to UniRec template
[out]dataPointer to the beginning of a record
[in]f_idIdentifier of a field. It must be a constant beginning with UR_, not its numeric value.
[in]vThe value the field should be set to.
Returns
0 on success, non-zero otherwise.

Definition at line 1487 of file unirec.c.

◆ ur_set_var()

int ur_set_var ( const ur_template_t tmplt,
void *  rec,
int  field_id,
const void *  val_ptr,
int  val_len 
)

Set content of variable-length UniRec field Copy given data into variable-length UniRec field, set its offset and length in a record and move data which are behind this field. For better performance use function ur_clear_varlen, before setting all variable fields in record.

Parameters
[in]tmpltPointer to UniRec template
[in]recPointer to the beginning of a record.
[in]field_idIdentifier of a field.
[in]val_ptrPointer to data which should be copied into the record.
[in]val_lenLength of the copied data in bytes.
Returns
UR_OK if there is no problem. UR_E_INVALID_FIELD_ID if the ID is not in the template.

Definition at line 1152 of file unirec.c.

◆ ur_template_compare()

int ur_template_compare ( const ur_template_t tmpltA,
const ur_template_t tmpltB 
)

Compares fields of two UniRec templates Function compares only sets of UniRec fields (direction is not compared).

Note
Function does not check if arguments are valid UniRec templates. Caller must check validity before calling this function. Return value is undefined when any argument IS NOT a valid UniRec template (i.e. some of its field is redefined, etc).
Parameters
[in]tmpltAPointer to the first template.
[in]tmpltBPointer to the second template.
Returns
Returns non-zero (1) value if templates matches. Otherwise, it returns 0.

Definition at line 1104 of file unirec.c.

◆ ur_template_string_delimiter()

char* ur_template_string_delimiter ( const ur_template_t tmplt,
int  delimiter 
)

Get UniRec specifier of the tmplt template with delimiter between fields.

Get names and sizes of fields separated by given delimiter.

Example:

ipaddr DST_IP,ipaddr SRC_IP
Parameters
[in]tmpltPointer to UniRec template
[in]delimiterDelimiter that is placed between the UniRec fields in the template specifier.
Returns
String containing list of fields and their types.
Note
Caller must free the returned memory.

Definition at line 253 of file unirec.c.

◆ ur_undefine_field()

int ur_undefine_field ( const char *  name)

Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated.

Parameters
[in]nameName of a field.
Returns
UR_E_MEMORY if there is an allocation problem. UR_E_INVALID_PARAMETER if the field was not created at run-time or the field_id does not exist.

Definition at line 720 of file unirec.c.

◆ ur_undefine_field_by_id()

int ur_undefine_field_by_id ( ur_field_id_t  field_id)

Undefine UniRec field by its id Undefine UniRec field created at run-time. It erases given field from UniRec structures and the field ID can be used for another field. By undefining field, all templates which were using the undefined field, has to be recreated.

Parameters
[in]field_idIdentifier of a field.
Returns
UR_E_MEMORY if there is an allocation problem. UR_E_INVALID_PARAMETER if the field was not created at run-time or the field_id does not exist.

Definition at line 695 of file unirec.c.

◆ ur_values_get_description_start_end()

const char* ur_values_get_description_start_end ( uint32_t  start,
uint32_t  end,
int32_t  value 
)

Returns description of specified value (Helper function) Helper function for ur_values_get_description. This function returns description of specified value and field, which is defined in values file. Function needs start and end index of a field.

Parameters
[in]startIndex of first item to search the value in ur_values array
[in]endIndex of last item to search the value in ur_values array
[in]valueValue of an item to find
Returns
Pointer to string or NULL if the value was not found

Definition at line 1676 of file unirec.c.

◆ ur_values_get_name_start_end()

const char* ur_values_get_name_start_end ( uint32_t  start,
uint32_t  end,
int32_t  value 
)

Returns name of specified value (Helper function) Helper function for ur_values_get_name. This function returns name of specified value and field, which is defined in values file. Function needs start and end index of a field.

Parameters
[in]startIndex of first item to search the value in ur_values array
[in]endIndex of last item to search the value in ur_values array
[in]valueValue of an item to find.
Returns
Pointer to string or NULL if the value was not found

Definition at line 1666 of file unirec.c.

Variable Documentation

◆ ur_field_array_elem_type

int ur_field_array_elem_type[]

UniRec array element types.

Used to get type of an array element. Can be indexed using UR_TYPE_*.

UniRec array element types.

Definition at line 168 of file unirec.c.

◆ ur_field_specs

ur_field_specs_t ur_field_specs

Structure that lists UniRec field specifications such as names, types, id.

Definition at line 201 of file unirec.c.

◆ UR_FIELD_SPECS_STATIC

ur_static_field_specs_t UR_FIELD_SPECS_STATIC

Structure that lists staticaly defined UniRec field specifications such as names, types, id (using UR_FIELDS()).

Definition at line 202 of file unirec.c.

◆ ur_field_type_size

const int ur_field_type_size[]

Sizes of UniRec data types.

Data types are defined in the ur_field_type_str array.

Definition at line 94 of file unirec.c.

◆ ur_field_type_str

const char* ur_field_type_str[]

UniRec data types.

Sizes of data types are defined in the ur_field_type_size array.

Definition at line 133 of file unirec.c.