Skip to content

The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas.

License

Notifications You must be signed in to change notification settings

ballerina-platform/module-ballerina-avro

Repository files navigation

Ballerina Avro Module

Build codecov Trivy GraalVM Check GitHub Last Commit Github issues

Avro is an open-source data serialization system that enables efficient binary serialization and deserialization. It allows users to define schemas for structured data, providing better representation and fast serialization/deserialization. Avro's schema evolution capabilities ensure compatibility and flexibility in evolving data systems.

The Ballerina Avro module provides the capability to efficiently serialize and deserialize data using Avro schemas.

Schema

The Schema instance accepts an Avro schema in string format. If the provided schema is not valid according to Avro, an error is returned. The client can be used to serialize data into bytes using the defined schema and deserialize the bytes back to the correct data type based on the schema.

A Schema can be defined using the string value of an Avro schema as shown below.

avro:Schema schema = check new(string `{"type": "int", "namespace": "example.data" }`);

APIs associated with Avro

  • toAvro: Serializes the given data according to the Avro format.
  • fromAvro: Deserializes the given Avro encoded message to the given data type.

toAvro

Serializes the given data according to the Avro format.

import ballerina/avro;

public function main() returns error? {
    int value = 5;
    byte[] serializedData = check schema.toAvro(value);
}

fromAvro

Deserializes the given Avro encoded message to the given data type.

import ballerina/avro;

public function main() returns error? {
    byte[] data = // Avro encoded message ;
    int deserializedData = check schema.fromAvro(data);
}

Issues and projects

The Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc., visit the Ballerina library parent repository.

This repository only contains the source code for the package.

Building from the source

Prerequisites

  1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:

    Note: After installation, remember to set the JAVA_HOME environment variable to the directory where JDK was installed.

  2. Download and install Ballerina Swan Lake.

  3. Download and install Docker.

    Note: Ensure that the Docker daemon is running before executing any tests.

  4. Generate a Github access token with read package permissions, then set the following env variables:

    export packageUser=<Your GitHub Username>
    export packagePAT=<GitHub Personal Access Token>

Build options

Execute the commands below to build from the source.

  1. To build the package:

    ./gradlew clean build
  2. To run the tests:

    ./gradlew clean test
  3. To build the without the tests:

    ./gradlew clean build -x test
  4. To debug package with a remote debugger:

    ./gradlew clean build -Pdebug=<port>
  5. To debug with Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
  6. Publish the generated artifacts to the local Ballerina central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
  7. Publish the generated artifacts to the Ballerina central repository:

    ./gradlew clean build -PpublishToCentral=true

Contributing to Ballerina

As an open source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All contributors are encouraged to read the Ballerina Code of Conduct.

Useful links