Permalink
Browse files

prepublish script for bin files, fixes #511; swallow enum value optio…

…ns (no wrapper), fixes #510; expose zero on LongBits, fixes #508
  • Loading branch information...
dcodeIO committed Dec 1, 2016
1 parent d3ae961 commit 6e5fdb67cb34f90932e95a51370e1652acc55b4c

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN -3 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -34,12 +34,14 @@
"zuul-local": "zuul --ui tape --no-coverage --concurrency 1 --local 8080 --disable-tunnel -- tests/*.js",
"bench": "node bench",
"all": "npm run lint && npm run test && npm run build && npm run types && npm run docs && npm run bench",
"postinstall": "npm install @types/node @types/long"
"prepublish": "node scripts/prepublish.js"
},
"optionalDependencies": {
"long": "^3.2.0"
},
"devDependencies": {
"@types/long": "^3.0.31",
"@types/node": "0.0.1",
"benchmark": "^2.1.2",
"browserify": "^13.1.1",
"bundle-collapser": "^1.2.1",
@@ -0,0 +1,7 @@
var path = require("path"),
fs = require("fs");
// ensure LF on bin files
[ path.join(__dirname, "..", "bin", "pbjs") ].forEach(function(file) {
fs.writeFileSync(file, fs.readFileSync(file).toString("utf8").replace(/\r?\n/g, "\n"), "utf8");
});
@@ -360,7 +360,8 @@ function parse(source, root) {
var name = token;
skip("=");
var value = parseId(next(), true);
parseInlineOptions(parent.values[name] = new Number(value)); // eslint-disable-line no-new-wrappers
parent.values[name] = value;
parseInlineOptions({}); // skips enum value options
}
function parseOption(parent, token) {
@@ -151,15 +151,19 @@ ServicePrototype.remove = function remove(object) {
/**
* Creates a runtime service using the specified rpc implementation.
* @param {RPCImpl} rpc 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.resolve().name] = function(request, callback) {
rpcService[method.name] = function(request, callback) {
method.resolve();
var requestData;
try {
requestData = (requestDelimited && method.resolvedRequestType.encodeDelimited(request) || method.resolvedRequestType.encode(request)).finish();
@@ -35,7 +35,7 @@ var LongBitsPrototype = LongBits.prototype;
* @memberof util.LongBits
* @type {util.LongBits}
*/
var zero = new LongBits(0, 0);
var zero = LongBits.zero = new LongBits(0, 0);
zero.toNumber = function() { return 0; };
zero.zzEncode = zero.zzDecode = function() { return this; };
@@ -71,9 +71,13 @@ LongBits.fromNumber = function fromNumber(value) {
* @returns {util.LongBits} Instance
*/
LongBits.from = function from(value) {
return typeof value === 'number'
? LongBits.fromNumber(value)
: new LongBits(value.low >>> 0, value.high >>> 0);
switch (typeof value) {
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;
};
/**
@@ -218,13 +218,7 @@ function writeVarint64(buf, pos, val) {
* @returns {Writer} `this`
*/
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);
};
@@ -280,24 +274,14 @@ WriterPrototype.sfixed32 = function write_sfixed32(value) {
return this.push(writeFixed32, 4, value << 1 ^ value >> 31);
};
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
* @returns {Writer} `this`
*/
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);
};
/**
@@ -3,7 +3,7 @@
/*
* protobuf.js v6.0.1 TypeScript definitions
* Generated Wed, 30 Nov 2016 22:05:17 UTC
* Generated Wed, 30 Nov 2016 22:50:15 UTC
*/
declare module protobuf {
@@ -1261,12 +1261,12 @@ declare module protobuf {
/**
* Creates a runtime service using the specified rpc implementation.
* @param {RPCImpl} rpc 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
*/
create(rpc: RPCImpl, requestDelimited?: boolean, responseDelimited?: boolean): Object;
create(rpc: (() => any), requestDelimited?: boolean, responseDelimited?: boolean): Object;
}

0 comments on commit 6e5fdb6

Please sign in to comment.