5 Module AVRO
gullradriel edited this page 2026-10-09 00:55:18 +02:00

AVRO: binary format encoding/decoding with JSON conversion

Structures

Name
struct AVRO_SCHEMA
Avro schema definition.
struct AVRO_READER
Avro read cursor for decoding.
struct AVRO_FIELD
Avro schema field (for records).

Types

Name
enum AVRO_TYPE { AVRO_UNION, AVRO_STRING, AVRO_RECORD, AVRO_NULL = 0, AVRO_MAP, AVRO_LONG, AVRO_INT, AVRO_FLOAT, AVRO_FIXED, AVRO_ENUM, AVRO_DOUBLE, AVRO_BYTES, AVRO_BOOLEAN, AVRO_ARRAY}
Avro schema type enumeration.

Functions

Name
char * avro_schema_to_json(const AVRO_SCHEMA * schema)
Convert an Avro schema back to JSON string (caller must free).
AVRO_SCHEMA * avro_schema_parse_nstr(const N_STR * schema_nstr)
Parse schema from N_STR.
AVRO_SCHEMA * avro_schema_parse(const char * json_str)
Parse an Avro schema from a JSON string.
AVRO_SCHEMA * avro_schema_from_cjson(const cJSON * json)
Parse an Avro schema from a cJSON object.
void avro_schema_free(AVRO_SCHEMA ** schema)
Free an Avro schema.
N_STR * avro_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).
N_STR * avro_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).
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.
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.
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_encode_datum(N_STR ** dest, const AVRO_SCHEMA * schema, const cJSON * json)
Encode a cJSON value as Avro binary according to schema.
N_STR * avro_encode_container(const AVRO_SCHEMA * schema, const cJSON * records)
Encode a cJSON array of records into Avro container format N_STR.
int avro_decode_long(AVRO_READER * reader, int64_t * value)
Decode a zig-zag varint from reader into a 64-bit signed integer.
cJSON * avro_decode_datum(AVRO_READER * reader, const AVRO_SCHEMA * schema)
Decode an Avro binary datum into cJSON according to schema.
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.

Defines

Name
AVRO_SYNC_LEN
Avro sync marker length.
AVRO_MAGIC_LEN
Avro magic length.
AVRO_MAGIC
Avro object container file magic bytes.

Types Documentation

enum AVRO_TYPE

Enumerator Value Description
AVRO_UNION
AVRO_STRING
AVRO_RECORD
AVRO_NULL 0
AVRO_MAP
AVRO_LONG
AVRO_INT
AVRO_FLOAT
AVRO_FIXED
AVRO_ENUM
AVRO_DOUBLE
AVRO_BYTES
AVRO_BOOLEAN
AVRO_ARRAY

Avro schema type enumeration.

Functions Documentation

function avro_schema_to_json

char * avro_schema_to_json(
    const AVRO_SCHEMA * schema
)

Convert an Avro schema back to JSON string (caller must free).

function avro_schema_parse_nstr

AVRO_SCHEMA * avro_schema_parse_nstr(
    const N_STR * schema_nstr
)

Parse schema from N_STR.

function avro_schema_parse

AVRO_SCHEMA * avro_schema_parse(
    const char * json_str
)

Parse an Avro schema from a JSON string.

function avro_schema_from_cjson

AVRO_SCHEMA * avro_schema_from_cjson(
    const cJSON * json
)

Parse an Avro schema from a cJSON object.

function avro_schema_free

void avro_schema_free(
    AVRO_SCHEMA ** schema
)

Free an Avro schema.

function avro_nstr_json_to_avro

N_STR * avro_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).

function avro_nstr_avro_to_json

N_STR * avro_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).

function avro_json_to_file

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.

function avro_file_to_json

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.

function avro_encode_long

int avro_encode_long(
    N_STR ** dest,
    int64_t value
)

Encode a 64-bit signed integer as zig-zag varint into N_STR.

function avro_encode_datum

int avro_encode_datum(
    N_STR ** dest,
    const AVRO_SCHEMA * schema,
    const cJSON * json
)

Encode a cJSON value as Avro binary according to schema.

function avro_encode_container

N_STR * avro_encode_container(
    const AVRO_SCHEMA * schema,
    const cJSON * records
)

Encode a cJSON array of records into Avro container format N_STR.

function avro_decode_long

int avro_decode_long(
    AVRO_READER * reader,
    int64_t * value
)

Decode a zig-zag varint from reader into a 64-bit signed integer.

function avro_decode_datum

cJSON * avro_decode_datum(
    AVRO_READER * reader,
    const AVRO_SCHEMA * schema
)

Decode an Avro binary datum into cJSON according to schema.

function avro_decode_container

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.

Macros Documentation

define AVRO_SYNC_LEN

#define AVRO_SYNC_LEN 16

Avro sync marker length.

define AVRO_MAGIC_LEN

#define AVRO_MAGIC_LEN 4

Avro magic length.

define AVRO_MAGIC

#define AVRO_MAGIC "Obj\x01"

Avro object container file magic bytes.