> ## 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.

# AvroType

> AvroType — Kinetica TypeScript API

An Avro type, compiled from its schema, that encodes values to Avro binary and decodes them back.Values map to JavaScript as JSON-style data: records and maps to plain objects, arrays to arrays, bytes and fixed to Uint8Array, enums to their symbol strings, and null to null. A union takes the value as-is and is written as its first branch that accepts it.

#### Example

```
const type = AvroType.forSchema({
    type: 'record', name: 'point',
    fields: [{ name: 'x', type: 'double' }, { name: 'label', type: ['string', 'null'] }],
});
const bytes = type.encode({ x: 1.5, label: null });
type.decode(bytes); // { x: 1.5, label: null }
```

<ul>
  <li>Defined in [src/avro.ts:921](https://github.com/kineticadb/kinetica-api-typescript/blob/master/src/avro.ts#L921)</li>
</ul>

##### Index

### Properties

[schema](#schema)&#x20;

### Methods

[decode](#decode) [encode](#encode) [forSchema](#forschema)&#x20;

## Properties

### `Readonly`schema

schema: [AvroSchema](https://docs.kinetica.com/content/api/typescript/types/AvroSchema.md)

The schema this type was compiled from

<ul>
  <li>Defined in [src/avro.ts:923](https://github.com/kineticadb/kinetica-api-typescript/blob/master/src/avro.ts#L923)</li>
</ul>

## Methods

### decode

<ul>
  <li>
    decode(data: ArrayBuffer | Uint8Array\<ArrayBufferLike>): any

    Decodes one Avro binary value, which must take up the whole input.

    #### Parameters

    <ul>
      <li>data: ArrayBuffer | Uint8Array\<ArrayBufferLike></li>
    </ul>

    #### Returns any

    #### Throws

    AvroError if the data is truncated, has bytes left over, or otherwise does not match the schema

    <ul>
      <li>Defined in [src/avro.ts:994](https://github.com/kineticadb/kinetica-api-typescript/blob/master/src/avro.ts#L994)</li>
    </ul>
  </li>
</ul>

### encode

<ul>
  <li>
    encode(value: any): Uint8Array

    Encodes a value to Avro binary.

    #### Parameters

    <ul>
      <li>value: any</li>
    </ul>

    #### Returns Uint8Array

    #### Throws

    AvroError if the value does not match the schema; its `path` names the offending field

    <ul>
      <li>Defined in [src/avro.ts:974](https://github.com/kineticadb/kinetica-api-typescript/blob/master/src/avro.ts#L974)</li>
    </ul>
  </li>
</ul>

### `Static`forSchema

<ul>
  <li>
    forSchema(schema: [AvroSchema](https://docs.kinetica.com/content/api/typescript/types/AvroSchema.md)): AvroType

    Compiles a schema, or returns the type already compiled for it.

    #### Parameters

    <ul>
      <li>
        schema: [AvroSchema](https://docs.kinetica.com/content/api/typescript/types/AvroSchema.md)

        The schema as an object, as JSON text, or as the bare name of a primitive type such as `"long"`
      </li>
    </ul>

    #### Returns AvroType

    #### Throws

    AvroError if the schema is invalid

    <ul>
      <li>Defined in [src/avro.ts:939](https://github.com/kineticadb/kinetica-api-typescript/blob/master/src/avro.ts#L939)</li>
    </ul>
  </li>
</ul>


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