New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

protobuf.js

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobuf.js - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

84

index.js
var fs = require('fs'),
path = require('path');
path = require('path'),
butils = require('butils');

@@ -8,41 +9,2 @@ function Protobuf(schema) {

function bufferToArray(buffer) {
var bytes = [];
for (var i = 0; i < buffer.length; i++) {
bytes.push(buffer[i]);
}
return bytes;
}
function encode(num) {
function _rshift(num, bits) {
return num / Math.pow(2, bits);
}
if (num === 0) return new Buffer([0x00]);
var bytes = [];
while (num >= 0x80) {
bytes.push(num | 0x80);
num = _rshift(num, 7);
}
bytes.push(num);
return new Buffer(bytes);
}
function decode(varint) {
function _lshift(num, bits) {
return num * Math.pow(2, bits);
}
var nextByte,
result = 0,
bytesRead = 0;
do {
nextByte = varint[bytesRead];
result += _lshift((nextByte & 0x7F), (7 * bytesRead));
bytesRead++;
} while (nextByte >= 0x80);
return { num: result, bytes: bytesRead };
}
function parseSchema(file, filepath) {

@@ -172,3 +134,3 @@ var lines = file.split('\n'),

if (schema[key].type === 0) {
varint = decode(buffer.slice(1));
varint = butils.readVarint(buffer, 1);
len = varint.bytes + 1;

@@ -178,3 +140,3 @@ val = varint.num;

} else if (schema[key].type === 2) {
varint = decode(buffer.slice(1));
varint = butils.readVarint(buffer, 1);
len = varint.num + varint.bytes + 1;

@@ -185,3 +147,3 @@ if (schema[key].raw_type === 'string' || schema[key].raw_type === 'bytes') {

} else {
val = buffer.slice(varint.bytes + 1, len).toString();
val = butils.readString(buffer, varint.bytes + 1, len);
}

@@ -217,5 +179,4 @@ } else {

bytes.push((schema[key].field << 3) + schema[key].type);
var encoded = encode(params[key].length);
bytes = bytes.concat(bufferToArray(encoded));
bytes = bytes.concat(bufferToArray(params[key]));
butils.writeVarint(bytes, params[key].length, bytes.length);
butils.writeVarint(bytes, params[key], bytes.length);
} else if (typeof params[key] === 'object') {

@@ -228,18 +189,12 @@ if (Array.isArray(params[key])) {

});
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);
params[key].forEach(function (item) {
bytes.push((schema[key].field << 3) + schema[key].type);
butils.writeVarint(bytes, item.length, bytes.length);
bytes = bytes.concat(item);
});
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));
butils.writeVarint(bytes, params[key].length, bytes.length);
bytes = bytes.concat(params[key]);

@@ -249,15 +204,8 @@ }

bytes.push((schema[key].field << 3) + schema[key].type);
var encoded = encode(Buffer.byteLength(params[key]));
for (var i = 0; i < encoded.length; i++) {
bytes.push(encoded[i]);
}
for (var i = 0; i < params[key].length; i++) {
bytes.push(params[key].charCodeAt(i));
}
butils.writeVarint(bytes, Buffer.byteLength(params[key]), bytes.length);
butils.writeString(bytes, params[key], bytes.length);
}
} else if (schema[key].type === 0) {
bytes.push((schema[key].field << 3) + schema[key].type);
var msg = encode(params[key]);
msg = bufferToArray(msg);
bytes = bytes.concat(msg);
butils.writeVarint(bytes, params[key], bytes.length);
}

@@ -267,3 +215,3 @@ }

return new Buffer(bytes);
return bytes;
};

5

package.json
{
"name": "protobuf.js",
"version": "0.0.7",
"version": "0.0.8",
"description": "a pure javascript protocol buffer encoding implementation, written specifically for riak",
"main": "index.js",
"dependencies": {
"butils": ""
},
"repository": {

@@ -7,0 +10,0 @@ "type": "git",

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