protobuf.js
Advanced tools
Comparing version 0.0.5 to 0.0.6
36
index.js
@@ -210,14 +210,33 @@ var fs = require('fs'), | ||
if (schema.hasOwnProperty(key) && typeof params[key] !== 'undefined') { | ||
bytes.push((schema[key].field << 3) + schema[key].type); | ||
if (schema[key].type === 2) { | ||
if (Buffer.isBuffer(params[key])) params[key] = bufferToArray(params[key]); | ||
if (!Array.isArray(params[key]) && typeof params[key] === 'object') { | ||
params[key] = self.encode(schema[key].raw_type, params[key]); | ||
params[key] = bufferToArray(params[key]); | ||
} | ||
if (Array.isArray(params[key])) { | ||
if (Buffer.isBuffer(params[key])) { | ||
bytes.push((schema[key].field << 3) + schema[key].type); | ||
var encoded = encode(params[key].length); | ||
bytes = bytes.concat(bufferToArray(encoded)); | ||
bytes = bytes.concat(params[key]); | ||
bytes = bytes.concat(bufferToArray(params[key])); | ||
} else if (typeof params[key] === 'object') { | ||
if (Array.isArray(params[key])) { | ||
var ret = []; | ||
params[key].forEach(function (item) { | ||
ret.push(self.encode(schema[key].raw_type, item)); | ||
}); | ||
params[key] = ret.map(function (item) { | ||
var arr = bufferToArray(item), | ||
len = bufferToArray(encode(arr.length)), | ||
head = [(schema[key].field << 3) + schema[key].type]; | ||
return head.concat(len).concat(arr); | ||
}).reduce(function (a, b) { | ||
return a.concat(b); | ||
}); | ||
bytes = bytes.concat(params[key]); | ||
} else { | ||
params[key] = self.encode(schema[key].raw_type, params[key]); | ||
params[key] = bufferToArray(params[key]); | ||
bytes.push((schema[key].field << 3) + schema[key].type); | ||
var encoded = encode(params[key].length); | ||
bytes = bytes.concat(bufferToArray(encoded)); | ||
bytes = bytes.concat(params[key]); | ||
} | ||
} else { | ||
bytes.push((schema[key].field << 3) + schema[key].type); | ||
var encoded = encode(Buffer.byteLength(params[key])); | ||
@@ -232,2 +251,3 @@ for (var i = 0; i < encoded.length; i++) { | ||
} else if (schema[key].type === 0) { | ||
bytes.push((schema[key].field << 3) + schema[key].type); | ||
var msg = encode(params[key]); | ||
@@ -234,0 +254,0 @@ msg = bufferToArray(msg); |
{ | ||
"name": "protobuf.js", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "a pure javascript protocol buffer encoding implementation, written specifically for riak", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11331
241
0
1