Avro parsing in Javascript
// Import library
var avro = require('avro-js')
// Schema definition
var type = avro.parse({
name: 'Pet',
type: 'record',
fields: [
{name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
{name: 'name', type: 'string'}
]
});
// Example document
var pet = {kind: 'CAT', name: 'Albert'};
// Buffer creation
var buf = type.toBuffer(pet);
// Reverse convertion
var obj = type.fromBuffer(buf);