Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_avro.c File Reference

Avro binary format encoding/decoding with JSON conversion. More...

#include "nilorea/n_avro.h"
#include <string.h>
#include <time.h>
+ Include dependency graph for n_avro.c:

Go to the source code of this file.

Functions

static int avro_decode_bytes_raw (AVRO_READER *reader, unsigned char **out, size_t *out_len)
 helper: read raw bytes with length prefix
 
cJSON * avro_decode_container (const AVRO_SCHEMA *schema, const N_STR *avro_data)
 Decode an Avro container format N_STR into a cJSON array of records.
 
cJSON * avro_decode_datum (AVRO_READER *reader, const AVRO_SCHEMA *schema)
 Decode an Avro binary datum into cJSON according to schema.
 
int avro_decode_long (AVRO_READER *reader, int64_t *value)
 Decode a zig-zag varint from reader into a 64-bit signed integer.
 
static int avro_encode_bytes_raw (N_STR **dest, const unsigned char *data, size_t len)
 helper: encode raw bytes with length prefix
 
N_STRavro_encode_container (const AVRO_SCHEMA *schema, const cJSON *records)
 Encode a cJSON array of records into Avro container format N_STR.
 
int avro_encode_datum (N_STR **dest, const AVRO_SCHEMA *schema, const cJSON *json)
 Encode a cJSON value as Avro binary according to schema.
 
int avro_encode_long (N_STR **dest, int64_t value)
 Encode a 64-bit signed integer as zig-zag varint into N_STR.
 
int avro_file_to_json (const char *avro_filename, const char *schema_filename, const char *json_filename)
 Read an Avro object container file and produce a JSON file using a schema file.
 
static int avro_find_union_branch (const AVRO_SCHEMA *schema, const cJSON *json)
 helper: find which union branch matches a cJSON value
 
int avro_json_to_file (const char *avro_filename, const char *schema_filename, const char *json_filename)
 Write an Avro object container file from a JSON file and schema file.
 
N_STRavro_nstr_avro_to_json (const N_STR *schema_nstr, const N_STR *avro_nstr)
 Convert Avro N_STR to JSON N_STR using schema N_STR (all in-memory)
 
N_STRavro_nstr_json_to_avro (const N_STR *schema_nstr, const N_STR *json_nstr)
 Convert JSON N_STR to Avro N_STR using schema N_STR (all in-memory)
 
void avro_schema_free (AVRO_SCHEMA **schema_ptr)
 Free an Avro schema.
 
AVRO_SCHEMAavro_schema_from_cjson (const cJSON *json)
 Parse an Avro schema from a cJSON object.
 
AVRO_SCHEMAavro_schema_parse (const char *json_str)
 Parse an Avro schema from a JSON string.
 
AVRO_SCHEMAavro_schema_parse_nstr (const N_STR *schema_nstr)
 Parse schema from N_STR.
 
char * avro_schema_to_json (const AVRO_SCHEMA *schema)
 Convert an Avro schema back to JSON string (caller must free)
 
static AVRO_TYPE avro_type_from_string (const char *type_str)
 helper to get AVRO_TYPE from a type name string
 
static const char * avro_type_to_string (AVRO_TYPE type)
 helper to get type name from AVRO_TYPE
 

Detailed Description

Avro binary format encoding/decoding with JSON conversion.

Author
Castagnier Mickael
Version
1.0
Date
11/03/2026

Definition in file n_avro.c.

Function Documentation

◆ avro_decode_bytes_raw()

static int avro_decode_bytes_raw ( AVRO_READER reader,
unsigned char **  out,
size_t *  out_len 
)
static

helper: read raw bytes with length prefix

Definition at line 695 of file n_avro.c.

References __n_assert, avro_decode_long(), AVRO_READER::data, LOG_ERR, Malloc, n_log, AVRO_READER::pos, and AVRO_READER::size.

Referenced by avro_decode_container(), and avro_decode_datum().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avro_encode_bytes_raw()

static int avro_encode_bytes_raw ( N_STR **  dest,
const unsigned char *  data,
size_t  len 
)
static

helper: encode raw bytes with length prefix

Definition at line 425 of file n_avro.c.

References avro_encode_long(), and nstrcat_ex().

Referenced by avro_encode_datum().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avro_find_union_branch()

static int avro_find_union_branch ( const AVRO_SCHEMA schema,
const cJSON *  json 
)
static

helper: find which union branch matches a cJSON value

Definition at line 435 of file n_avro.c.

References AVRO_ARRAY, AVRO_BOOLEAN, AVRO_BYTES, AVRO_DOUBLE, AVRO_ENUM, AVRO_FIXED, AVRO_FLOAT, AVRO_INT, AVRO_LONG, AVRO_MAP, AVRO_NULL, AVRO_RECORD, AVRO_STRING, AVRO_UNION, AVRO_SCHEMA::nb_branches, AVRO_SCHEMA::type, and AVRO_SCHEMA::union_branches.

Referenced by avro_encode_datum().

+ Here is the caller graph for this function:

◆ avro_type_from_string()

static AVRO_TYPE avro_type_from_string ( const char *  type_str)
static

helper to get AVRO_TYPE from a type name string

Definition at line 37 of file n_avro.c.

References AVRO_BOOLEAN, AVRO_BYTES, AVRO_DOUBLE, AVRO_FLOAT, AVRO_INT, AVRO_LONG, AVRO_NULL, and AVRO_STRING.

Referenced by avro_schema_from_cjson().

+ Here is the caller graph for this function:

◆ avro_type_to_string()

static const char * avro_type_to_string ( AVRO_TYPE  type)
static

helper to get type name from AVRO_TYPE

Definition at line 50 of file n_avro.c.

References AVRO_BOOLEAN, AVRO_BYTES, AVRO_DOUBLE, AVRO_FLOAT, AVRO_INT, AVRO_LONG, AVRO_NULL, and AVRO_STRING.

Referenced by avro_schema_to_json().

+ Here is the caller graph for this function: