Coder Social home page Coder Social logo

protocol-buffers-schema's Introduction

protocol-buffers-schema

No nonsense protocol buffers schema parser written in Javascript

npm install protocol-buffers-schema

build status

Usage

First save the following file as example.proto

syntax = "proto2";

message Point {
  required int32 x = 1;
  required int32 y=2;
  optional string label = 3;
}

message Line {
  required Point start = 1;
  required Point end = 2;
  optional string label = 3;
}

The run the following example

var fs = require('fs')
var schema = require('protocol-buffers-schema')

// pass a buffer or string to schema.parse
var sch = schema.parse(fs.readFileSync('example.proto'))

// will print out the schema as a javascript object
console.log(sch)

Running the above example will print something like

{
  syntax: 2,
  package: null,
  enums: [],
  messages: [{
    name: 'Point',
    enums: [],
    messages: [],
    fields: [{
      name: 'x',
      type: 'int32',
      tag: 1,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'y',
      type: 'int32',
      tag: 2,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'label',
      type: 'string',
      tag: 3,
      required: false,
      repeated: false,
      options: {}
    }]
  }, {
    name: 'Line',
    enums: [],
    messages: [],
    fields: [{
      name: 'start',
      type: 'Point',
      tag: 1,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'end',
      type: 'Point',
      tag: 2,
      required: true,
      repeated: false,
      options: {}
    }, {
      name: 'label',
      type: 'string',
      tag: 3,
      required: false,
      repeated: false,
      options: {}
    }]
  }],
  options:{}
}

API

schema.parse(protobufSchemaBufferOrString)

Parses a .proto schema into a javascript object

schema.stringify(schema)

Stringifies a parsed schema back into .proto format

License

MIT

protocol-buffers-schema's People

Contributors

mafintosh avatar davidbruant avatar c-p-b avatar astro avatar hvoecking avatar sastan avatar adon-at-work avatar wanglam avatar aoj avatar bydga avatar natevw avatar pgirolami avatar raydog avatar rthewhite avatar cute-angelia avatar iwasinnam avatar

Watchers

James Cloos avatar 顾长风 avatar

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.