Code Monkey home page Code Monkey logo

avsc's Introduction

Avsc NPM version Build status Coverage status

Pure JavaScript implementation of the Avro specification.

Features

  • Fast! Typically twice as fast as JSON with much smaller encodings.
  • Full Avro support, including recursive schemas, sort order, and evolution.
  • Serialization of arbitrary JavaScript objects via logical types.
  • Unopinionated 64-bit integer compatibility.
  • No dependencies, avsc even runs in the browser.

Performance

Representative throughput rates (higher is better):

Throughput rates chart

Libraries compared:

  • node-avsc, this package.
  • node-json, built-in JSON serializer.
  • node-protobuf, most popular Protocol Buffers implementation.
  • node-pson, alternative to JSON.
  • node-msgpack, official MessagePack implementation.

These rates are for processing a realistic record schema, modeled after a popular open-source API. You can find the raw numbers and more details on the benchmarks page.

Installation

$ npm install avsc

avsc is compatible with all versions of node.js since 0.11 and major browsers via browserify.

Documentation

Examples

Inside a node.js module, or using browserify:

var avsc = require('avsc');
  • Encode and decode objects:

    // We can declare a schema inline:
    var type = avsc.parse({
      name: 'Pet',
      type: 'record',
      fields: [
        {name: 'kind', type: {name: 'Kind', type: 'enum', symbols: ['CAT', 'DOG']}},
        {name: 'name', type: 'string'}
      ]
    });
    var pet = {kind: 'CAT', name: 'Albert'};
    var buf = type.toBuffer(pet); // Serialized object.
    var obj = type.fromBuffer(buf); // {kind: 'CAT', name: 'Albert'}
  • Generate random instances of a schema:

    // We can also parse a JSON-stringified schema:
    var type = avsc.parse('{"type": "fixed", "name": "Id", "size": 4}');
    var id = type.random(); // E.g. Buffer([48, 152, 2, 123])
  • Check whether an object fits a given schema:

    // Or we can specify a path to a schema file (not in the browser):
    var type = avsc.parse('./Person.avsc');
    var person = {name: 'Bob', address: {city: 'Cambridge', zip: '02139'}};
    var status = type.isValid(person); // Boolean status.
  • Get a readable stream of decoded records from an Avro container file (not in the browser):

    avsc.createFileDecoder('./records.avro')
      .on('metadata', function (type) { /* `type` is the writer's type. */ })
      .on('data', function (record) { /* Do something with the record. */ });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.