🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@avro/common-types

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avro/common-types

Common Avro types

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

Avro types NPM version

Pure JavaScript implementation of the Avro specification.

Features

Installation

$ npm install @avro/types

@avro/types is compatible with all versions of node.js since 0.11.

Examples

Inside a node.js module, or using browserify:

const {Type} = require('@avro/types');
  • Encode and decode values from a known schema:

    const type = Type.forSchema({
      type: 'record',
      fields: [
        {name: 'kind', type: {type: 'enum', symbols: ['CAT', 'DOG']}},
        {name: 'name', type: 'string'}
      ]
    });
    
    const buf = type.toBuffer({kind: 'CAT', name: 'Albert'}); // Encoded buffer.
    const val = type.fromBuffer(buf); // = {kind: 'CAT', name: 'Albert'}
    
  • Infer a value's schema and encode similar values:

    const type = Type.forValue({
      city: 'Cambridge',
      zipCodes: ['02138', '02139'],
      visits: 2
    });
    
    // We can use `type` to encode any values with the same structure:
    const bufs = [
      type.toBuffer({city: 'Seattle', zipCodes: ['98101'], visits: 3}),
      type.toBuffer({city: 'NYC', zipCodes: [], visits: 0})
    ];
    

Keywords

avro

FAQs

Package last updated on 29 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts