Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protobufjs

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobufjs - npm Package Compare versions

Comparing version 0.9.1 to 0.9.3

bin/proto2js

7

package.json
{
"name": "protobufjs",
"version": "0.9.1",
"version": "0.9.3",
"author": "Daniel Wirtz <dcode@dcode.io>",
"description": "",
"description": "protobuf for JavaScript",
"contributors": [

@@ -10,2 +10,5 @@ { "name": "Daniel Wirtz", "email": "dcode@dcode.io" }

"main": "ProtoBuf.js",
"bin": {
"proto2js": "./bin/proto2js"
},
"repository": {

@@ -12,0 +15,0 @@ "type": "git",

@@ -7,3 +7,3 @@ /*

(function(s){function t(k){if(!k||!k.calculateUTF8String||!k.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(k=dcodeIO.ByteBuffer),!k&&"function"==typeof require&&(k=require("ByteBuffer")),!k)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");Object.create||(Object.create=function(b){function a(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");a.prototype=b;return new a});
var e={VERSION:"0.9.1",WIRE_TYPES:{}};e.WIRE_TYPES.VARINT=0;e.WIRE_TYPES.BITS64=1;e.WIRE_TYPES.LDELIM=2;e.WIRE_TYPES.STARTGROUP=3;e.WIRE_TYPES.ENDGROUP=4;e.WIRE_TYPES.BITS32=5;e.TYPES={int32:{name:"int32",wireType:e.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:e.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:e.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:e.WIRE_TYPES.VARINT},"double":{name:"double",wireType:e.WIRE_TYPES.BITS64},string:{name:"string",wireType:e.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
var e={VERSION:"0.9.2",WIRE_TYPES:{}};e.WIRE_TYPES.VARINT=0;e.WIRE_TYPES.BITS64=1;e.WIRE_TYPES.LDELIM=2;e.WIRE_TYPES.STARTGROUP=3;e.WIRE_TYPES.ENDGROUP=4;e.WIRE_TYPES.BITS32=5;e.TYPES={int32:{name:"int32",wireType:e.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:e.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:e.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:e.WIRE_TYPES.VARINT},"double":{name:"double",wireType:e.WIRE_TYPES.BITS64},string:{name:"string",wireType:e.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
wireType:e.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:e.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:e.WIRE_TYPES.BITS32},"float":{name:"float",wireType:e.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:e.WIRE_TYPES.VARINT},message:{name:"message",wireType:e.WIRE_TYPES.LDELIM}};e.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"]/g,KEYWORD:/package|option|message|enum/,RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|fixed32|sfixed32|bool|string|bytes/,

@@ -43,3 +43,3 @@ NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/-?([1-9][0-9]*)|0/,ID:/[0-9]+/,COMMENT:"//",WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"'};e.DotProto={};var s=e.DotProto,p=e.Lang,n=function(b){this.source=""+b;this.index=0;this.stack=[];this.readingString=!1};n.prototype._readString=function(){p.STRING.lastIndex=this.index-1;var b;if(null!==(b=p.STRING.exec(this.source)))return b=b[1],this.index=

j.prototype.build=function(){for(var a={},b=this.getChildren(j.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;return this.built=a};a.Enum=j;f=function(a,b,d){c.call(this,a,b);this.id=d};f.prototype=Object.create(c.prototype);a.Enum.Value=f;return a}(e);var h=e.Lang,q=e.Reflect,m=function(){this.ptr=this.ns=new q.Namespace(null,"");this.resolved=!1;this.result=null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(b){if("string"!=typeof b||!h.TYPEDEF.test(b))throw Error("Illegal package name: "+
b);b=b.split(".");var a;for(a=0;a<b.length;a++)if(!h.NAME.test(b[a]))throw Error("Illegal package name: "+b[a]);for(a=0;a<b.length;a++)this.ptr.hasChild(b[a])||this.ptr.addChild(new q.Namespace(this.ptr,b[a])),this.ptr=this.ptr.getChild(b[a])};m.isValidMessage=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"!=typeof b.values)return!1;var a;if("undefined"!=typeof b.fields){if(!(b.fields instanceof Array))return!1;var c=[],d;for(a=0;a<b.fields.length;a++){if(!m.isValidMessageField(b.fields[a]))return!1;
b);b=b.split(".");var a;for(a=0;a<b.length;a++)if(!h.NAME.test(b[a]))throw Error("Illegal package name: "+b[a]);for(a=0;a<b.length;a++)this.ptr.hasChild(b[a])||this.ptr.addChild(new q.Namespace(this.ptr,b[a])),this.ptr=this.ptr.getChild(b[a]);return this};m.isValidMessage=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"!=typeof b.values)return!1;var a;if("undefined"!=typeof b.fields){if(!(b.fields instanceof Array))return!1;var c=[],d;for(a=0;a<b.fields.length;a++){if(!m.isValidMessageField(b.fields[a]))return!1;
d=parseInt(b.id,10);if(0<=c.indexOf(d))return!1;c.push(d)}}if("undefined"!=typeof b.enums){if(!(b.enums instanceof Array))return!1;for(a=0;a<b.enums.length;a++)if(!m.isValidEnum(b.enums[a]))return!1}if("undefined"!=typeof b.messages){if(!(b.messages instanceof Array))return!1;for(a=0;a<b.messages.length;a++)if(!m.isValidMessage(b.messages[a]))return!1}return!0};m.isValidMessageField=function(b){if("string"!=typeof b.rule||"string"!=typeof b.name||"string"!=typeof b.type||"undefined"==typeof b.id||

@@ -50,3 +50,3 @@ !h.RULE.test(b.rule)||!h.NAME.test(b.name)||!h.TYPEREF.test(b.type)||!h.ID.test(""+b.id))return!1;if("undefined"!=typeof b.options){if("object"!=typeof b.options)return!1;for(var a=Object.keys(b.options),c=0;c<a.length;c++)if(!h.NAME.test(a[c])||!h.ID.test(""+b.options[a[c]])&&!h.TYPEREF.test(b.options[a[c]]))return!1}return!0};m.isValidEnum=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"==typeof b.values||!(b.values instanceof Array)||0==b.values.length)return!1;for(var a=

c.fields[f].name,c.fields[f].id,c.fields[f].options))}e=[];if("undefined"!=typeof c.enums&&0<c.enums.length)for(f=0;f<c.enums.length;f++)e.push(c.enums[f]);if(c.messages&&0<c.messages.length)for(f=0;f<c.messages.length;f++)e.push(c.messages[f]);this.ptr.addChild(d);0<e.length&&(a.push(b),b=e,this.ptr=d)}else if(m.isValidEnum(c)){d=new q.Enum(this.ptr,c.name);for(f=0;f<c.values.length;f++)d.addChild(new q.Enum.Value(d,c.values[f].name,c.values[f].id));this.ptr.addChild(d)}else throw Error("Not a valid message or enum definition: "+
JSON.stringify(c));else throw Error("Not a valid namespace definition: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof q.Namespace)for(var b=this.ptr.getChildren(),a=0;a<b.length;a++)this.ptr=b[a],this.resolveAll();else if(this.ptr instanceof q.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!h.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+
JSON.stringify(c));else throw Error("Not a valid namespace definition: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof q.Namespace)for(var b=this.ptr.getChildren(),a=0;a<b.length;a++)this.ptr=b[a],this.resolveAll();else if(this.ptr instanceof q.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!h.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+
this.ptr.toString(!0)+": "+this.ptr.type);b=this.ptr.parent.resolve(this.ptr.type);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof q.Enum)this.ptr.type=e.TYPES["enum"];else if(b instanceof q.Message)this.ptr.type=e.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof e.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+

@@ -53,0 +53,0 @@ typeof this.ptr+":"+this.ptr);this.reset()}};m.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var a=this.result,c=0;c<b.length;c++)if(a[b[c]])a=a[b[c]];else{a=null;break}return a}return this.result};m.prototype.toString=function(){return"Builder"};e.Builder=m;e.protoFromString=function(b){b=(new e.DotProto.Parser(b+"")).parse();var a=new e.Builder;null!==b["package"]&&

@@ -7,3 +7,3 @@ /*

(function(p){function q(k){if(!k||!k.calculateUTF8String||!k.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(k=dcodeIO.ByteBuffer),!k&&"function"==typeof require&&(k=require("ByteBuffer")),!k)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");Object.create||(Object.create=function(a){function b(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");b.prototype=a;return new b});
var f={VERSION:"0.9.1",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
var f={VERSION:"0.9.2",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"]/g,KEYWORD:/package|option|message|enum/,RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|fixed32|sfixed32|bool|string|bytes/,

@@ -30,4 +30,4 @@ NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/-?([1-9][0-9]*)|0/,ID:/[0-9]+/,COMMENT:"//",WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"'};f.Reflect=function(a){var b={},e=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};e.prototype.toString=function(a){var c=this.name,d=this;do{d=d.parent;if(null==d)break;c=d.name+"."+c}while(1);a&&(this instanceof b.Message?c="Message "+c:this instanceof

": "+b+" (unknown type)");};b.Message.Field=g;var j=function(a,b){f.call(this,a,b);this.built=null};j.prototype=Object.create(f.prototype);j.prototype.build=function(){for(var a={},b=this.getChildren(j.Value),d=0;d<b.length;d++)a[b[d].name]=b[d].id;return this.built=a};b.Enum=j;g=function(a,b,d){e.call(this,a,b);this.id=d};g.prototype=Object.create(e.prototype);b.Enum.Value=g;return b}(f);var j=f.Lang,n=f.Reflect,m=function(){this.ptr=this.ns=new n.Namespace(null,"");this.resolved=!1;this.result=
null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(a){if("string"!=typeof a||!j.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var b;for(b=0;b<a.length;b++)if(!j.NAME.test(a[b]))throw Error("Illegal package name: "+a[b]);for(b=0;b<a.length;b++)this.ptr.hasChild(a[b])||this.ptr.addChild(new n.Namespace(this.ptr,a[b])),this.ptr=this.ptr.getChild(a[b])};m.isValidMessage=function(a){if("string"!=typeof a.name||!j.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;
var b;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],f;for(b=0;b<a.fields.length;b++){if(!m.isValidMessageField(a.fields[b]))return!1;f=parseInt(a.id,10);if(0<=e.indexOf(f))return!1;e.push(f)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(b=0;b<a.enums.length;b++)if(!m.isValidEnum(a.enums[b]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(b=0;b<a.messages.length;b++)if(!m.isValidMessage(a.messages[b]))return!1}return!0};
null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(a){if("string"!=typeof a||!j.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var b;for(b=0;b<a.length;b++)if(!j.NAME.test(a[b]))throw Error("Illegal package name: "+a[b]);for(b=0;b<a.length;b++)this.ptr.hasChild(a[b])||this.ptr.addChild(new n.Namespace(this.ptr,a[b])),this.ptr=this.ptr.getChild(a[b]);return this};m.isValidMessage=function(a){if("string"!=typeof a.name||!j.NAME.test(a.name)||"undefined"!=
typeof a.values)return!1;var b;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],f;for(b=0;b<a.fields.length;b++){if(!m.isValidMessageField(a.fields[b]))return!1;f=parseInt(a.id,10);if(0<=e.indexOf(f))return!1;e.push(f)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(b=0;b<a.enums.length;b++)if(!m.isValidEnum(a.enums[b]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(b=0;b<a.messages.length;b++)if(!m.isValidMessage(a.messages[b]))return!1}return!0};
m.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!j.RULE.test(a.rule)||!j.NAME.test(a.name)||!j.TYPEREF.test(a.type)||!j.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var b=Object.keys(a.options),e=0;e<b.length;e++)if(!j.NAME.test(b[e])||!j.ID.test(""+a.options[b[e]])&&!j.TYPEREF.test(a.options[b[e]]))return!1}return!0};m.isValidEnum=function(a){if("string"!=

@@ -37,3 +37,3 @@ typeof a.name||!j.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var b=0;b<a.values.length;b++)if("object"!=typeof a.values[b]||"string"!=typeof a.values[b].name||"undefined"==typeof a.values[b].id||!j.NAME.test(a.values[b].name)||!j.ID.test(""+a.values[b].id))return!1;return!0};m.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var b=[],e,f,l,g,k;for(b.push(a);0<b.length;){a=b.pop();if(a instanceof Array)for(;0<

!j.TYPEREF.test(e.fields[g].options[l[k]]))throw Error("Illegal field option value in message "+f.name+"#"+e.fields[g].name+"#"+l[k]+": "+e.fields[g].options[l[k]]);}}f.addChild(new n.Message.Field(f,e.fields[g].rule,e.fields[g].type,e.fields[g].name,e.fields[g].id,e.fields[g].options))}l=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(g=0;g<e.enums.length;g++)l.push(e.enums[g]);if(e.messages&&0<e.messages.length)for(g=0;g<e.messages.length;g++)l.push(e.messages[g]);this.ptr.addChild(f);0<
l.length&&(b.push(a),a=l,this.ptr=f)}else if(m.isValidEnum(e)){f=new n.Enum(this.ptr,e.name);for(g=0;g<e.values.length;g++)f.addChild(new n.Enum.Value(f,e.values[g].name,e.values[g].id));this.ptr.addChild(f)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof
l.length&&(b.push(a),a=l,this.ptr=f)}else if(m.isValidEnum(e)){f=new n.Enum(this.ptr,e.name);for(g=0;g<e.values.length;g++)f.addChild(new n.Enum.Value(f,e.values[g].name,e.values[g].id));this.ptr.addChild(f)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof
n.Namespace)for(var a=this.ptr.getChildren(),b=0;b<a.length;b++)this.ptr=a[b],this.resolveAll();else if(this.ptr instanceof n.Message.Field)if(j.TYPE.test(this.ptr.type))this.ptr.type=f.TYPES[this.ptr.type];else{if(!j.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type);if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof

@@ -40,0 +40,0 @@ n.Enum)this.ptr.type=f.TYPES["enum"];else if(a instanceof n.Message)this.ptr.type=f.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof f.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};m.prototype.build=function(a){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(a){a=

ProtoBuf.js - protobuf for JavaScript [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js)
=====================================
A protobuf implementation on top of [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) including a .proto parser,

@@ -11,8 +12,10 @@ reflection, message class building and simple encoding and decoding in plain JavaScript. No compilation step required,

ready to use classes. Can be created from a .proto file or from a JSON definition. The later does not even require the
.proto parser to be included (see: `ProtoBuf.noparse.js`).
.proto parser to be included ([see](https://github.com/dcodeIO/ProtoBuf.js#using-json-without-the-proto-parser)).
Install: `npm install protobufjs`
#### Using .proto files ####
Example: [tests/complex.proto](https://github.com/dcodeIO/ProtoBuf.js/tree/master/tests/complex.proto)
Install: `npm install protobufjs`
```javascript

@@ -53,5 +56,87 @@ var ProtoBuf = require("protobufjs");

#### Using JSON without the .proto parser ####
Example: [tests/complex.json](https://github.com/dcodeIO/ProtoBuf.js/tree/master/tests/complex.json)
```javascript
var ProtoBuf = require("protobufjs");
var builder = ProtoBuf.newBuilder(); // Alternatively:
builder.define("Game"); // var builder = ProtoBuf.newBuilder("Game");
builder.create([
{
"name": "Car",
"fields": [
{
"rule": "required",
"type": "string",
"name": "model",
"id": 1
},
...
],
"messages": [
{
"name": "Vendor",
"fields": ...,
},
...
],
"enums": [
{
"name": "Speed",
"values": [
{
"name": "FAST",
"id": 1
},
...
]
}
]
}
]);
var Game = builder.build("Game");
var Car = Game.Cars.Car;
... actually the same as above ...
```
When using JSON only, you can use [ProtoBuf.noparse.js](https://github.com/dcodeIO/ProtoBuf.js/blob/master/ProtoBuf.noparse.js)
/ [ProtoBuf.noparse.min.js](https://github.com/dcodeIO/ProtoBuf.js/blob/master/ProtoBuf.noparse.min.js) instead, which
do NOT include the `ProtoBuf.DotProto` package for parsing and are therefore even smaller.
Command line utility
--------------------
It's also possible to transform .proto files into their JSON counterparts or to transform entire namespaces into
ready-to-use message classes and enum objects by using the `proto2js` command line utility.
```
Usage: proto2js protoFile [-class[=My.Package]] [-min] [> outFile]
Options:
-class[=My.Package] Creates the class instead of just a JSON definition.
If you do not specifiy a package, the package
declaration from the .proto file is used instead.
-min Minifies the generated output
```
So, to create a JSON definition from the [tests/complex.proto](https://github.com/dcodeIO/ProtoBuf.js/blob/master/tests/complex.proto)
file, run:
```bash
proto2js tests/complex.proto > tests/complex.json
```
Or to create classes for the entire `Game` namespace, run:
```bash
proto2js tests/complex.proto -class=Game > tests/complex.js
```
Parser
------
Compliant with the protobuf parser to the following extend:
Only available in the full build (i.e. not in "noparse" builds). Compliant with the protobuf parser to the following extend:

@@ -164,6 +249,8 @@ * Required, optional, repeated and packed repeated fields:

Encoder
-------
Built into all message classes. Just call `YourMessage#encode([buffer])`.
Encoder / Decoder
-----------------
Built into all message classes. Just call `YourMessage#encode([buffer])` respectively `YourMessage.decode(buffer)`.
#### Encoding a message ####
```javascript

@@ -183,5 +270,3 @@ ...

Decoder
-------
Built into all message classes. Just call `YourMessage.decode(buffer)`.
#### Decoding from an ArrayBuffer/ByteBuffer ####

@@ -188,0 +273,0 @@ ```javascript

@@ -74,2 +74,3 @@ // #ifdef UNDEFINED

* Defines a package on top of the current pointer position and places the pointer on it.
* @return {ProtoBuf.Builder} this
* @throws {Error} If the package name is invalid

@@ -94,2 +95,3 @@ * @expose

}
return this;
};

@@ -218,2 +220,3 @@

* Creates ths specified protocol types at the current pointer position.
* @return {ProtoBuf.Builder} this
* @throws {Error} If a message definition is invalid

@@ -304,2 +307,3 @@ * @expose

this.result = null; // Require re-build
return this;
};

@@ -306,0 +310,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc