UniRec  2.9.3
Functions | Variables
example_unirec.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include "fields.c"

Go to the source code of this file.

Functions

 UR_FIELDS (uint32 FOO, uint32 BAR, ipaddr IP, string STR1, string STR2,) int main(int argc
 
 ur_set (tmplt, rec, F_FOO, 12345)
 
 ur_set (tmplt, rec, F_BAR, 54321)
 
 ur_set (tmplt, rec, F_IP, ip_from_int(12345678))
 
 ur_set_string (tmplt, rec, F_STR1, "Hello World!")
 
 memcpy (buffer, rec, ur_rec_size(tmplt, rec))
 
 free (rec)
 
 ur_free_template (tmplt)
 
 printf ("%u %u %u %s\, ur_get(tmplt, buffer, F_FOO), ip_get_v4_as_int(&(ur_get(tmplt, buffer, F_IP))), ur_get_var_len(tmplt, buffer, F_STR1), ur_get_ptr(tmplt, buffer, F_STR1))
 
 if (new_id< 0)
 
 ur_copy_fields (tmplt2, buffer2, tmplt1, buffer)
 
 ur_set_string (tmplt2, buffer2, F_STR2, "The second string")
 
*uint16_t * ur_get_ptr_by_id (tmplt2, buffer2, new_id))
 
 ur_free_template (tmplt1)
 
 ur_free_template (tmplt2)
 
 printf (" new field %d\, new_id)
 
 printf ("%u %u %s %u %s %u\, ur_get(tmplt, buffer2, F_BAR), ur_get_var_len(tmplt, buffer2, F_STR1), ur_get_ptr(tmplt, buffer2, F_STR1), ur_get_var_len(tmplt, buffer2, F_STR2), ur_get_ptr(tmplt, buffer2, F_STR2), *(uint16_t *) ur_get_ptr_by_id(tmplt, buffer2, new_id))
 
 free (buffer)
 
 free (buffer2)
 
 ur_finalize ()
 

Variables

char ** argv
 
void * rec = ur_create_record(tmplt, 512)
 
 buffer = malloc(ur_rec_size(tmplt, rec))
 
ur_template_ttmplt1 = ur_create_template("FOO,BAR,IP,STR1", NULL)
 
ur_template_ttmplt2 = ur_create_template("BAR,STR1,STR2,NEW", NULL)
 
 buffer2 = ur_create_record(tmplt2, ur_get_var_len(tmplt1, buffer, F_STR1) + 64)
 
ur_field_id_t new_id = ur_get_id_by_name("NEW")
 
 return
 

Function Documentation

◆ free() [1/3]

free ( rec  )

◆ free() [2/3]

free ( buffer  )

◆ free() [3/3]

free ( buffer2  )

◆ if()

if ( )

Definition at line 78 of file example_unirec.c.

◆ memcpy()

memcpy ( buffer  ,
rec  ,
ur_rec_size(tmplt, rec  
)

◆ printf() [1/3]

printf ( "%u %u %u %s\  ,
ur_get(tmplt, buffer, F_FOO)  ,
ip_get_v4_as_int(&(ur_get(tmplt, buffer, F_IP)))  ,
ur_get_var_len(tmplt, buffer, F_STR1)  ,
ur_get_ptr(tmplt, buffer, F_STR1)   
)

◆ printf() [2/3]

printf ( " new field %d\  ,
new_id   
)

◆ printf() [3/3]

printf ( "%u %u %s %u %s %u\  ,
ur_get(tmplt, buffer2, F_BAR)  ,
ur_get_var_len(tmplt, buffer2, F_STR1)  ,
ur_get_ptr(tmplt, buffer2, F_STR1)  ,
ur_get_var_len(tmplt, buffer2, F_STR2)  ,
ur_get_ptr(tmplt, buffer2, F_STR2)  ,
uint16_t *) ur_get_ptr_by_id(tmplt, buffer2, new_id 
)

◆ ur_copy_fields()

ur_copy_fields ( tmplt2  ,
buffer2  ,
tmplt1  ,
buffer   
)

◆ UR_FIELDS()

UR_FIELDS ( uint32  FOO,
uint32  BAR,
ipaddr  IP,
string  STR1,
string  STR2 
)

◆ ur_finalize()

ur_finalize ( )

Definition at line 734 of file unirec.c.

◆ ur_free_template() [1/3]

ur_free_template ( tmplt  )

◆ ur_free_template() [2/3]

ur_free_template ( tmplt1  )

◆ ur_free_template() [3/3]

ur_free_template ( tmplt2  )

◆ ur_get_ptr_by_id()

* uint16_t* ur_get_ptr_by_id ( tmplt2  ,
buffer2  ,
new_id   
)

◆ ur_set() [1/3]

ur_set ( tmplt  ,
rec  ,
F_FOO  ,
12345   
)

◆ ur_set() [2/3]

ur_set ( tmplt  ,
rec  ,
F_BAR  ,
54321   
)

◆ ur_set() [3/3]

ur_set ( tmplt  ,
rec  ,
F_IP  ,
ip_from_int(12345678)   
)

◆ ur_set_string() [1/2]

ur_set_string ( tmplt  ,
rec  ,
F_STR1  ,
"Hello World!"   
)

◆ ur_set_string() [2/2]

ur_set_string ( tmplt2  ,
buffer2  ,
F_STR2  ,
"The second string"   
)

Variable Documentation

◆ argv

char** argv
Initial value:
{
char *buffer, *buffer2
buffer
buffer2

Definition at line 26 of file example_unirec.c.

◆ buffer

buffer = malloc(ur_rec_size(tmplt, rec))

Definition at line 43 of file example_unirec.c.

◆ buffer2

buffer2 = ur_create_record(tmplt2, ur_get_var_len(tmplt1, buffer, F_STR1) + 64)

Definition at line 88 of file example_unirec.c.

◆ new_id

Definition at line 115 of file example_unirec.c.

◆ rec

void* rec = ur_create_record(tmplt, 512)

Definition at line 35 of file example_unirec.c.

◆ return

return

Definition at line 135 of file example_unirec.c.

◆ tmplt1

ur_template_t* tmplt1 = ur_create_template("FOO,BAR,IP,STR1", NULL)

Definition at line 84 of file example_unirec.c.

◆ tmplt2

ur_template_t* tmplt2 = ur_create_template("BAR,STR1,STR2,NEW", NULL)

Definition at line 85 of file example_unirec.c.