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

protocol-buffers

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protocol-buffers - npm Package Compare versions

Comparing version 3.2.1 to 4.0.0

bin.js

5

bench/index.js
var protobuf = require('../')
var fs = require('fs')
var messages = protobuf(fs.readFileSync(__dirname + '/bench.proto'))
var path = require('path')
var messages = protobuf(fs.readFileSync(path.join(__dirname, 'bench.proto')))

@@ -14,3 +15,3 @@ var TIMES = 1000000

hello: 42,
payload: new Buffer('a'),
payload: Buffer.from('a'),
meh: {

@@ -17,0 +18,0 @@ b: {

42

compile.js
/* eslint-disable no-spaced-func */
/* eslint-disable no-unexpected-multiline */
var encodings = require('./encodings')
/* eslint-disable func-call-spacing */
var encodings = require('protocol-buffers-encodings')
var varint = require('varint')

@@ -17,27 +19,3 @@ var genobj = require('generate-object-property')

var skip = function (type, buffer, offset) {
switch (type) {
case 0:
varint.decode(buffer, offset)
return offset + varint.decode.bytes
case 1:
return offset + 8
case 2:
var len = varint.decode(buffer, offset)
return offset + varint.decode.bytes + len
case 3:
case 4:
throw new Error('Groups are not supported')
case 5:
return offset + 4
}
throw new Error('Unknown wire type: ' + type)
}
var defined = function (val) {
var defined = function defined (val) {
return val !== null && val !== undefined && (typeof val !== 'number' || !isNaN(val))

@@ -282,3 +260,3 @@ }

('if (!offset) offset = 0')
('if (!buf) buf = new Buffer(encodingLength(obj))')
('if (!buf) buf = Buffer.allocUnsafe(encodingLength(obj))')
('var oldOffset = offset')

@@ -480,3 +458,3 @@

varint: varint,
skip: skip,
skip: encodings.skip,
enc: enc

@@ -493,2 +471,3 @@ })

exports.encodingLength = encodingLength
exports.dependencies = enc

@@ -515,3 +494,6 @@ return exports

if (m.values) return compileEnum(m)
return cache[m.id] || compileMessage(m, cache[m.id] = {})
if (cache[m.id]) return cache[m.id]
cache[m.id] = {}
return compileMessage(m, cache[m.id])
}

@@ -523,1 +505,3 @@

}
module.exports.defined = defined
var protobuf = require('./')
var fs = require('fs')
var path = require('path')
var messages = protobuf(fs.readFileSync(__dirname + '/example.proto'))
var messages = protobuf(fs.readFileSync(path.join(__dirname, 'example.proto')))

@@ -6,0 +7,0 @@ var ex = {

{
"name": "protocol-buffers",
"version": "3.2.1",
"version": "4.0.0",
"description": "Protocol Buffers for Node.js",

@@ -10,5 +10,5 @@ "repository": {

"dependencies": {
"brfs": "^1.4.0",
"generate-function": "^2.0.0",
"generate-object-property": "^1.2.0",
"protocol-buffers-encodings": "^1.1.0",
"protocol-buffers-schema": "^3.1.1",

@@ -19,5 +19,8 @@ "signed-varint": "^2.0.0",

"devDependencies": {
"standard": "^5.4.1",
"tape": "^3.0.3"
"standard": "^10.0.3",
"tape": "^4.8.0"
},
"bin": {
"protocol-buffers": "./bin.js"
},
"scripts": {

@@ -27,7 +30,2 @@ "test": "standard && tape test/*.js",

},
"browserify": {
"transform": [
"brfs"
]
},
"bugs": {

@@ -34,0 +32,0 @@ "url": "https://github.com/mafintosh/protocol-buffers/issues"

@@ -77,2 +77,29 @@ # protocol-buffers

## Compile to a file
Since v4 you can now compile your schemas to a JavaScript file you can require from Node.
This means you do not have runtime parse the schemas, which is useful if using in the browser or on embedded devices.
It also makes the dependency footprint a lot smaller.
``` sh
# first install the cli tool
npm install -g protocol-buffers
# compile the schema
protocol-buffers test.proto -o messages.js
# then install the runtime dependency in the project
npm install --save protocol-buffers-encodings
```
That's it! Then in your application you can simply do
``` js
var messages = require('./messages')
var buf = messages.Test.encode({
num: 42
})
```
## Performance

@@ -79,0 +106,0 @@

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Basic = protobuf(fs.readFileSync(__dirname + '/test.proto')).Basic
var Basic = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Basic

@@ -9,3 +10,3 @@ tape('basic encode', function (t) {

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
})

@@ -15,3 +16,3 @@

num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meeeh: 42

@@ -34,3 +35,3 @@ })

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
})

@@ -41,7 +42,7 @@

t.same(o1.num, 1)
t.same(o1.payload, new Buffer('lol'))
t.same(o1.payload, Buffer.from('lol'))
var b2 = Basic.encode({
num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meeeh: 42

@@ -59,3 +60,3 @@ })

num: 1.1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
})

@@ -66,4 +67,4 @@

t.same(o1.num, 1.1)
t.same(o1.payload, new Buffer('lol'))
t.same(o1.payload, Buffer.from('lol'))
t.end()
})

@@ -28,3 +28,3 @@ var tape = require('tape')

try {
messages.ABC.decode(new Buffer([8, 182, 168, 235, 144, 178, 41]))
messages.ABC.decode(Buffer.from([8, 182, 168, 235, 144, 178, 41]))
} catch (e) {

@@ -50,3 +50,3 @@ didFail = true

var didFail = false
var buf = new Buffer('cec1', 'hex')
var buf = Buffer.from('cec1', 'hex')
try {

@@ -53,0 +53,0 @@ messages.Open.decode(buf)

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Defaults = protobuf(fs.readFileSync(__dirname + '/test.proto')).Defaults
var Defaults = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Defaults
tape('defaults decode', function (t) {
var o1 = Defaults.decode(new Buffer(0)) // everything default
var o1 = Defaults.decode(Buffer.alloc(0)) // everything default

@@ -9,0 +10,0 @@ var b2 = Defaults.encode({

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var messages = protobuf(fs.readFileSync(__dirname + '/test.proto'))
var messages = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto')))

@@ -6,0 +7,0 @@ tape('enums', function (t) {

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Float = protobuf(fs.readFileSync(__dirname + '/test.proto')).Float
var Float = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Float

@@ -6,0 +7,0 @@ tape('float encode + decode', function (t) {

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Integers = protobuf(fs.readFileSync(__dirname + '/test.proto')).Integers
var Integers = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Integers

@@ -6,0 +7,0 @@ tape('integers encode + decode', function (t) {

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Map = protobuf(fs.readFileSync(__dirname + '/test.proto')).Map
var Map = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Map

@@ -6,0 +7,0 @@ tape('map encode + decode', function (t) {

@@ -17,3 +17,3 @@ var tape = require('tape')

var testString = 'hello!'
var properResult = new Buffer([0x12, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x21])
var properResult = Buffer.from([0x12, 0x06, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x21])
try {

@@ -20,0 +20,0 @@ encoded = messages.MyMessage.encode({ my_number: NaN, my_other: testString })

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Nested = protobuf(fs.readFileSync(__dirname + '/test.proto')).Nested
var Nested = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Nested

@@ -9,6 +10,6 @@ tape('nested encode', function (t) {

num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meh: {
num: 2,
payload: new Buffer('bar')
payload: Buffer.from('bar')
}

@@ -19,7 +20,7 @@ })

num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meeeh: 42,
meh: {
num: 2,
payload: new Buffer('bar')
payload: Buffer.from('bar')
}

@@ -35,6 +36,6 @@ })

num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meh: {
num: 2,
payload: new Buffer('bar')
payload: Buffer.from('bar')
}

@@ -46,14 +47,14 @@ })

t.same(o1.num, 1)
t.same(o1.payload, new Buffer('lol'))
t.same(o1.payload, Buffer.from('lol'))
t.ok(o1.meh, 'has nested property')
t.same(o1.meh.num, 2)
t.same(o1.meh.payload, new Buffer('bar'))
t.same(o1.meh.payload, Buffer.from('bar'))
var b2 = Nested.encode({
num: 1,
payload: new Buffer('lol'),
payload: Buffer.from('lol'),
meeeh: 42,
meh: {
num: 2,
payload: new Buffer('bar')
payload: Buffer.from('bar')
}

@@ -60,0 +61,0 @@ })

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var NotPacked = protobuf(fs.readFileSync(__dirname + '/test.proto')).NotPacked
var FalsePacked = protobuf(fs.readFileSync(__dirname + '/test.proto')).FalsePacked
var NotPacked = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).NotPacked
var FalsePacked = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).FalsePacked

@@ -7,0 +8,0 @@ tape('NotPacked encode + FalsePacked decode', function (t) {

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var proto = protobuf(fs.readFileSync(__dirname + '/test.proto'))
var proto = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto')))
var Property = proto.Property

@@ -6,0 +7,0 @@ var PropertyNoOneof = proto.PropertyNoOneof

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Packed = protobuf(fs.readFileSync(__dirname + '/test.proto')).Packed
var Packed = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Packed

@@ -9,5 +10,5 @@ tape('Packed encode', function (t) {

packed: [
'hello world',
'hej verden',
'hola mundo'
10,
42,
52
]

@@ -18,5 +19,5 @@ })

packed: [
'hello world',
'hej verden',
'hola mundo'
10,
42,
52
],

@@ -33,5 +34,5 @@ meeh: 42

packed: [
'hello world',
'hej verden',
'hola mundo'
10,
42,
52
]

@@ -43,11 +44,11 @@ })

t.same(o1.packed.length, 3)
t.same(o1.packed[0], 'hello world')
t.same(o1.packed[1], 'hej verden')
t.same(o1.packed[2], 'hola mundo')
t.same(o1.packed[0], 10)
t.same(o1.packed[1], 42)
t.same(o1.packed[2], 52)
var b2 = Packed.encode({
packed: [
'hello world',
'hej verden',
'hola mundo'
10,
42,
52
],

@@ -67,6 +68,6 @@ meeh: 42

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1')
payload: Buffer.from('lol1')
}]

@@ -78,6 +79,6 @@ })

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1'),
payload: Buffer.from('lol1'),
meeeeh: 100

@@ -96,6 +97,6 @@ }],

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1')
payload: Buffer.from('lol1')
}]

@@ -108,5 +109,5 @@ })

t.same(o1.list[0].num, 1)
t.same(o1.list[0].payload, new Buffer('lol'))
t.same(o1.list[0].payload, Buffer.from('lol'))
t.same(o1.list[1].num, 2)
t.same(o1.list[1].payload, new Buffer('lol1'))
t.same(o1.list[1].payload, Buffer.from('lol1'))

@@ -116,6 +117,6 @@ var b2 = Packed.encode({

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1'),
payload: Buffer.from('lol1'),
meeeeh: 100

@@ -122,0 +123,0 @@ }],

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var Repeated = protobuf(fs.readFileSync(__dirname + '/test.proto')).Repeated
var Repeated = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).Repeated

@@ -10,6 +11,6 @@ tape('repeated encode', function (t) {

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1')
payload: Buffer.from('lol1')
}]

@@ -21,6 +22,6 @@ })

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1'),
payload: Buffer.from('lol1'),
meeeeh: 100

@@ -39,6 +40,6 @@ }],

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1')
payload: Buffer.from('lol1')
}]

@@ -51,5 +52,5 @@ })

t.same(o1.list[0].num, 1)
t.same(o1.list[0].payload, new Buffer('lol'))
t.same(o1.list[0].payload, Buffer.from('lol'))
t.same(o1.list[1].num, 2)
t.same(o1.list[1].payload, new Buffer('lol1'))
t.same(o1.list[1].payload, Buffer.from('lol1'))

@@ -59,6 +60,6 @@ var b2 = Repeated.encode({

num: 1,
payload: new Buffer('lol')
payload: Buffer.from('lol')
}, {
num: 2,
payload: new Buffer('lol1'),
payload: Buffer.from('lol1'),
meeeeh: 100

@@ -65,0 +66,0 @@ }],

var tape = require('tape')
var fs = require('fs')
var path = require('path')
var protobuf = require('../')
var UTF8 = protobuf(fs.readFileSync(__dirname + '/test.proto')).UTF8
var UTF8 = protobuf(fs.readFileSync(path.join(__dirname, 'test.proto'))).UTF8

@@ -6,0 +7,0 @@ tape('strings can be utf-8', function (t) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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