Skip to main content

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.

schema: AvroSchema

The schema this type was compiled from

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

    Parameters

    • data: ArrayBuffer | Uint8Array<ArrayBufferLike>

    Returns any

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

  • Encodes a value to Avro binary.

    Parameters

    • value: any

    Returns Uint8Array

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

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

    Parameters

    • schema: AvroSchema

      The schema as an object, as JSON text, or as the bare name of a primitive type such as “long”

    Returns AvroType

    AvroError if the schema is invalid