New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 6.0.0 to 6.0.1

dist/protobuf.js

2

.eslintrc.json
{
"env": {
"node": true,
"shared-node-browser": true
"browser": true
},

@@ -6,0 +6,0 @@ "globals": {

@@ -13,3 +13,5 @@ module.exports = proto_target;

Service = protobuf.Service,
Method = protobuf.Method;
Method = protobuf.Method,
types = protobuf.types,
util = protobuf.util;

@@ -65,2 +67,18 @@ var out = [];

function escape(str) {
return str.replace(/[\\"']/g, '\\$&')
.replace(/\u0000/g, '\\0');
}
function value(v) {
switch (typeof v) {
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return v.toString();
default:
return '"' + escape(v + '') + '"';
}
}
function buildRoot(root) {

@@ -131,2 +149,14 @@ root.resolveAll();

function buildRanges(keyword, ranges) {
if (ranges && ranges.length) {
push("");
ranges.forEach(function(range) {
if (range[0] === range[1])
push(keyword + " " + range[0] + ";");
else
push(keyword + " " + range[0] + " to " + (range[1] === 0x1FFFFFFF ? "max" : range[1]) + ";");
});
}
}
function buildType(type) {

@@ -141,2 +171,4 @@ push("");

consolidateExtends(type.nestedArray).remaining.forEach(build);
buildRanges("extensions", type.extensions);
buildRanges("reserved", type.reserved);
--indent;

@@ -147,3 +179,3 @@ push("}");

function buildField(field, passExtend) {
if (field.partOf || field.declaringType || (field.extend !== undefined && !passExtend))
if (field.partOf || field.declaringField || (field.extend !== undefined && !passExtend))
return;

@@ -162,18 +194,42 @@ if (first)

sb.push(under_score(field.name), "=", field.id);
var opts = [];
if (field.repeated) {
if (syntax === 2) {
if (field.packed)
opts.push("packed=true");
} else {
if (!field.packed)
opts.push("packed=false");
}
// TODO: Proper field options
}
if (opts.length)
sb.push("[" + opts.join(', ') + "]");
var opts = buildFieldOptions(field);
if (opts)
sb.push(opts);
push(sb.join(" ") + ";");
}
function buildFieldOptions(field) {
var keys;
if (!field.options || !(keys = Object.keys(field.options)).length)
return null;
var sb = [];
Object.keys(field.options).forEach(function(key) {
var val = field.options[key];
var wireType = types.packed[field.resolvedType instanceof Enum ? "uint32" : field.type];
switch (key) {
case "packed":
val = Boolean(val);
// skip when not packable or syntax default
if (wireType === undefined || (syntax === 3) === val)
return;
break;
case "default":
// skip default (resolved) default values
if (field.long && !util.longNeq(field.defaultValue, types.defaults[field.type]) || !field.long && field.defaultValue === types.defaults[field.type])
return;
// enum defaults specified as strings are type references and not enclosed in quotes
if (field.resolvedType instanceof Enum)
break;
// otherwise fallthrough
default:
val = value(val);
break;
}
sb.push(key + "=" + val);
});
return sb.length
? "[" + sb.join(", ") + "]"
: null;
}
function consolidateExtends(nested) {

@@ -210,3 +266,4 @@ var ext = {};

push(""), first = false;
push(field.type + " " + under_score(field.name) + " = " + field.id + ";");
var opts = buildFieldOptions(field);
push(field.type + " " + under_score(field.name) + " = " + field.id + (opts ? " " + opts : "") + ";");
});

@@ -213,0 +270,0 @@ --indent;

{
"name": "protobufjs",
"version": "6.0.0",
"version": "6.0.1",
"description": "Protocol Buffers for JavaScript.",

@@ -36,3 +36,4 @@ "author": "Daniel Wirtz",

"bench": "node bench",
"all": "npm run lint && npm run test && npm run build && npm run docs && npm run types && npm run bench"
"all": "npm run lint && npm run test && npm run build && npm run types && npm run docs && npm run bench",
"prepublish": "node scripts/prepublish.js"
},

@@ -43,2 +44,4 @@ "optionalDependencies": {

"devDependencies": {
"@types/long": "^3.0.31",
"@types/node": "0.0.1",
"benchmark": "^2.1.2",

@@ -69,9 +72,3 @@ "browserify": "^13.1.1",

"zuul-ngrok": "^4.0.0"
},
"browser": {
"process": false,
"_process": false,
"buffer": false,
"fs": false
}
}

@@ -7,2 +7,5 @@ var fs = require("fs"),

var header = [
'/// <reference path="../node_modules/@types/node/index.d.ts" />',
'/// <reference path="../node_modules/@types/long/index.d.ts" />',
"",
"/*",

@@ -9,0 +12,0 @@ " * protobuf.js v" + pkg.version + " TypeScript definitions",

@@ -64,3 +64,3 @@ "use strict";

* @param {Writer} [writer] Writer to use
* @returns {number[]} Encoded message
* @returns {Uint8Array} Encoded message
*/

@@ -79,3 +79,3 @@ encode: {

* @param {Writer} [writer] Writer to use
* @returns {number[]} Encoded message
* @returns {Uint8Array} Encoded message
*/

@@ -92,3 +92,3 @@ encodeDelimited: {

* @function
* @param {number[]} buffer Buffer to decode
* @param {Uint8Array} buffer Buffer to decode
* @returns {Prototype} Decoded message

@@ -106,3 +106,3 @@ */

* @function
* @param {number[]} buffer Buffer to decode
* @param {Uint8Array} buffer Buffer to decode
* @returns {Prototype} Decoded message

@@ -109,0 +109,0 @@ */

@@ -40,3 +40,3 @@ "use strict";

throw _TypeError("responseType");
ReflectionObject.call(this, name, options);

@@ -134,3 +134,4 @@

throw Error("unresolvable response type: " + this.requestType);
this.resolvedResponseType = resolved;
return ReflectionObject.prototype.resolve.call(this);
};

@@ -121,16 +121,15 @@ "use strict";

* Adds nested elements to this namespace from JSON.
* @param {Object.<string,*>} json Nested JSON
* @param {Object.<string,*>} nestedJson Nested JSON
* @returns {Namespace} `this`
*/
NamespacePrototype.addJSON = function addJSON(json) {
if (json) {
var keys = Object.keys(json);
for (var i = 0; i < keys.length; ++i) {
var nested = json[keys[i]];
NamespacePrototype.addJSON = function addJSON(nestedJson) {
var ns = this;
if (nestedJson)
Object.keys(nestedJson).forEach(function(nestedName) {
var nested = nestedJson[nestedName];
for (var j = 0; j < nestedTypes.length; ++j)
if (nestedTypes[j].testJSON(nested))
return this.add(nestedTypes[j].fromJSON(keys[i], nested));
throw _TypeError("json." + keys[i], "JSON for " + nestedError);
}
}
return ns.add(nestedTypes[j].fromJSON(nestedName, nested));
throw _TypeError("nested." + nestedName, "JSON for " + nestedError);
});
return this;

@@ -240,3 +239,6 @@ };

while (i < nested.length)
nested[i++].resolve();
if (nested[i] instanceof Namespace)
nested[i++].resolveAll();
else
nested[i++].resolve();
return ReflectionObject.prototype.resolve.call(this);

@@ -248,3 +250,3 @@ };

* @param {string|string[]} path Path to look up
* @param {boolean} [parentAlreadyChecked] Whether the parent has already been checked
* @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
* @returns {?ReflectionObject} Looked up object or `null` if none could be found

@@ -251,0 +253,0 @@ */

@@ -148,3 +148,3 @@ "use strict";

return sign * parseInt(token, 8);
if (/^[0-9]*(?:\.[0-9]*)?(?:[e][+-]?[0-9]+)?$/.test(tokenLower))
if (/^(?!e)[0-9]*(?:\.[0-9]*)?(?:[e][+-]?[0-9]+)?$/.test(tokenLower))
return sign * parseFloat(token);

@@ -154,3 +154,3 @@ throw illegal(token, 'number');

function parseId(token) {
function parseId(token, acceptNegative) {
var tokenLower = lower(token);

@@ -162,7 +162,9 @@ switch (tokenLower) {

}
if (/^[1-9][0-9]*$/.test(token))
if (token.charAt(0) === '-' && !acceptNegative)
throw illegal(token, "id");
if (/^-?[1-9][0-9]*$/.test(token))
return parseInt(token, 10);
if (/^0[x][0-9a-f]+$/.test(tokenLower))
if (/^-?0[x][0-9a-f]+$/.test(tokenLower))
return parseInt(token, 16);
if (/^0[0-7]+$/.test(token))
if (/^-?0[0-7]+$/.test(token))
return parseInt(token, 8);

@@ -363,4 +365,5 @@ throw illegal(token, "id");

skip("=");
var value = parseId(next());
parseInlineOptions(parent.values[name] = new Number(value)); // eslint-disable-line no-new-wrappers
var value = parseId(next(), true);
parent.values[name] = value;
parseInlineOptions({}); // skips enum value options
}

@@ -367,0 +370,0 @@

@@ -12,3 +12,3 @@ "use strict";

function indexOutOfRange(reader, writeLength) {
return "index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len;
return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
}

@@ -21,13 +21,11 @@

* @constructor
* @param {number[]} buffer Buffer to read from
* @param {Uint8Array} buffer Buffer to read from
*/
function Reader(buffer) {
if (!(this instanceof Reader))
return util.Buffer && (!buffer || util.Buffer.isBuffer(buffer))
? new BufferReader(buffer)
: new Reader(buffer);
return util.Buffer && (!buffer || util.Buffer.isBuffer(buffer)) && new BufferReader(buffer) || new Reader(buffer);
/**
* Read buffer.
* @type {number[]}
* @type {Uint8Array}
*/

@@ -73,3 +71,3 @@ this.buf = buffer;

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
return new Tag(this.buf[this.pos] >>> 3, this.buf[this.pos++] & 7);

@@ -88,3 +86,3 @@ };

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
octet = this.buf[this.pos++];

@@ -146,3 +144,3 @@ if (shift < 32)

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
b = this.buf[this.pos++];

@@ -154,3 +152,3 @@ lo |= (b & 127) << i * 7;

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
b = this.buf[this.pos++];

@@ -163,3 +161,3 @@ lo |= (b & 127) << 28;

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
b = this.buf[this.pos++];

@@ -233,3 +231,3 @@ hi |= (b & 127) << i * 7 + 3;

if (this.pos + 4 > this.len)
throw RangeError(indexOutOfRange(this, 4));
throw indexOutOfRange(this, 4);
this.pos += 4;

@@ -260,3 +258,3 @@ return this.buf[this.pos - 4]

if (this.pos + 8 > this.len)
throw RangeError(indexOutOfRange(this, 8));
throw indexOutOfRange(this, 8);
return new LongBits(

@@ -311,3 +309,3 @@ ( this.buf[this.pos++]

if (this.pos + 4 > this.len)
throw RangeError(indexOutOfRange(this, 4));
throw indexOutOfRange(this, 4);
var value = ieee754.read(this.buf, this.pos, false, 23, 4);

@@ -325,3 +323,3 @@ this.pos += 4;

if (this.pos + 8 > this.len)
throw RangeError(indexOutOfRange(this, 4));
throw indexOutOfRange(this, 4);
var value = ieee754.read(this.buf, this.pos, false, 52, 8);

@@ -334,3 +332,3 @@ this.pos += 8;

* Reads a sequence of bytes preceeded by its length as a varint.
* @returns {number[]} Value read
* @returns {Uint8Array} Value read
*/

@@ -342,3 +340,3 @@ ReaderPrototype.bytes = function read_bytes() {

if (end > this.len)
throw RangeError(indexOutOfRange(this, length));
throw indexOutOfRange(this, length);
this.pos += length;

@@ -387,7 +385,7 @@ return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1

if (this.pos >= this.len)
throw RangeError(indexOutOfRange(this));
throw indexOutOfRange(this);
} while (this.buf[this.pos++] & 128);
} else {
if (this.pos + length > this.len)
throw RangeError(indexOutOfRange(this, length));
throw indexOutOfRange(this, length);
this.pos += length;

@@ -433,3 +431,3 @@ }

* Resets this instance and frees all resources.
* @param {number[]} [buffer] New buffer for a new sequence of read operations
* @param {Uint8Array} [buffer] New buffer for a new sequence of read operations
* @returns {Reader} `this`

@@ -451,4 +449,4 @@ */

* Finishes the current sequence of read operations, frees all resources and returns the remaining buffer.
* @param {number[]} [buffer] New buffer for a new sequence of read operations
* @returns {number[]} Finished buffer
* @param {Uint8Array} [buffer] New buffer for a new sequence of read operations
* @returns {Uint8Array} Finished buffer
*/

@@ -490,8 +488,7 @@ ReaderPrototype.finish = function finish(buffer) {

/**
* Reads a float (32 bit) as a number using node buffers.
* @returns {number} Value read
* @override
*/
BufferReaderPrototype.float = function read_float_buffer() {
if (this.pos + 4 > this.len)
throw RangeError(indexOutOfRange(this, 4));
throw indexOutOfRange(this, 4);
var value = this.buf.readFloatLE(this.pos, true);

@@ -503,8 +500,7 @@ this.pos += 4;

/**
* Reads a double (64 bit float) as a number using node buffers.
* @returns {number} Value read
* @override
*/
BufferReaderPrototype.double = function read_double_buffer() {
if (this.pos + 8 > this.len)
throw RangeError(indexOutOfRange(this, 8));
throw indexOutOfRange(this, 8);
var value = this.buf.readDoubleLE(this.pos, true);

@@ -516,4 +512,3 @@ this.pos += 8;

/**
* Reads a string.
* @returns {string} Value read
* @override
*/

@@ -525,3 +520,3 @@ BufferReaderPrototype.string = function read_string_buffer() {

if (end > this.len)
throw RangeError(indexOutOfRange(this, length));
throw indexOutOfRange(this, length);
this.pos += length;

@@ -532,5 +527,3 @@ return this.buf.toString("utf8", start, end);

/**
* Finishes the current sequence of read operations using node buffers, frees all resources and returns the remaining buffer.
* @param {Buffer} [buffer] New buffer for a new sequence of read operations
* @returns {Buffer} Finished buffer
* @override
*/

@@ -537,0 +530,0 @@ BufferReaderPrototype.finish = function finish_buffer(buffer) {

@@ -44,3 +44,3 @@ "use strict";

root = new Root();
return root.addJSON(json);
return root.setOptions(json.options).addJSON(json.nested);
};

@@ -84,8 +84,6 @@

source = JSON.parse(source);
if (!util.isString(source)) {
if (!util.isString(source))
self.setOptions(source.options).addJSON(source.nested);
self.files.push(filename);
} else {
else {
var parsed = require("./parse")(source, self);
self.files.push(filename);
if (parsed.imports)

@@ -111,3 +109,3 @@ parsed.imports.forEach(function(name) {

// Check if this file references a bundled definition
// Strip path if this file references a bundled definition
var idx = filename.indexOf("google/protobuf/");

@@ -123,2 +121,3 @@ if (idx > -1) {

return;
self.files.push(filename);

@@ -125,0 +124,0 @@ // Shortcut bundled definitions

@@ -77,3 +77,8 @@ "use strict";

Service.fromJSON = function fromJSON(name, json) {
return new Service(name, json.options);
var service = new Service(name, json.options);
if (json.methods)
Object.keys(json.methods).forEach(function(methodName) {
service.add(Method.fromJSON(methodName, json.methods[methodName]));
});
return service;
};

@@ -137,1 +142,54 @@

};
/**
* RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
* @typedef RPCImpl
* @function
* @param {Method} method Reflected method being called
* @param {Uint8Array} requestData Request data
* @param {function(?Error, Uint8Array=)} callback Node-style callback called with the error, if any, and the response data
* @returns {undefined}
*/
/**
* Creates a runtime service using the specified rpc implementation.
* @param {function(Method, Uint8Array, function)} rpc RPC implementation ({@link RPCImpl|see})
* @param {boolean} [requestDelimited=false] Whether request data is length delimited
* @param {boolean} [responseDelimited=false] Whether response data is length delimited
* @returns {Object} Runtime service
*/
ServicePrototype.create = function create(rpc, requestDelimited, responseDelimited) {
var rpcService = {};
Object.defineProperty(rpcService, "$rpc", {
value: rpc
});
this.getMethodsArray().forEach(function(method) {
rpcService[method.name] = function(request, callback) {
method.resolve();
var requestData;
try {
requestData = (requestDelimited && method.resolvedRequestType.encodeDelimited(request) || method.resolvedRequestType.encode(request)).finish();
} catch (err) {
(typeof setImmediate === 'function' && setImmediate || setTimeout)(function() { callback(err); });
return;
}
// Calls the custom RPC implementation with the reflected method and binary request data
// and expects the rpc implementation to call its callback with the binary response data.
rpc(method, requestData, function(err, responseData) {
if (err) {
callback(err);
return;
}
var response;
try {
response = responseDelimited && method.resolvedResponseType.decodeDelimited(responseData) || method.resolvedResponseType.decode(responseData);
} catch (err2) {
callback(err2);
return;
}
callback(null, response);
});
};
});
return rpcService;
};
"use strict";
/* eslint-disable default-case, callback-return */
module.exports = tokenize;

@@ -23,2 +22,16 @@

function unescape(str) {
return str.replace(/\\(.?)/g, function($0, $1) {
switch ($1) {
case "\\":
case "":
return $1;
case "0":
return "\u0000";
default:
return $1;
}
});
}
/**

@@ -30,2 +43,3 @@ * Tokenizes the given .proto source and returns an object with useful utility functions.

function tokenize(source) {
/* eslint-disable default-case, callback-return */
source = source.toString();

@@ -65,3 +79,3 @@

stringDelim = null;
return match[1];
return unescape(match[1]);
}

@@ -194,2 +208,3 @@

};
/* eslint-enable default-case, callback-return */
}

@@ -208,3 +208,3 @@ "use strict";

type.add(nestedTypes[i].fromJSON(nestedName, nested));
break;
return;
}

@@ -214,2 +214,6 @@ }

});
if (json.extensions && json.extensions.length)
type.extensions = json.extensions;
if (json.reserved && json.reserved.length)
type.reserved = json.reserved;
return type;

@@ -224,6 +228,8 @@ };

return {
options : inherited && inherited.options || undefined,
oneofs : Namespace.arrayToJSON(this.getOneofsArray()),
fields : Namespace.arrayToJSON(this.getFieldsArray().filter(function(obj) { return !obj.declaringField; })) || {},
nested : inherited && inherited.nested || undefined
options : inherited && inherited.options || undefined,
oneofs : Namespace.arrayToJSON(this.getOneofsArray()),
fields : Namespace.arrayToJSON(this.getFieldsArray().filter(function(obj) { return !obj.declaringField; })) || {},
extensions : this.extensions && this.extensions.length ? this.extensions : undefined,
reserved : this.reserved && this.reserved.length ? this.reserved : undefined,
nested : inherited && inherited.nested || undefined
};

@@ -351,3 +357,3 @@ };

* Decodes a message of this type.
* @param {Reader|number[]} readerOrBuffer Reader or buffer to decode from
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Length of the message, if known beforehand

@@ -366,3 +372,3 @@ * @returns {Prototype} Decoded message

* Decodes a message of this type preceeded by its byte length as a varint.
* @param {Reader|number[]} readerOrBuffer Reader or buffer to decode from
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {Prototype} Decoded message

@@ -369,0 +375,0 @@ */

@@ -18,3 +18,3 @@ "use strict";

*/
var isNode = util.isNode = Boolean(typeof process !== 'undefined' && process.versions && process.versions.node);
var isNode = util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);

@@ -36,5 +36,6 @@ /**

*/
util.Long = global.Long || null;
util.Long = global.dcodeIO && global.dcodeIO.Long || null;
try { util.Long = require("long"); } catch (e) {} // eslint-disable-line no-empty
if (!util.Long)
try { util.Long = require("long"); } catch (e) {} // eslint-disable-line no-empty

@@ -291,3 +292,3 @@ /**

* @param {number} [size=0] Buffer size
* @returns {Buffer|Uint8Array|Array} Buffer
* @returns {Uint8Array} Buffer
*/

@@ -294,0 +295,0 @@ util.newBuffer = function newBuffer(size) {

@@ -38,3 +38,3 @@ "use strict";

*/
var zero = new LongBits(0, 0);
var zero = LongBits.zero = new LongBits(0, 0);

@@ -70,10 +70,15 @@ zero.toNumber = function() { return 0; };

/**
* Constrcuts new long bits from a number or long.
* @param {Long|number} value Value
* Constructs new long bits from a number, long or string.
* @param {Long|number|string} value Value
* @returns {util.LongBits} Instance
* @throws {TypeError} If `value` is a string and no long library is present.
*/
LongBits.from = function from(value) {
return typeof value === 'number'
? LongBits.fromNumber(value)
: new LongBits(value.low >>> 0, value.high >>> 0);
switch (typeof value) { // eslint-disable-line default-case
case 'number':
return LongBits.fromNumber(value);
case 'string':
value = util.Long.fromString(value); // throws without a long lib
}
return (value.low || value.high) && new LongBits(value.low >>> 0, value.high >>> 0) || zero;
};

@@ -80,0 +85,0 @@

@@ -15,3 +15,3 @@ "use strict";

* @constructor
* @param {function(number[], number, *)} fn Function to call
* @param {function(Uint8Array, number, *)} fn Function to call
* @param {*} val Value to write

@@ -26,3 +26,3 @@ * @param {number} len Value byte length

* Function to call.
* @type {function(number[], number, *)}
* @type {function(Uint8Array, number, *)}
*/

@@ -97,5 +97,3 @@ this.fn = fn;

if (!(this instanceof Writer))
return util.Buffer
? new BufferWriter()
: new Writer();
return util.Buffer && new BufferWriter() || new Writer();

@@ -138,3 +136,3 @@ /**

* Pushes a new operation to the queue.
* @param {function(number[], number, *)} fn Function to call
* @param {function(Uint8Array, number, *)} fn Function to call
* @param {number} len Value byte length

@@ -153,3 +151,3 @@ * @param {number} val Value to write

function writeByte(buf, pos, val) {
buf[pos] = val;
buf[pos] = val & 255;
}

@@ -164,3 +162,3 @@

WriterPrototype.tag = function write_tag(id, wireType) {
return this.push(writeByte, 1, (id << 3 | wireType & 7) & 255);
return this.push(writeByte, 1, id << 3 | wireType & 7);
};

@@ -198,3 +196,7 @@

*/
WriterPrototype.int32 = WriterPrototype.uint32;
WriterPrototype.int32 = function write_int32(value) {
return value < 0
? this.push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
: this.uint32(value);
};

@@ -222,13 +224,8 @@ /**

* Writes an unsigned 64 bit value as a varint.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.uint64 = function write_uint64(value) {
var bits;
if (typeof value === 'number')
bits = value ? LongBits.fromNumber(value) : LongBits.zero;
else if (value.low || value.high)
bits = new LongBits(value.low >>> 0, value.high >>> 0);
else
bits = LongBits.zero;
var bits = LongBits.from(value);
return this.push(writeVarint64, bits.length(), bits);

@@ -240,4 +237,5 @@ };

* @function
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/

@@ -248,4 +246,5 @@ WriterPrototype.int64 = WriterPrototype.uint64;

* Writes a signed 64 bit value as a varint, zig-zag encoded.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/

@@ -291,20 +290,11 @@ WriterPrototype.sint64 = function sint64(value) {

function writeFixed64(buf, pos, val) {
buf[pos++] = val.lo & 255;
buf[pos++] = val.lo >>> 8 & 255;
buf[pos++] = val.lo >>> 16 & 255;
buf[pos++] = val.lo >>> 24 ;
buf[pos++] = val.hi & 255;
buf[pos++] = val.hi >>> 8 & 255;
buf[pos++] = val.hi >>> 16 & 255;
buf[pos ] = val.hi >>> 24 ;
}
/**
* Writes a 64 bit value as fixed 64 bits.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.fixed64 = function write_fixed64(value) {
return this.push(writeFixed64, 8, LongBits.from(value));
var bits = LongBits.from(value);
return this.push(writeFixed32, 4, bits.hi).push(writeFixed32, 4, bits.lo);
};

@@ -314,7 +304,9 @@

* Writes a 64 bit value as fixed 64 bits, zig-zag encoded.
* @param {Long|number} value Value to write
* @param {Long|number|string} value Value to write
* @returns {Writer} `this`
* @throws {TypeError} If `value` is a string and no long library is present.
*/
WriterPrototype.sfixed64 = function write_sfixed64(value) {
return this.push(writeFixed64, 8, LongBits.from(value).zzEncode());
var bits = LongBits.from(value).zzEncode();
return this.push(writeFixed32, 4, bits.hi).push(writeFixed32, 4, bits.lo);
};

@@ -356,3 +348,3 @@

* Writes a sequence of bytes.
* @param {number[]} value Value to write
* @param {Uint8Array} value Value to write
* @returns {Writer} `this`

@@ -368,4 +360,4 @@ */

function writeString(buf, pos, val) {
for (var i = 0, len = val.length, c1, c2; i < len; ++i) {
c1 = val.charCodeAt(i);
for (var i = 0; i < val.length; ++i) {
var c1 = val.charCodeAt(i), c2;
if (c1 < 128) {

@@ -376,3 +368,3 @@ buf[pos++] = c1;

buf[pos++] = c1 & 63 | 128;
} else if ((c1 & 0xFC00) === 0xD800 && i + 1 < len && ((c2 = val.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
} else if ((c1 & 0xFC00) === 0xD800 && i + 1 < val.length && ((c2 = val.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);

@@ -475,3 +467,3 @@ ++i;

* Finishes the current sequence of write operations and frees all resources.
* @returns {number[]} Finished buffer
* @returns {Uint8Array} Finished buffer
*/

@@ -511,5 +503,3 @@ WriterPrototype.finish = function finish() {

/**
* Writes a float (32 bit) using node buffers.
* @param {number} value Value to write
* @returns {BufferWriter} `this`
* @override
*/

@@ -525,5 +515,3 @@ BufferWriterPrototype.float = function write_float_buffer(value) {

/**
* Writes a double (64 bit float) using node buffers.
* @param {number} value Value to write
* @returns {BufferWriter} `this`
* @override
*/

@@ -540,5 +528,3 @@ BufferWriterPrototype.double = function write_double_buffer(value) {

/**
* Writes a sequence of bytes using node buffers.
* @param {Buffer} value Value to write
* @returns {BufferWriter} `this`
* @override
*/

@@ -557,5 +543,3 @@ BufferWriterPrototype.bytes = function write_bytes_buffer(value) {

/**
* Writes a string using node buffers.
* @param {string} value Value to write
* @returns {BufferWriter} `this`
* @override
*/

@@ -570,4 +554,3 @@ BufferWriterPrototype.string = function write_string_buffer(value) {

/**
* Finishes the current sequence of write operations using node buffers and frees all resources.
* @returns {Buffer} Finished buffer
* @override
*/

@@ -574,0 +557,0 @@ BufferWriterPrototype.finish = function finish_buffer() {

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

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

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

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