1.0.0 • Published 8 years ago

protobuff-schema v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
8 years ago

protobuff-schema

A protobuff schema generator from JS Definitions

Example

const Proto = require('protobuff-schema');

/**
 * Registers the 'event1' schema
 * @param {string} The name of the schema
 * @param {object|string} The schema (JSON object of string)
 */
let schema = Proto.generate({
  global: {
    FOO: {
      type: Proto.ENUM,
      name: 'BAR',
      value: 1
    }
  },
  message: {
    AnotherOne: {
      items: [{
        name: 'list',
        type: Proto.LIST,
        items: 'FOO'
      }]
    },
    Test: {
      items: [{
        name: 'num',
        type: Proto.FLOAT,
        required: true
      }, {
        name: 'payload',
        type: Proto.STRING,
        required: true
      }]
    }
  }
});

Will generate this schema:

enum FOO {
  BAR = 1;
}

message Test {
  required float num = 1;
  required string payload = 2;
}

message AnotherOne {
  repeated FOO list = 1;
}