Avsc
Pure JavaScript implementation of the Avro specification.
Features
- Blazingly fast and compact serialization! Typically faster than JSON with much smaller encodings.
- All the Avro goodness and more: type inference, schema evolution, and remote procedure calls.
- Support for serializing arbitrary JavaScript objects.
- Unopinionated 64-bit integer compatibility.
Installation
$ npm install avsc
avsc
is compatible with all versions of node.js since 0.11
and major
browsers via browserify. For convenience, you can also find compiled
distributions with the releases (but please host your own copy).
Documentation
Examples
Inside a node.js module, or using browserify:
const avro = ;
-
Encode and decode values from a known schema:
const type = avroType;const buf = type; // Encoded buffer.const val = type; // = {kind: 'CAT', name: 'Albert'} -
Infer a value's schema and encode similar values:
const type = avroType;// We can use `type` to encode any values with the same structure:const bufs =typetype; -
Get a readable stream of decoded values from an Avro container file compressed using Snappy (see the
BlockDecoder
API for an example including checksum validation):const snappy = ; // Or your favorite Snappy library.const codecs ={// Avro appends checksums to compressed blocks, which we skip here.return snappy;};avro; -
Implement a TCP server for an IDL-defined protocol:
// We first generate a protocol from its IDL specification.const protocol = avro;// We then create a corresponding server, implementing our endpoint.const server = avroService;// Finally, we use our server to respond to incoming TCP connections!;