> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# avro

> avro — Kinetica Rust API

[gpudb\_api](https://docs.kinetica.com/content/api/rust/index.md)
[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/avro.rs#L1-L701)&#x20;

High-performance Avro encoding and decoding utilities.This module provides optimized Avro serialization and deserialization using `serde_avro_fast` for best performance, with `rayon` parallelism for large batches.

## Performance

<ul>
  <li>**Encoding**: Uses `serde_avro_fast` for 2-3x faster encoding than `apache_avro`</li>
  <li>**Decoding**: Uses `serde_avro_fast` + rayon for up to 8x faster decoding</li>
  <li>**Parallelism**: Automatically enabled for batches above threshold (500 records)</li>
</ul>

These helpers split large batches over rayon’s threads, with the results of a sequential pass: records come back in order, and a batch with several bad records reports the first of them. Failures read “Could not encode object: …” and “Could not decode object: …”.

## Usage

### Encoding Records

```rust theme={null}
use gpudb_api::avro::{encode_records, parse_fast_schema};

let schema = parse_fast_schema(schema_str)?;
let encoded: Vec<Vec<u8>> = encode_records(&schema, &records)?;
```

### Decoding Records

```rust theme={null}
use gpudb_api::avro::{decode_records, parse_fast_schema};

#[derive(serde::Deserialize)]
struct Employee { id: i32, name: String }

let schema = parse_fast_schema(&response.type_schema)?;
let employees: Vec<Employee> = decode_records(&schema, &response.records_binary)?;
```

## Constants

`pub const PARALLEL_THRESHOLD: usize = 500;`

Threshold for switching to parallel processing. Below this count, sequential processing is faster due to thread spawning overhead. Based on benchmarks: parallel becomes beneficial around 500 records.

## Functions

[decode\_<wbr />records](https://docs.kinetica.com/content/api/rust/avro/fn.decode_records.md)Decodes binary Avro records to typed Rust structs.[decode\_<wbr />records\_<wbr />parallel](https://docs.kinetica.com/content/api/rust/avro/fn.decode_records_parallel.md)Decodes binary Avro records in parallel using serde\_avro\_fast + rayon.[decode\_<wbr />records\_<wbr />sequential](https://docs.kinetica.com/content/api/rust/avro/fn.decode_records_sequential.md)Decodes binary Avro records sequentially using serde\_avro\_fast.[decode\_<wbr />single](https://docs.kinetica.com/content/api/rust/avro/fn.decode_single.md)Decodes a single binary Avro record using a pre-parsed schema.[decode\_<wbr />with\_<wbr />fast\_<wbr />schema](https://docs.kinetica.com/content/api/rust/avro/fn.decode_with_fast_schema.md)Decodes binary Avro records using a pre-parsed serde\_avro\_fast schema.[encode\_<wbr />arc\_<wbr />records\_<wbr />parallel](https://docs.kinetica.com/content/api/rust/avro/fn.encode_arc_records_parallel.md)Encodes Arc-wrapped records in parallel.[encode\_<wbr />arc\_<wbr />records\_<wbr />partitioned](https://docs.kinetica.com/content/api/rust/avro/fn.encode_arc_records_partitioned.md)Encodes Arc-wrapped records, partitioning the batch over threads.[encode\_<wbr />records](https://docs.kinetica.com/content/api/rust/avro/fn.encode_records.md)Encodes records to Avro binary format.[encode\_<wbr />records\_<wbr />parallel](https://docs.kinetica.com/content/api/rust/avro/fn.encode_records_parallel.md)Encodes records in parallel using serde\_avro\_fast + rayon.[encode\_<wbr />records\_<wbr />partitioned](https://docs.kinetica.com/content/api/rust/avro/fn.encode_records_partitioned.md)Encodes records, partitioning the batch over threads (non-Arc version).[encode\_<wbr />records\_<wbr />sequential](https://docs.kinetica.com/content/api/rust/avro/fn.encode_records_sequential.md)Encodes records sequentially using serde\_avro\_fast.[encode\_<wbr />single](https://docs.kinetica.com/content/api/rust/avro/fn.encode_single.md)Encodes a single record to Avro binary format.[parse\_<wbr />fast\_<wbr />schema](https://docs.kinetica.com/content/api/rust/avro/fn.parse_fast_schema.md)Parses a schema string into a serde\_avro\_fast Schema for direct use.[parse\_<wbr />schema](https://docs.kinetica.com/content/api/rust/avro/fn.parse_schema.md)Parses a schema string into a serde\_avro\_fast Schema.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.