Avro Decoding/Encoding Functions
The functions described in this section are used to decode binary encoded Avro messages.
The following functions for AVRO Decoding/Encoding described here are:
avroInitialize
This function initialises a schema registry provider that is used to obtain schemas used in avroDeserialize and avroSerialize functions
void avroInitialize(string schemaRegistry, string schemaField)
Parameter | Description |
---|---|
| The binary encoded Avro message to decode |
schemaField | A DynamicAvro UDR |
Returns |
avroDeserialize
This function decodes a binary encoded Avro message to a DynamicAvro UDRÂ
DynamicAvro avroDeserialize ( AvroDecoderUDR avroDecoderUDR)
Parameter | Description |
---|---|
avroDecoderUDR | AvroDecoderUDR containing a bytearray with a binary encoded Avro message to decode |
Returns | A DynamicAvro UDR containing decoded message |
Note
avroDeserialize function has to be used inside try-catch block if the exception handling is required
Example - Example - Decoding AVRO binary encoded message
import apl.Avro;
initialize
{
string schemaRegistry = "http://localhost:8081/schemas/ids";
string schemaField = "schema";
avroInitialize(schemaRegistry, schemaField);
}
consume {
//This example assumes that the input of an analysis agent is a bytearray
//representing complete Avro message
debug(input);
Avro.AvroDecoderUDR decoder = udrCreate(Avro.AvroDecoderUDR);
decoder.readerSchemaID = "5";
decoder.writerSchemaID = "5";
decoder.data = input;
Avro.DynamicAvro decodedAvro = (Avro.DynamicAvro)Avro.avroDeserialize(decoder);
debug(decodedAvro);
}
avroSerialize
This function encodes a schema defined structure using binary Avro encoder
Note
avroSerialize function has to be used inside try-catch block if the exception handling is required
Parameter | Description |
---|---|
avroEncoderUDR | AvroEncoderUDR containing data to encode and specifying selected schemaID (data must match selected schema) |
Returns | binary encoded Avro message |