UniRec  3.3.2
unirec.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright (C) 2015 CESNET
10 
11  *
12  * LICENSE TERMS
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in
21  * the documentation and/or other materials provided with the
22  * distribution.
23  * 3. Neither the name of the Company nor the names of its contributors
24  * may be used to endorse or promote products derived from this
25  * software without specific prior written permission.
26  *
27  * ALTERNATIVELY, provided that this notice is retained in full, this
28  * product may be distributed under the terms of the GNU General Public
29  * License (GPL) version 2 or later, in which case the provisions
30  * of the GPL apply INSTEAD OF those given above.
31  *
32  * This software is provided ``as is'', and any express or implied
33  * warranties, including, but not limited to, the implied warranties of
34  * merchantability and fitness for a particular purpose are disclaimed.
35  * In no event shall the company or contributors be liable for any
36  * direct, indirect, incidental, special, exemplary, or consequential
37  * damages (including, but not limited to, procurement of substitute
38  * goods or services; loss of use, data, or profits; or business
39  * interruption) however caused and on any theory of liability, whether
40  * in contract, strict liability, or tort (including negligence or
41  * otherwise) arising in any way out of the use of this software, even
42  * if advised of the possibility of such damage.
43  *
44  */
45 
46 #ifndef _UNIREC2_H_
47 #define _UNIREC2_H_
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #ifndef __STDC_LIMIT_MACROS
54 #define __STDC_LIMIT_MACROS
55 #endif
56 #include <stdint.h>
57 
58 #include "ipaddr.h"
59 #include "macaddr.h"
60 #include "ur_time.h"
61 #include "links.h"
62 #include "ur_values.h"
63 #include <libtrap/trap.h>
64 
65 //General setting
66 #define UR_DEFAULT_LENGTH_OF_TEMPLATE 1024
67 #define UR_DEFAULT_LENGTH_OF_FIELD_NAME 128
68 #define UR_DEFAULT_LENGTH_OF_FIELD_TYPE 16
69 #define UR_INITIAL_SIZE_FIELDS_TABLE 5
70 #define UR_FIELD_ID_MAX INT16_MAX
71 #define UR_FIELDS(...)
72 #define UR_ARRAY_DELIMITER ' '
73 #define UR_ARRAY_ALLOC 10
74 //Iteration constants
75 #define UR_ITER_BEGIN (-1)
76 #define UR_ITER_END INT16_MAX
77 //default values
78 #define UR_INVALID_OFFSET 0xffff
79 #define UR_NO_DYNAMIC_VALUES 0xffff
80 #define UR_UNINITIALIZED 0
81 #define UR_INITIALIZED 1
82 #define UR_INVALID_FIELD ((ur_field_id_t) 0xffff)
83 //return codes
84 #define UR_E_INVALID_PARAMETER -6
85 #define UR_E_INVALID_FIELD_ID -5
86 #define UR_E_TYPE_MISMATCH -4
87 #define UR_E_INVALID_NAME -3
88 #define UR_E_INVALID_TYPE -2
89 #define UR_E_MEMORY -1
90 #define UR_OK 0
91 
92 
94 #define UR_COUNT_OF_TYPES 29
95 typedef enum {
112 
113  // Arrays
128 
129 typedef enum {
135 
136 typedef int16_t ur_field_id_t;
138 
142 typedef struct ur_field_id_linked_list_s ur_field_id_linked_list_t;
145  ur_field_id_linked_list_t *next;
146 };
147 
152 typedef struct {
153  char **ur_field_names;
154  short *ur_field_sizes;
158 
164 typedef struct {
165  char **ur_field_names;
166  short *ur_field_sizes;
174  ur_field_id_linked_list_t * ur_undefine_fields;
175  uint8_t intialized;
177 
182 typedef struct field_spec_s {
183  char *name;
184  int size;
186 } field_spec_t;
187 
191 typedef struct {
192  uint16_t *offset;
193  uint16_t offset_size;
194  int16_t *ids;
195  uint16_t first_dynamic;
196  uint16_t count;
197  uint16_t static_size;
199  uint32_t ifc_out;
200 } ur_template_t;
201 
219 #define TRAP_RECEIVE(ifc_num, data, data_size, tmplt) \
220  TRAP_CTX_RECEIVE(trap_get_global_ctx(), ifc_num, data, data_size, tmplt);
221 
233 #define TRAP_CTX_RECEIVE(ctx, ifc_num, data, data_size, tmplt) __extension__ \
234 ({\
235  int ret = trap_ctx_recv(ctx, ifc_num, &data, &data_size);\
236  if (ret == TRAP_E_FORMAT_CHANGED) {\
237  const char *spec = NULL;\
238  uint8_t data_fmt;\
239  if (trap_ctx_get_data_fmt(ctx, TRAPIFC_INPUT, ifc_num, &data_fmt, &spec) != TRAP_E_OK) {\
240  fprintf(stderr, "Data format was not loaded.\n");\
241  } else {\
242  tmplt = ur_define_fields_and_update_template(spec, tmplt);\
243  if (tmplt == NULL) {\
244  fprintf(stderr, "Template could not be edited.\n");\
245  } else {\
246  if (tmplt->direction == UR_TMPLT_DIRECTION_BI) {\
247  char * spec_cpy = ur_cpy_string(spec);\
248  if (spec_cpy == NULL) {\
249  fprintf(stderr, "Memory allocation problem.\n");\
250  } else {\
251  trap_ctx_set_data_fmt(ctx, tmplt->ifc_out, TRAP_FMT_UNIREC, spec_cpy);\
252  }\
253  }\
254  }\
255  }\
256  }\
257  ret;\
258 })
259 
271 /*#define UNIREC_CTX_CHECK_TEMPLATE (ctx, ret, ifc_num, tmplt, fmt_changed_cmd, fmt_not_compatabile_cmd) __extension__ \
272 ({\
273  if (ret == TRAP_E_OK_FORMAT_CHANGED && trap_ctx_get_in_ifc_state(ctx, ifc_num) == FMT_SUBSET) {\
274  const char *spec = NULL;\
275  uint8_t data_fmt;\
276  if (trap_ctx_get_data_fmt(ctx, TRAPIFC_INPUT, ifc_num, &data_fmt, &spec) != TRAP_E_OK) {\
277  fprintf(stderr, "Data format was not loaded.");\
278  } else {\
279  tmplt = ur_define_fields_and_update_template(spec, tmplt);\
280  if (tmplt == NULL) {\
281  fprintf(stderr, "Template could not be edited");\
282  } else {\
283  if (tmplt->direction == UR_TMPLT_DIRECTION_BI) {\
284  char * spec_cpy = ur_cpy_string(spec);\
285  if (spec_cpy == NULL) {\
286  fprintf(stderr, "Memory allocation problem.");\
287  } else {\
288  trap_ctx_set_data_fmt(ctx, tmplt->ifc_out, TRAP_FMT_UNIREC, spec_cpy);\
289  }\
290  }\
291  trap_ctx_confirm_ifc_state(ctx, ifc_num);\
292  fmt_changed_cmd;
293  }\
294  }\
295  }\
296  ret;\
297 })*/
298 /* libtraphelpers */
302 
314 extern const int ur_field_type_size[];
315 
321 extern const char *ur_field_type_str[];
322 
328 extern int ur_field_array_elem_type[];
329 
334 
339 
354 char *ur_template_string_delimiter(const ur_template_t *tmplt, int delimiter);
355 
364 #define ur_template_string(tmplt) \
365  ur_template_string_delimiter(tmplt, ',')
366 
372 #define ur_size_of(type) \
373  ur_field_type_size[type]
374 
380 #define ur_get_name(field_id) \
381  ur_field_specs.ur_field_names[field_id]
382 
388 #define ur_get_type(field_id) \
389  ur_field_specs.ur_field_types[field_id]
390 
397 int ur_get_field_type_from_str(const char *type);
398 
405 #define ur_get_size(field_id) \
406  ur_field_specs.ur_field_sizes[field_id]
407 
418 #define ur_get(tmplt, data, field_id) \
419  (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]))
420 
430 #define ur_get_ptr(tmplt, data, field_id) \
431  (field_id ## _T*)((char *) (ur_is_static(field_id) ? ((char *)(data) + (tmplt)->offset[field_id]) : \
432  (char *)(data) + (tmplt)->static_size + (*((uint16_t *)((char *)(data) + (tmplt)->offset[field_id])))))
433 
442 #define ur_get_ptr_by_id(tmplt, data, field_id) \
443  (void *)((char *) (ur_is_static(field_id) ? ((char *)(data) + (tmplt)->offset[field_id]) : \
444  (char *)(data) + (tmplt)->static_size + (*((uint16_t *)((char *)(data) + (tmplt)->offset[field_id])))))
445 
454 #define ur_set(tmplt, data, field_id, value) \
455  (*(field_id ## _T*)((char *)(data) + (tmplt)->offset[field_id]) = (value))
456 
464 #define ur_get_var_offset(tmplt, rec, field_id) \
465  *((uint16_t *)((char *) rec + tmplt->offset[field_id]))
466 
474 #define ur_get_var_len(tmplt, rec, field_id) \
475  *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2))
476 
485 #define ur_set_var_len(tmplt, rec, field_id, len) \
486  *((uint16_t *)((char *) rec + tmplt->offset[field_id] + 2)) = (uint16_t) len
487 
496 #define ur_set_var_offset(tmplt, rec, field_id, offset_val) \
497  *((uint16_t *)((char *) rec + tmplt->offset[field_id])) = (uint16_t) offset_val
498 
506 #define ur_get_len(tmplt, rec, field) \
507  ur_is_static(field) ? ur_get_size(field) : ur_get_var_len(tmplt, rec, field)
508 
517 #define ur_set_string(tmplt, rec, field_id, str) \
518  ur_set_var(tmplt, rec, field_id, str, strlen(str))
519 
526 #define ur_is_array(field_id) \
527  (ur_field_type_size[ur_get_type(field_id)] < 0 ? 1 : 0)
528 
535 #define ur_array_get_elem_size(field_id) \
536  (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)])
537 
546 #define ur_array_get_elem_cnt(tmplt, rec, field_id) \
547  (ur_get_var_len(tmplt, rec, field_id) / ur_array_get_elem_size(field_id))
548 
555 #define ur_array_get_elem_type(field_id) \
556  ur_field_array_elem_type[ur_get_type(field_id)]
557 
568 #define ur_array_set(tmplt, rec, field_id, index, element) \
569  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) { \
570  (((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index] = (element)); \
571  }
572 
581 #define ur_array_append(tmplt, rec, field_id, element) \
582  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) { \
583  (((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[ur_array_get_elem_cnt(tmplt, rec, field_id) - 1] = (element)); \
584  }
585 
594 char *ur_array_append_get_ptr(const ur_template_t *tmplt, void *rec, int field_id);
595 
604 #define ur_array_clear(tmplt, rec, field_id) \
605  ur_array_resize(tmplt, rec, field_id, 0)
606 
617 #define ur_array_get(tmplt, rec, field_id, index) \
618  ((field_id ## _T)((char *)(ur_get_ptr_by_id(tmplt, rec, field_id))))[index]
619 
629 #define ur_array_allocate(tmplt, rec, field_id, elem_cnt) \
630  ur_array_resize(tmplt, rec, field_id, (elem_cnt) * ur_array_get_elem_size(field_id))
631 
638 #define ur_is_present(tmplt, field_id) \
639  ((tmplt)->offset_size > (field_id) && (tmplt)->offset[(field_id)] != UR_INVALID_OFFSET)
640 
646 #define ur_is_varlen(field_id) \
647  (ur_field_specs.ur_field_sizes[field_id] < 0)
648 
650 #define ur_is_dynamic(field_id) \
651  ur_is_varlen(field_id)
652 
658 #define ur_is_fixlen(field_id) \
659  (ur_field_specs.ur_field_sizes[field_id] >= 0)
660 
662 #define ur_is_static(field_id) \
663  ur_is_fixlen(field_id)
664 
665 
671 #define ur_rec_fixlen_size(tmplt) \
672  ((tmplt)->static_size)
673 
680 #define ur_rec_size(tmplt, rec) \
681  (ur_rec_fixlen_size(tmplt) + ur_rec_varlen_size(tmplt, rec))
682 
688 int ur_init(ur_static_field_specs_t field_specs_static);
689 
695 int ur_get_empty_id();
696 
707 int ur_define_field(const char *name, ur_field_type_t type);
708 
721 int ur_define_set_of_fields(const char *ifc_data_fmt);
722 
732 
741 int ur_undefine_field(const char *name);
742 
750 void ur_finalize();
751 
757 int ur_get_id_by_name(const char *name);
758 
766 int compare_fields(const void *field1, const void *field2);
767 
781 ur_template_t *ur_create_template(const char *fields, char **errstr);
782 
793 #define ur_create_input_template(ifc, fields, errstr) \
794  ur_ctx_create_input_template(trap_get_global_ctx(), ifc, fields, errstr);
795 
806 #define ur_create_output_template(ifc, fields, errstr) \
807  ur_ctx_create_output_template(trap_get_global_ctx(), ifc, fields, errstr);
808 
819 ur_template_t *ur_ctx_create_output_template(trap_ctx_t *ctx, int ifc, const char *fields, char **errstr);
820 
831 ur_template_t *ur_ctx_create_input_template(trap_ctx_t *ctx, int ifc, const char *fields, char **errstr);
832 
833 
840 int ur_ctx_set_output_template(trap_ctx_t *ctx, int ifc, ur_template_t *tmplt);
841 
847 #define ur_set_output_template(ifc, tmplt) \
848  ur_ctx_set_output_template(trap_get_global_ctx(), ifc, tmplt)
849 
856 int ur_ctx_set_input_template(trap_ctx_t *ctx, int ifc, ur_template_t *tmplt);
857 
863 #define ur_set_input_template(ifc, tmplt) \
864  ur_ctx_set_input_template(trap_get_global_ctx(), ifc, tmplt)
865 
877 ur_template_t *ur_ctx_create_bidirectional_template(trap_ctx_t *ctx, int ifc_in, int ifc_out, const char *fields, char **errstr);
878 
890 #define ur_create_bidirectional_template(ifc_in, ifc_out, fields, errstr) \
891  ur_ctx_create_bidirectional_template(trap_get_global_ctx(), ifc_in, ifc_out, fields, errstr);
892 
904 ur_template_t *ur_expand_template(const char *ifc_data_fmt, ur_template_t *tmplt);
905 
918 ur_template_t *ur_define_fields_and_update_template(const char *ifc_data_fmt, ur_template_t *tmplt);
919 
929 ur_template_t *ur_create_template_from_ifc_spec(const char *ifc_data_fmt);
930 
936 void ur_free_template(ur_template_t *tmplt);
937 
947 int ur_template_compare(const ur_template_t *tmpltA, const ur_template_t *tmpltB);
948 
949 
955 void ur_print_template(ur_template_t *tmplt);
956 
968 int ur_set_var(const ur_template_t *tmplt, void *rec, int field_id, const void *val_ptr, int val_len);
969 
977 int ur_array_resize(const ur_template_t *tmplt, void *rec, int field_id, int len);
978 
986 void ur_clear_varlen(const ur_template_t *tmplt, void *rec);
987 
994 uint16_t ur_rec_varlen_size(const ur_template_t *tmplt, const void *rec);
995 
1012 void *ur_create_record(const ur_template_t *tmplt, uint16_t max_var_size);
1013 #define UR_MAX_SIZE 0xffff
1014 
1020 void ur_free_record(void *record);
1021 
1032 char *ur_get_var_as_str(const ur_template_t *tmplt, const void *rec, ur_field_id_t field_id);
1033 
1045 void ur_copy_fields(const ur_template_t *dst_tmplt, void *dst, const ur_template_t *src_tmplt, const void *src);
1046 
1056 #define ur_cpy(tmplt, src, dst) \
1057  (memcpy(dst,src,ur_rec_size(tmplt,src)))
1058 /*inline void ur_cpy(ur_template_t *tmplt, const void *src, void *dst)
1059 {
1060  memcpy(dst, src, ur_rec_size(tmplt, src));
1061 }*/
1062 
1071 void *ur_clone_record(const ur_template_t *tmplt, const void *src);
1072 
1090 
1107 ur_iter_t ur_iter_fields_record_order(const ur_template_t *tmplt, int index);
1108 
1117 int ur_set_array_from_string(const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v);
1118 
1127 int ur_set_from_string(const ur_template_t *tmpl, void *data, ur_field_id_t f_id, const char *v);
1128 
1137 char *ur_ifc_data_fmt_to_field_names(const char *ifc_data_fmt);
1138 
1145 char *ur_cpy_string(const char *str);
1146 
1156 const char *ur_values_get_name_start_end(uint32_t start, uint32_t end, int32_t value);
1157 
1167 const char *ur_values_get_description_start_end(uint32_t start, uint32_t end, int32_t value);
1168 
1176 #define ur_values_get_name(field, value) \
1177  ur_values_get_name_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)
1178 
1186 #define ur_values_get_description(field, value) \
1187  ur_values_get_description_start_end(UR_TYPE_START_ ## field, UR_TYPE_END_ ## field, value)
1188 /* urtemplate */
1192 
1193 #ifdef __cplusplus
1194 } // extern "C"
1195 #endif
1196 
1197 #endif
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...
Definition: unirec.c:701
void ur_print_template(ur_template_t *tmplt)
Print UniRec template Print static_size, first_dynamic and table of offsets to stdout (for debugging)...
Definition: unirec.c:1121
char * ur_cpy_string(const char *str)
Duplicates given string. Helper function which returns pointer to duplicated string....
Definition: unirec.c:1661
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 ...
Definition: unirec.c:1201
int ur_init(ur_static_field_specs_t field_specs_static)
Initialize UniRec structures Initialize UniRec structures. Function is called during defining first o...
Definition: unirec.c:210
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_descriptio...
Definition: unirec.c:1682
const char * ur_field_type_str[]
UniRec data types.
Definition: unirec.c:137
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 ...
Definition: unirec.c:438
int ur_undefine_field(const char *name)
Undefine UniRec field by its name Undefine UniRec field created at run-time. It erases given field fr...
Definition: unirec.c:726
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)...
Definition: unirec.c:616
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 U...
Definition: unirec.c:1210
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 t...
Definition: unirec.c:881
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:1176
ur_static_field_specs_t UR_FIELD_SPECS_STATIC
Structure that lists staticaly defined UniRec field specifications such as names, types,...
Definition: unirec.c:206
void ur_free_template(ur_template_t *tmplt)
Destroy UniRec template Free all memory allocated for a template created previously by ur_create_temp...
Definition: unirec.c:1094
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.
Definition: unirec.c:1190
void ur_finalize()
Deallocate UniRec structures Deallocate UniRec structures at the end of a program....
Definition: unirec.c:740
void * ur_create_record(const ur_template_t *tmplt, uint16_t max_var_size)
Definition: unirec.c:1220
const int ur_field_type_size[]
Sizes of UniRec data types.
Definition: unirec.c:98
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...
Definition: unirec.c:1312
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 recor...
Definition: unirec.c:1235
ur_field_specs_t ur_field_specs
Structure that lists UniRec field specifications such as names, types, id.
Definition: unirec.c:205
int ur_get_empty_id()
Return first empty id for new UniRec field Return first empty id for new UniRec field....
Definition: unirec.c:292
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.
Definition: unirec.c:862
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.
Definition: unirec.c:842
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 no...
Definition: unirec.c:1110
int ur_field_array_elem_type[]
UniRec array element types.
Definition: unirec.c:172
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...
Definition: unirec.c:1249
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,...
Definition: unirec.c:823
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,...
Definition: unirec.c:804
char * ur_template_string_delimiter(const ur_template_t *tmplt, int delimiter)
Get UniRec specifier of the tmplt template with delimiter between fields.
Definition: unirec.c:257
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 ...
Definition: unirec.c:490
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....
Definition: unirec.c:1672
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,...
Definition: unirec.c:1158
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 existin...
Definition: unirec.c:564
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 ...
Definition: unirec.c:1259
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.
Definition: unirec.c:780
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_templ...
Definition: unirec.c:631
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.
Definition: unirec.c:1321
int ur_get_field_type_from_str(const char *type)
Definition: unirec.c:359
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.
Definition: unirec.c:1493
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 structur...
Definition: unirec.c:642
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 field...
Definition: unirec.c:906
void ur_free_record(void *record)
Definition: unirec.c:1229
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....
Definition: unirec.c:791
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 ...
Definition: unirec.c:1292
Structure to store both IPv4 and IPv6 addresses and associated functions.
Structure to store MAC address and associated functions.
ur_field_type_t
Definition: unirec.h:95
@ UR_TYPE_A_UINT32
unsigned int (32b) array
Definition: unirec.h:118
@ UR_TYPE_UINT64
unsigned int (64b)
Definition: unirec.h:105
@ UR_TYPE_A_UINT16
unsigned int (16b) array
Definition: unirec.h:116
@ UR_TYPE_A_INT64
int (64b) array
Definition: unirec.h:121
@ UR_TYPE_A_DOUBLE
double (64b) array
Definition: unirec.h:123
@ UR_TYPE_A_IP
IP address (128b) array.
Definition: unirec.h:124
@ UR_TYPE_INT16
int (8b)
Definition: unirec.h:102
@ UR_TYPE_A_INT32
int (32b) array
Definition: unirec.h:119
@ UR_TYPE_A_INT8
int (8b) array
Definition: unirec.h:115
@ UR_TYPE_A_INT16
int (8b) array
Definition: unirec.h:117
@ UR_TYPE_IP
IP address (128b)
Definition: unirec.h:109
@ UR_TYPE_INT8
int (8b)
Definition: unirec.h:100
@ UR_TYPE_CHAR
char
Definition: unirec.h:98
@ UR_TYPE_A_UINT8
unsigned int (8b) array
Definition: unirec.h:114
@ UR_TYPE_DOUBLE
double (64b)
Definition: unirec.h:108
@ UR_TYPE_A_FLOAT
float (32b) array
Definition: unirec.h:122
@ UR_TYPE_A_UINT64
unsigned int (64b) array
Definition: unirec.h:120
@ UR_TYPE_A_MAC
MAC address (48b) array.
Definition: unirec.h:125
@ UR_TYPE_TIME
time (64b)
Definition: unirec.h:111
@ UR_TYPE_UINT8
unsigned int (8b)
Definition: unirec.h:99
@ UR_TYPE_INT64
int (64b)
Definition: unirec.h:106
@ UR_TYPE_STRING
var-len fields (string where only printable characters are expected; '\0' at the end should NOT be in...
Definition: unirec.h:96
@ UR_TYPE_A_TIME
time (64b) array
Definition: unirec.h:126
@ UR_TYPE_INT32
int (32b)
Definition: unirec.h:104
@ UR_TYPE_UINT16
unsigned int (16b)
Definition: unirec.h:101
@ UR_TYPE_UINT32
unsigned int (32b)
Definition: unirec.h:103
@ UR_TYPE_MAC
MAC address (48b)
Definition: unirec.h:110
@ UR_TYPE_BYTES
var-len fields (generic string of bytes)
Definition: unirec.h:97
@ UR_TYPE_FLOAT
float (32b)
Definition: unirec.h:107
ur_field_id_t ur_last_id
The highest ID of a field + 1.
Definition: unirec.h:169
ur_tmplt_direction direction
Direction of data input, output, bidirection, no direction.
Definition: unirec.h:198
ur_field_id_t ur_iter_t
Type for identifying iteration id through all fields.
Definition: unirec.h:137
ur_field_id_linked_list_t * next
Pointer to next item in the linked list.
Definition: unirec.h:145
int16_t ur_field_id_t
Type of UniRec field identifiers.
Definition: unirec.h:136
uint8_t intialized
If the UniRec is initialized by function ur_init variable is set to UR_INITIALIZED,...
Definition: unirec.h:175
int size
Size of a field.
Definition: unirec.h:184
ur_field_id_linked_list_t * ur_undefine_fields
linked list of free (undefined) IDs
Definition: unirec.h:174
ur_field_id_t ur_last_statically_defined_id
Last statically defined field by UR_FIELDS(...)
Definition: unirec.h:168
uint16_t count
Count of fields in template.
Definition: unirec.h:196
ur_field_type_t * ur_field_types
Array of types of fields.
Definition: unirec.h:167
char * name
Name of a field.
Definition: unirec.h:183
uint16_t first_dynamic
First dynamic (variable-length) field. Index to the ids array.
Definition: unirec.h:195
uint16_t * offset
Table of offsets.
Definition: unirec.h:192
uint32_t ifc_out
output interface number (stored only if the direction == UR_TMPLT_DIRECTION_BI)
Definition: unirec.h:199
uint16_t static_size
Size of static part.
Definition: unirec.h:197
ur_field_id_t id
ID of a field.
Definition: unirec.h:185
short * ur_field_sizes
Array of sizes of fields.
Definition: unirec.h:154
ur_field_id_t ur_last_id
Last specified ID.
Definition: unirec.h:156
ur_tmplt_direction
Definition: unirec.h:129
@ UR_TMPLT_DIRECTION_IN
input direction
Definition: unirec.h:131
@ UR_TMPLT_DIRECTION_NO
template is not used for sending data
Definition: unirec.h:130
@ UR_TMPLT_DIRECTION_OUT
ouput direction
Definition: unirec.h:132
@ UR_TMPLT_DIRECTION_BI
bidirection
Definition: unirec.h:133
short * ur_field_sizes
Array of sizes of fields.
Definition: unirec.h:166
char ** ur_field_names
Array of names of fields.
Definition: unirec.h:153
char ** ur_field_names
Array of names of fields.
Definition: unirec.h:165
ur_field_id_t id
free id
Definition: unirec.h:144
ur_field_id_t ur_allocated_fields
Definition: unirec.h:173
int16_t * ids
Array of ids in template.
Definition: unirec.h:194
ur_field_type_t * ur_field_types
Array of types of fields.
Definition: unirec.h:155
uint16_t offset_size
size of offset table.
Definition: unirec.h:193
Sorting fields structure This structure is used to sort fields by their size and name....
Definition: unirec.h:182
Linked list for undefined field ids Linked list consisting of field ids, which are freed after operat...
Definition: unirec.h:143
UniRec fields structure It contains all fields which are statically defined by UR_FIELDS(....
Definition: unirec.h:164
UniRec default field list It contains all fields which are specified statically in source code of a m...
Definition: unirec.h:152
UniRec template. It contains a table mapping a field to its position in an UniRec record.
Definition: unirec.h:191
Types, macros and function for UniRec timestamp format.