Breaking: Dropped IE8 support; New: Converters use code generation and support custom implementations; CLI: Generated static code now supports asJSON/from

This commit is contained in:
dcodeIO 2017-01-02 05:46:27 +01:00
parent 39bc1031bb
commit a017bf8a2d
63 changed files with 10657 additions and 5238 deletions

View File

@ -9,7 +9,7 @@ browsers:
- name: safari
version: [5, latest]
- name: ie
version: [8, 9, 10, 11]
version: [9, 10, 11]
- name: opera
version: [11, 12]
- name: android

View File

@ -1,15 +1,33 @@
# [6.3.2](https://github.com/dcodeIO/protobuf.js/releases/tag/6.3.2)
# [6.4.0](https://github.com/dcodeIO/protobuf.js/releases/tag/6.4.0)
## Breaking
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/39bc1031bb502f8b677b3736dd283736ea4d92c1) Removed now unused util.longNeq which was used by early static code<br />
## Fixed
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/7eb3d456370d7d66b0856e32b2d2602abf598516) Respect optional properties when writing interfaces in tsd-jsdoc, fixes [#598](https://github.com/dcodeIO/protobuf.js/issues/598)<br />
## New
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/28ce07d9812f5e1743afef95a94532d2c9488a84) Be more verbose when throwing invalid wire type errors, see [#602](https://github.com/dcodeIO/protobuf.js/issues/602)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/40074bb69c3ca4fcefe09d4cfe01f3a86844a7e8) Added an asJSON-option to always populate array fields, even if defaults=false, see [#597](https://github.com/dcodeIO/protobuf.js/issues/597)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/a7d23240a278aac0bf01767b6096d692c09ae1ce) Attempt to improve TypeScript support by using explicit exports<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/cec253fb9a177ac810ec96f4f87186506091fa37) Copy-pasted typescript definitions to micro modules, see [#599](https://github.com/dcodeIO/protobuf.js/issues/599)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/1f18453c7bfcce65c258fa98a3e3d4577d2e550f) Emit an error on resolveAll() if any extension fields cannot be resolved, see [#595](https://github.com/dcodeIO/protobuf.js/issues/595) + test case<br />
## CLI
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/3c775535517b8385a1d3c1bf056f3da3b4266f8c) Added support for TypeScript enums to pbts<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0cda72a55a1f2567a5d981dc5d924e55b8070513) Added a few helpful comments to static code<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/24b293c297feff8bda5ee7a2f8f3f83d77c156d0) Slightly beautify statically generated code<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/65637ffce20099df97ffbcdce50faccc8e97c366) Do not wrap main definition as a module and export directly instead<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/65637ffce20099df97ffbcdce50faccc8e97c366) Generate prettier definitions with --no-comments<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/20d8a2dd93d3bbb6990594286f992e703fc4e334) Added variable arguments support to tsd-jsdoc<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/8493dbd9a923693e943f710918937d83ae3c4572) Reference dependency imports as a module to prevent name collisions, see [#596](https://github.com/dcodeIO/protobuf.js/issues/596)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/39a2ea361c50d7f4aaa0408a0d55bb13823b906c) Removed now unnecessary comment lines in generated static code<br />
## Other
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/805291086f6212d1f108b3d8f36325cf1739c0bd) Reverted previous attempt on [#597](https://github.com/dcodeIO/protobuf.js/issues/597)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/c5160217ea95996375460c5403dfe37b913d392e) Minor tsd-jsdoc refactor<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/961dd03061fc2c43ab3bf22b3f9f5165504c1002) Removed unused sandbox files<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/f625eb8b0762f8f5d35bcd5fc445e52b92d8e77d) Updated package.json of micro modules to reference types, see [#599](https://github.com/dcodeIO/protobuf.js/issues/599)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/46ec8209b21cf9ff09ae8674e2a5bbc49fd4991b) Reference dependencies as imports in generated typescript definitions, see [#596](https://github.com/dcodeIO/protobuf.js/issues/596)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/c0ab94c2e469c0fbf790e4807f24fddd6370e342) Reference dependencies as imports in generated typescript definitions, see [#596](https://github.com/dcodeIO/protobuf.js/issues/596)<br />
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/3bab132b871798c7c50c60a4c14c2effdffa372e) Allow null values on optional long fields, see [#590](https://github.com/dcodeIO/protobuf.js/issues/590)<br />

View File

@ -541,7 +541,7 @@ Compatibility
* Because the internals of this package do not rely on `google/protobuf/descriptor.proto`, options are parsed and presented literally.
* If typed arrays are not supported by the environment, plain arrays will be used instead.
* Support for pre-ES5 environments like IE8 can be achieved by [using a polyfill](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/polyfill.js) and, instead of using property getters and setters on reflection objects, calling the respective functions prefixed with `get`, `set` or `is` directly (i.e. calling `Type#getFieldsById()` instead of accessing `Type#fieldsById`). Note that this also applies to virtual oneof properties (use `getKind`, `setKind` for example if the oneof is named `kind`).
* Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/dcodeIO/protobuf.js/blob/master/scripts/polyfill.js).
* If you need a proper way to work with 64 bit values (uint64, int64 etc.), you can install [long.js](https://github.com/dcodeIO/long.js) alongside this library. All 64 bit numbers will then be returned as a `Long` instance instead of a possibly unsafe JavaScript number ([see](https://github.com/dcodeIO/long.js)).
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)

View File

@ -26,14 +26,17 @@ exports.main = function(args, callback) {
root : "r"
},
string: [ "target", "out", "path", "wrap", "root" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "delimited" ],
boolean: [ "keep-case", "create", "encode", "decode", "verify", "convert", "delimited", "beautify", "comments" ],
default: {
target: "json",
create: true,
encode: true,
decode: true,
verify: true,
delimited: true
target : "json",
create : true,
encode : true,
decode : true,
verify : true,
convert : true,
delimited : true,
beautify : true,
comments : true
}
});
@ -81,7 +84,10 @@ exports.main = function(args, callback) {
" --no-encode Does not generate encode functions.",
" --no-decode Does not generate decode functions.",
" --no-verify Does not generate verify functions.",
" --no-convert Does not generate convert functions like asJSON and from.",
" --no-delimited Does not generate delimited encode/decode functions.",
" --no-beautify Does not beautify generated code.",
" --no-comments Does not output any JSDoc comments.",
"",
"usage: " + chalk.bold.green("pbjs") + " [options] file1.proto file2.json ..."
].join("\n"));

View File

@ -1,11 +1,11 @@
"use strict";
module.exports = static_target;
// - Static code does not have any reflection or JSON features.
var protobuf = require("../.."),
cliUtil = require("../util");
var UglifyJS = cliUtil.require("uglify-js", require(require("path").join(__dirname, "..", "..", "package.json")).devDependencies["uglify-js"]);
var Type = protobuf.Type,
Service = protobuf.Service,
Enum = protobuf.Enum,
@ -22,14 +22,17 @@ static_target.description = "Static code without reflection";
function static_target(root, options, callback) {
config = options;
try {
push("// Lazily resolved type references");
if (config.comments)
push("// Lazily resolved type references");
push("var $lazyTypes = [];");
push("");
push("// Exported root namespace");
if (config.comments)
push("// Exported root namespace");
push("var $root = {};");
buildNamespace(null, root);
push("");
push("// Resolve lazy types");
if (config.comments)
push("// Resolve lazy types");
push("$lazyTypes.forEach(function(types) {");
++indent;
push("types.forEach(function(path, i) {");
@ -38,7 +41,7 @@ function static_target(root, options, callback) {
++indent;
push("return;");
--indent;
push("path = path.split('.');");
push("path = path.split(\".\");");
push("var ptr = $root;");
push("while (path.length)");
++indent;
@ -70,6 +73,8 @@ function push(line) {
}
function pushComment(lines) {
if (!config.comments)
return;
push("/**");
lines.forEach(function(line) {
if (line === null)
@ -85,6 +90,12 @@ function name(name) {
return cliUtil.reserved(name) ? name + "_" : name;
}
function aOrAn(name) {
return ((/^[hH](?:ou|on|ei)/.test(name) || /^[aeiouAEIOU][a-z]/.test(name)) && !/^us/i.test(name)
? "an "
: "a ") + name;
}
// generate dot-notation property accessors where possible. this saves a few chars (i.e. m.hello
// instead of m["hello"]) but has no measurable performance impact (on V8). not present within the
// library itself because the reserved words check requires a rather longish regex.
@ -133,43 +144,52 @@ function buildNamespace(ref, ns) {
}
}
function slightlyBeautify(generatedCode) {
return generatedCode
.replace(/(!?[=<>|&%?:]+)([^\s])/g, " $1 $2") // a!==b, a&&b, a?b:c etc.
.replace(/\b([+-])\b/g," $1 ") // a+b
.replace(/\b(if|else|else if|for|while|do|switch)\(/g, "$1 (") // if(a)
.replace(/\b(return|case)"/g, "$1 \"") // return"error", case"one"
.replace(/([;,])([^\s])/g, "$1 $2") // cond(var a=0;a<b;++b), var a=1,b;
.replace(/{$/mg, " {")
function beautify(code) {
return UglifyJS.minify(code
.replace(/\br\b/g, "reader")
.replace(/\bw\b/g, "writer")
.replace(/\bm\b/g, "message")
.replace(/\bt\b/g, "tag")
.replace(/\bl\b/g, "length")
.replace(/\bl\b/g, "len")
.replace(/\bc\b/g, "end")
.replace(/\bc2\b/g, "end2")
.replace(/\bk\b/g, "key")
.replace(/\bks\b/g, "keys")
.replace(/\bs\b/g, "reason")
.replace(/(uint32)\((\d+)\)/g, function($0, $1, $2) {
var tag = parseInt($2, 10);
return $1 + "(" + tag + "/*= id " + (tag >>> 3) + ", wireType " + (tag & 7) + " */)";
});
.replace(/\be\b/g, "err")
.replace(/\bf\b/g, "impl")
.replace(/\bo\b/g, "options")
.replace(/\bs\b/g, "src")
.replace(/\bd\b/g, "dst"),
{
fromString: true,
compress: false,
mangle: false,
output: {
beautify: true,
bracketize: true,
screw_ie8: false
}
}
).code.replace(/ {4}/g, "\t");
}
function buildFunction(type, functionName, gen, scope) {
var lines = slightlyBeautify(gen.str(functionName)
.replace("(this.getCtor())", " $root" + type.fullName))
.split(/\n/g);
var code = gen.str(functionName)
.replace("(this.ctor)", " $root" + type.fullName) // types: construct directly instead of using reflected ctor
.replace(/(types\[\d+])(\.values)/,"$1"); // enums: use types[N] instead of reflected types[N].values
// add referenced types to scope
scope["types"] = "[" + type.fieldsArray.map(function(field) {
return field.resolve().resolvedType
? JSON.stringify(field.resolvedType.fullName.substring(1))
: "null";
}).join(", ") + "]";
if (config.beautify)
code = beautify(code);
// remove unused scope vars
Object.keys(scope).forEach(function(key) {
if (!new RegExp("\\b(" + key + ")\\b", "g").test(code))
delete scope[key];
});
// enclose all but the first and last line in an iife returning our properly scoped function
push(name(type.name) + "." + functionName + " = /* eslint-disable */ (function(" + Object.keys(scope).join(", ") + ") { $lazyTypes.push(types); return " + lines[0]);
var lines = code.split(/\n/g);
push(name(type.name) + "." + functionName + " = (function(" + Object.keys(scope).join(", ") + ") { return " + lines[0]);
lines.slice(1, lines.length - 1).forEach(function(line) {
var prev = indent;
var i = 0;
@ -178,7 +198,7 @@ function buildFunction(type, functionName, gen, scope) {
push(line.trim());
indent = prev;
});
push("}})(" + Object.keys(scope).map(function(key) { return scope[key]; }).join(", ") + "); /* eslint-enable */");
push("};})(" + Object.keys(scope).map(function(key) { return scope[key]; }).join(", ") + ");");
}
function buildType(ref, type) {
@ -205,9 +225,10 @@ function buildType(ref, type) {
--indent;
push("}");
if (type.fieldsArray.length || type.oneofsArray.length) {
if (type.fieldsArray.length || type.oneofsArray.length || config.convert) {
push("");
push("/** @alias " + fullName + ".prototype */");
if (config.comments)
push("/** @alias " + fullName + ".prototype */");
push("var $prototype = " + name(type.name) + ".prototype;");
}
@ -253,13 +274,15 @@ function buildType(ref, type) {
}
if (field.repeated)
jsType = "Array.<" + jsType + ">";
push("");
var prop = util.safeProp(field.name);
pushComment([
type.name + " " + field.name + ".",
prop.charAt(0) !== "." ? "@name " + fullName + "#" + field.name : null,
"@type {" + jsType + "}"
]);
if (config.comments) {
push("");
pushComment([
type.name + " " + field.name + ".",
prop.charAt(0) !== "." ? "@name " + fullName + "#" + field.name : null,
"@type {" + jsType + "}"
]);
}
if (Array.isArray(field.defaultValue)) {
push("$prototype" + prop + " = $protobuf.util.emptyArray;");
} else if (util.isObject(field.defaultValue))
@ -304,6 +327,22 @@ function buildType(ref, type) {
push("});");
});
var hasTypes = false;
var types = type.fieldsArray.map(function(field) {
if (field.resolve().resolvedType) { // including enums!
hasTypes = true;
return JSON.stringify(field.resolvedType.fullName.substring(1));
}
return "null";
}).join(", ");
if (hasTypes && (config.encode || config.decode || config.verify || config.convert)) {
push("");
if (config.comments)
push("// Referenced types");
push("var $types = [" + types + "]; $lazyTypes.push($types);");
}
if (config.create) {
push("");
pushComment([
@ -317,27 +356,27 @@ function buildType(ref, type) {
--indent;
push("};");
}
if (config.encode) {
push("");
pushComment([
"Encodes the specified " + type.name + ".",
"Encodes the specified " + type.name + " message.",
"@function",
"@param {" + fullName + "|Object} message " + type.name + " or plain object to encode",
"@param {" + fullName + "|Object} message " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [writer] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
buildFunction(type, "encode", protobuf.encoder(type), {
Writer : "$protobuf.Writer",
util : "$protobuf.util"
util : "$protobuf.util",
types : hasTypes ? "$types" : undefined
});
if (config.delimited) {
push("");
pushComment([
"Encodes the specified " + type.name + ", length delimited.",
"@param {" + fullName + "|Object} message " + type.name + " or plain object to encode",
"Encodes the specified " + type.name + " message, length delimited.",
"@param {" + fullName + "|Object} message " + type.name + " message or plain object to encode",
"@param {$protobuf.Writer} [writer] Writer to encode to",
"@returns {$protobuf.Writer} Writer"
]);
@ -354,7 +393,7 @@ function buildType(ref, type) {
if (config.decode) {
push("");
pushComment([
"Decodes a " + type.name + " from the specified reader or buffer.",
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer.",
"@function",
"@param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from",
"@param {number} [length] Message length if known beforehand",
@ -362,13 +401,14 @@ function buildType(ref, type) {
]);
buildFunction(type, "decode", protobuf.decoder(type), {
Reader : "$protobuf.Reader",
util : "$protobuf.util"
util : "$protobuf.util",
types : hasTypes ? "$types" : undefined
});
if (config.delimited) {
push("");
pushComment([
"Decodes a " + type.name + " from the specified reader or buffer, length delimited.",
"Decodes " + aOrAn(type.name) + " message from the specified reader or buffer, length delimited.",
"@param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from",
"@returns {" + fullName + "} " + type.name
]);
@ -385,16 +425,58 @@ function buildType(ref, type) {
if (config.verify) {
push("");
pushComment([
"Verifies a " + type.name + ".",
"Verifies " + aOrAn(type.name) + " message.",
"@function",
"@param {" + fullName + "|Object} message " + type.name + " or plain object to verify",
"@param {" + fullName + "|Object} message " + type.name + " message or plain object to verify",
"@returns {?string} `null` if valid, otherwise the reason why it is not"
]);
buildFunction(type, "verify", protobuf.verifier(type), {
util : "$protobuf.util"
util : "$protobuf.util",
types : hasTypes ? "$types" : undefined
});
}
if (config.convert) {
push("");
pushComment([
"Converts " + aOrAn(type.name) + " message.",
"@function",
"@param {" + fullName + "|Object} source " + type.name + " message or plain object to convert",
"@param {*} impl Converter implementation to use",
"@param {Object.<string,*>} [options] Conversion options",
"@returns {" + fullName + "|Object} Converted message"
]);
buildFunction(type, "convert", protobuf.converter(type), {
util : "$protobuf.util",
types : hasTypes ? "$types" : undefined
});
push("");
pushComment([
"Creates " + aOrAn(type.name) + " message from JSON.",
"@param {Object.<string,*>} source Source object",
"@param {Object.<string,*>} [options] Conversion options",
"@returns {" + fullName + "} " + type.name
]);
push(name(type.name) + ".from = function from(source, options) {");
++indent;
push("return this.convert(source, $protobuf.converters.message, options);");
--indent;
push("};");
push("");
pushComment([
"Converts this " + type.name + " message to JSON.",
"@param {Object.<string,*>} [options] Conversion options",
"@returns {Object.<string,*>} JSON object"
]);
push("$prototype.asJSON = function asJSON(options) {");
++indent;
push("return this.constructor.convert(this, $protobuf.converters.json, options);");
--indent;
push("};");
}
}
function buildService(ref, service) {
@ -427,7 +509,7 @@ function buildService(ref, service) {
push("");
pushComment([
"Constructs a new " + service.name + ".",
"Constructs a new " + service.name + " service.",
"@exports " + fullName,
"@constructor",
"@param {RPCImpl} rpc RPC implementation",
@ -458,7 +540,7 @@ function buildService(ref, service) {
--indent;
push("};");
service.getMethodsArray().forEach(function(method) {
service.methodsArray.forEach(function(method) {
method.resolve();
var lcName = method.name.substring(0, 1).toLowerCase() + method.name.substring(1);
push("");
@ -473,7 +555,7 @@ function buildService(ref, service) {
push("");
pushComment([
"Calls " + method.name + ".",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " or plain object",
"@param {" + method.resolvedRequestType.fullName.substring(1) + "|Object} request " + method.resolvedRequestType.name + " message or plain object",
"@param {" + cbName + "} callback Node-style callback called with the error, if any, and " + method.resolvedResponseType.name,
"@returns {undefined}"
]);
@ -520,18 +602,26 @@ function buildService(ref, service) {
function buildEnum(ref, enm) {
push("");
pushComment([
enm.name + " values.",
"@exports " + enm.fullName.substring(1),
"@type {Object.<string,number>}"
]);
push(name(ref) + "." + name(enm.name) + " = {");
push("");
var comment = [
enm.name + " enum.",
"@name " + name(enm.name),
"@memberof " + enm.parent.fullName.substring(1),
"@enum {number}"
];
Object.keys(enm.values).forEach(function(key) {
var val = enm.values[key];
comment.push("@property {number} " + key + "=" + val + " " + key + " value");
});
pushComment(comment);
push(name(ref) + "." + name(enm.name) + " = (function() {");
++indent;
var keys = Object.keys(enm.values);
for (var i = 0; i < keys.length; ++i) {
push(name(keys[i]) + ": " + enm.values[keys[i]].toString(10) + (i < keys.length - 1 ? "," : ""));
}
push("var valuesById = {},");
push(" values = Object.create(valuesById);");
Object.keys(enm.values).forEach(function(key) {
var val = enm.values[key];
push("values[valuesById[" + val + "] = " + JSON.stringify(key) + "] = " + val + ";");
});
push("return values;");
--indent;
push("};");
push("})();");
}

View File

@ -83,7 +83,7 @@ exports.require = function(name, version) {
require.resolve(path.join(dir, "package.json"));
} catch (e) {
console.error("installing " + name + "@" + version + " ...");
child_process.execSync("npm install " + name + "@" + version, {
child_process.execSync("npm --silent install " + name + "@" + version, {
cwd: cwd
});
}

View File

@ -1,5 +1,6 @@
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
define(["protobuf"], function($protobuf) {
"use strict"; // eslint-disable-line strict
"use strict";
%OUTPUT%

View File

@ -1,4 +1,5 @@
"use strict"; // eslint-disable-line strict
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
"use strict";
var $protobuf = require("protobufjs/runtime");

View File

@ -1,15 +1,14 @@
(function(global, factory) {
/* eslint-disable no-undef */
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
(function(global, factory) { /* global define, require, module */
/* AMD */ if (typeof define === 'function' && define.amd)
define(["protobuf"], factory);
/* CommonJS */ else if (typeof require === 'function' && typeof module === 'object' && module && module.exports)
module.exports = factory(require("protobufjs/runtime"));
/* eslint-enable no-undef */
})(this, function($protobuf) {
"use strict"; // eslint-disable-line strict
"use strict";
%OUTPUT%

View File

@ -1,3 +1,4 @@
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex */
import * as $protobuf from "protobufjs";
%OUTPUT%

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

910
dist/protobuf.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.3.2 (c) 2016, Daniel Wirtz
* Compiled Fri, 30 Dec 2016 23:13:48 UTC
* protobuf.js v6.4.0 (c) 2016, Daniel Wirtz
* Compiled Mon, 02 Jan 2017 04:21:33 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/
@ -309,11 +309,12 @@ utf8.write = function(string, buffer, offset) {
"use strict";
var protobuf = global.protobuf = exports;
protobuf.Writer = require(10);
protobuf.BufferWriter = require(11);
protobuf.Reader = require(6);
protobuf.BufferReader = require(7);
protobuf.util = require(9);
protobuf.Writer = require(11);
protobuf.BufferWriter = require(12);
protobuf.Reader = require(7);
protobuf.BufferReader = require(8);
protobuf.converters = require(6);
protobuf.util = require(10);
protobuf.roots = {};
protobuf.configure = configure;
@ -333,11 +334,144 @@ if (typeof define === "function" && define.amd)
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"10":10,"11":11,"6":6,"7":7,"9":9}],6:[function(require,module,exports){
},{"10":10,"11":11,"12":12,"6":6,"7":7,"8":8}],6:[function(require,module,exports){
"use strict";
var converters = exports;
var util = require(10);
/**
* JSON conversion options as used by {@link Message#asJSON}.
* @typedef JSONConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
* @property {*} [longs] Long conversion type. Only relevant with a long library.
* Valid values are `String` and `Number` (the global types).
* Defaults to a possibly unsafe number without, and a `Long` with a long library.
* @property {*} [enums=Number] Enum value conversion type.
* Valid values are `String` and `Number` (the global types).
* Defaults to the numeric ids.
* @property {*} [bytes] Bytes value conversion type.
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @property {boolean} [defaults=false] Also sets default values on the resulting object
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
*/
/**
* Converter implementation producing JSON.
* @type {ConverterImpl}
*/
converters.json = {
create: function(value, typeOrCtor, options) {
if (!value)
return null;
return options.fieldsOnly
? {}
: util.merge({}, value);
},
enums: function(value, defaultValue, values, options) {
if (!options.defaults) {
if (value === undefined || value === defaultValue)
return undefined;
} else if (value === undefined)
value = defaultValue;
return options.enums === String && typeof value === "number"
? values[value]
: value;
},
longs: function(value, defaultLow, defaultHigh, unsigned, options) {
if (!value) {
if (options.defaults)
value = { low: defaultLow, high: defaultHigh };
else
return undefined;
} else if (!util.longNe(value, defaultLow, defaultHigh) && !options.defaults)
return undefined;
if (options.longs === Number)
return typeof value === "number"
? value
: util.LongBits.from(value).toNumber(unsigned);
if (options.longs === String) {
if (typeof value === "number")
return util.Long.fromNumber(value, unsigned).toString();
value = util.Long.fromValue(value); // has no unsigned option
value.unsigned = unsigned;
return value.toString();
}
return value;
},
bytes: function(value, defaultValue, options) {
if (!value) {
if (options.defaults)
value = defaultValue;
else
return undefined;
} else if (!value.length && !options.defaults)
return undefined;
return options.bytes === String
? util.base64.encode(value, 0, value.length)
: options.bytes === Array
? Array.prototype.slice.call(value)
: options.bytes === util.Buffer && !util.Buffer.isBuffer(value)
? util.Buffer.from(value) // polyfilled
: value;
}
};
/**
* Message conversion options as used by {@link Message.from} and {@link Type#from}.
* @typedef MessageConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
*/
// Note that options.defaults and options.arrays also affect the message converter.
// As defaults are already on the prototype, usage is not recommended and thus undocumented.
/**
* Converter implementation producing runtime messages.
* @type {ConverterImpl}
*/
converters.message = {
create: function(value, typeOrCtor, options) {
if (!value)
return null;
// can't use instanceof Type here because converters are also part of the minimal runtime
return new (typeOrCtor.getCtor ? typeOrCtor.getCtor() : typeOrCtor)(options.fieldsOnly ? undefined : value);
},
enums: function(value, defaultValue, values) {
if (typeof value === "string")
return values[value];
return value | 0;
},
longs: function(value, defaultLow, defaultHigh, unsigned) {
if (typeof value === "string")
return util.Long.fromString(value, unsigned);
if (typeof value === "number")
return util.Long.fromNumber(value, unsigned);
return value;
},
bytes: function(value/*, defaultValue*/) {
if (util.Buffer)
return util.Buffer.isBuffer(value)
? value
: util.Buffer.from(value, "base64"); // polyfilled
if (typeof value === "string") {
var buf = util.newBuffer(util.base64.length(value));
util.base64.decode(value, buf, 0);
return buf;
}
return value instanceof util.Array
? value
: new util.Array(value);
}
};
},{"10":10}],7:[function(require,module,exports){
"use strict";
module.exports = Reader;
var util = require(9);
var util = require(10);
var BufferReader; // cyclic
@ -385,7 +519,7 @@ function Reader(buffer) {
Reader.create = util.Buffer
? function create_buffer_setup(buffer) {
if (!BufferReader)
BufferReader = require(7);
BufferReader = require(8);
return (Reader.create = function create_buffer(buffer) {
return new BufferReader(buffer);
})(buffer);
@ -823,7 +957,7 @@ ReaderPrototype.skipType = function(wireType) {
/* istanbul ignore next */
default:
throw Error("invalid wire type: " + wireType);
throw Error("invalid wire type " + wireType + " at offset " + this.pos);
}
return this;
};
@ -849,16 +983,16 @@ Reader._configure = configure;
configure();
},{"7":7,"9":9}],7:[function(require,module,exports){
},{"10":10,"8":8}],8:[function(require,module,exports){
"use strict";
module.exports = BufferReader;
var Reader = require(6);
var Reader = require(7);
/** @alias BufferReader.prototype */
var BufferReaderPrototype = BufferReader.prototype = Object.create(Reader.prototype);
BufferReaderPrototype.constructor = BufferReader;
var util = require(9);
var util = require(10);
/**
* Constructs a new buffer reader instance.
@ -882,12 +1016,12 @@ BufferReaderPrototype.string = function read_string_buffer() {
return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
};
},{"6":6,"9":9}],8:[function(require,module,exports){
},{"10":10,"7":7}],9:[function(require,module,exports){
"use strict";
module.exports = LongBits;
var util = require(9);
var util = require(10);
/**
* Any compatible Long instance.
@ -1094,13 +1228,13 @@ LongBitsPrototype.length = function length() {
: part2 < 128 ? 9 : 10;
};
},{"9":9}],9:[function(require,module,exports){
},{"10":10}],10:[function(require,module,exports){
(function (global){
"use strict";
var util = exports;
util.LongBits = require(8);
util.LongBits = require(9);
util.base64 = require(1);
util.inquire = require(2);
util.utf8 = require(4);
@ -1212,23 +1346,6 @@ util.longFromHash = function longFromHash(hash, unsigned) {
return bits.toNumber(Boolean(unsigned));
};
/**
* Tests if two possibly long values are not equal.
* @param {number|Long} a First value
* @param {number|Long} b Second value
* @returns {boolean} `true` if not equal
* @deprecated Use {@link util.longNe|longNe} instead
*/
util.longNeq = function longNeq(a, b) {
return typeof a === "number"
? typeof b === "number"
? a !== b
: (a = util.LongBits.fromNumber(a)).lo !== b.low || a.hi !== b.high
: typeof b === "number"
? (b = util.LongBits.fromNumber(b)).lo !== a.low || b.hi !== a.high
: a.low !== b.low || a.high !== b.high;
};
/**
* Tests if a possibily long value equals the specified low and high bits.
* @param {number|string|Long} val Value to test
@ -1304,11 +1421,11 @@ util.emptyObject = Object.freeze ? Object.freeze({}) : {};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"1":1,"2":2,"3":3,"4":4,"8":8}],10:[function(require,module,exports){
},{"1":1,"2":2,"3":3,"4":4,"9":9}],11:[function(require,module,exports){
"use strict";
module.exports = Writer;
var util = require(9);
var util = require(10);
var BufferWriter; // cyclic
@ -1439,7 +1556,7 @@ function Writer() {
Writer.create = util.Buffer
? function create_buffer_setup() {
if (!BufferWriter)
BufferWriter = require(11);
BufferWriter = require(12);
return (Writer.create = function create_buffer() {
return new BufferWriter();
})();
@ -1851,16 +1968,16 @@ WriterPrototype.finish = function finish() {
return buf;
};
},{"11":11,"9":9}],11:[function(require,module,exports){
},{"10":10,"12":12}],12:[function(require,module,exports){
"use strict";
module.exports = BufferWriter;
var Writer = require(10);
var Writer = require(11);
/** @alias BufferWriter.prototype */
var BufferWriterPrototype = BufferWriter.prototype = Object.create(Writer.prototype);
BufferWriterPrototype.constructor = BufferWriter;
var util = require(9);
var util = require(10);
var utf8 = util.utf8,
Buffer = util.Buffer;
@ -1924,7 +2041,7 @@ BufferWriterPrototype.string = function write_string_buffer(value) {
return this;
};
},{"10":10,"9":9}]},{},[5])
},{"10":10,"11":11}]},{},[5])
//# sourceMappingURL=protobuf.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

141
index.d.ts vendored
View File

@ -1,5 +1,5 @@
// $> pbts --main --global protobuf --out index.d.ts src
// Generated Sat, 31 Dec 2016 00:05:20 UTC
// Generated Mon, 02 Jan 2017 04:20:31 UTC
export as namespace protobuf;
@ -92,31 +92,80 @@ export class Class {
export function common(name: string, json: { [k: string]: any }): void;
/**
* A converter as used by {@link convert}.
* @typedef Converter
* Generates a conveter specific to the specified message type.
* @param {Type} mtype Message type
* @param {function} generateField Field generator
* @returns {Codegen} Codegen instance
* @property {ConverterImpl} json Converter implementation producing JSON
* @property {ConverterImpl} message Converter implementation producing runtime messages
*/
export function converter(mtype: Type, generateField: () => any): Codegen;
/**
* A converter implementation as used by {@link Type#convert} respectively {@link Message.convert}.
* @typedef ConverterImpl
* @type {Object}
* @property {ConverterCreate} create Function for creating a new destination object
* @property {ConverterEnums} enums Function for converting enum values
* @property {ConverterLongs} longs Function for converting long values
* @property {ConverterBytes} bytes Function for converting bytes values
*/
interface ConverterImpl {
create: ConverterCreate;
enums: ConverterEnums;
longs: ConverterLongs;
bytes: ConverterBytes;
}
/**
* A function for creating a new destination object.
* @typedef ConverterCreate
* @type {function}
* @param {Field} field Reflected field
* @param {*} value Value to convert
* @param {Object.<string,*>} options Conversion options
* @returns {*} Converted value
* @param {Message|Object} value Source object or message
* @param {Function} typeOrCtor Reflected type or message constructor
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Destination object or message
*/
type Converter = (field: Field, value: any, options: { [k: string]: any }) => any;
type ConverterCreate = (value: (Message|Object), typeOrCtor: () => any, options?: { [k: string]: any }) => (Message|Object);
/**
* Converts between JSON objects and messages, based on reflection information.
* @param {Type} type Type
* @param {*} source Source object
* @param {*} destination Destination object
* @param {Object.<string,*>} options Conversion options
* @param {Converter} converter Conversion function
* @returns {*} `destination`
* @property {Converter} toJson To JSON converter using {@link JSONConversionOptions}
* @property {Converter} toMessage To message converter using {@link MessageConversionOptions}
* A function for converting enum values.
* @typedef ConverterEnums
* @type {function}
* @param {number|string} value Actual value
* @param {number} defaultValue Default value
* @param {Object.<string,number>} values Possible values
* @param {Object.<string,*>} [options] Conversion options
* @returns {number|string} Converted value
*/
export function convert(type: Type, source: any, destination: any, options: { [k: string]: any }, converter: Converter): any;
type ConverterEnums = (value: (number|string), defaultValue: number, values: { [k: string]: number }, options?: { [k: string]: any }) => (number|string);
/**
* JSON conversion options as used by {@link Message#asJSON} with {@link convert}.
* A function for converting long values.
* @typedef ConverterLongs
* @type {function}
* @param {number|string|Long} value Actual value
* @param {Long} defaultValue Default value
* @param {boolean} unsigned Whether unsigned or not
* @param {Object.<string,*>} [options] Conversion options
* @returns {number|string|Long} Converted value
*/
type ConverterLongs = (value: (number|string|Long), defaultValue: Long, unsigned: boolean, options?: { [k: string]: any }) => (number|string|Long);
/**
* A function for converting bytes values.
* @typedef ConverterBytes
* @type {function}
* @param {string|number[]|Uint8Array} value Actual value
* @param {number[]} defaultValue Default value
* @param {Object.<string,*>} [options] Conversion options
* @returns {string|number[]|Uint8Array} Converted value
*/
type ConverterBytes = (value: (string|number[]|Uint8Array), defaultValue: number[], options?: { [k: string]: any }) => (string|number[]|Uint8Array);
/**
* JSON conversion options as used by {@link Message#asJSON}.
* @typedef JSONConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
@ -130,6 +179,7 @@ export function convert(type: Type, source: any, destination: any, options: { [k
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @property {boolean} [defaults=false] Also sets default values on the resulting object
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
*/
interface JSONConversionOptions {
@ -138,10 +188,11 @@ interface JSONConversionOptions {
enums?: any;
bytes?: any;
defaults?: boolean;
arrays?: boolean;
}
/**
* Message conversion options as used by {@link Message.from} and {@link Type#from} with {@link convert}.
* Message conversion options as used by {@link Message.from} and {@link Type#from}.
* @typedef MessageConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
@ -187,28 +238,18 @@ export class Enum extends ReflectionObject {
*/
constructor(name: string, values?: { [k: string]: number }, options?: { [k: string]: any });
/**
* Enum values by id.
* @type {Object.<number,string>}
*/
valuesById: { [k: number]: string };
/**
* Enum values by name.
* @type {Object.<string,number>}
*/
values: { [k: string]: number };
/**
* Enum values by id.
* @name Enum#valuesById
* @type {Object.<number,string>}
* @readonly
*/
readonly valuesById: { [k: number]: string };
/**
* Gets this enum's values by id. This is an alias of {@link Enum#valuesById|valuesById}'s getter for use within non-ES5 environments.
* @name Enum#getValuesById
* @function
* @returns {Object.<number,string>}
*/
getValuesById(): { [k: number]: string };
/**
* Tests if the specified JSON object describes an enum.
* @param {*} json JSON object to test
@ -624,6 +665,15 @@ export class Message {
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
static verify(message: (Message|Object)): string;
/**
* Converts an object or runtime message of this type.
* @param {Message|Object} source Source object or runtime message
* @param {ConverterImpl} impl Converter implementation to use, i.e. {@link converters.json} or {@link converters.message}
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Converted object or runtime message
*/
static convert(source: (Message|Object), impl: ConverterImpl, options?: { [k: string]: any }): (Message|Object);
}
/**
@ -1672,6 +1722,15 @@ export class Type extends Namespace {
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
verify(message: (Message|Object)): string;
/**
* Converts an object or runtime message.
* @param {Message|Object} source Source object or runtime message
* @param {ConverterImpl} impl Converter implementation to use, i.e. {@link converters.json} or {@link converters.message}
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Converted object or runtime message
*/
convert(source: (Message|Object), impl: ConverterImpl, options?: { [k: string]: any }): (Message|Object);
}
/**
@ -1954,6 +2013,7 @@ export namespace util {
* @returns {Codegen} Codegen instance
* @property {boolean} supported Whether code generation is supported by the environment.
* @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging.
* @property {function(string, ...*):string} sprintf Underlying sprintf implementation
*/
function codegen(...params: string[]): Codegen;
@ -2242,15 +2302,6 @@ export namespace util {
*/
function longFromHash(hash: string, unsigned?: boolean): (Long|number);
/**
* Tests if two possibly long values are not equal.
* @param {number|Long} a First value
* @param {number|Long} b Second value
* @returns {boolean} `true` if not equal
* @deprecated Use {@link util.longNe|longNe} instead
*/
function longNeq(a: (number|Long), b: (number|Long)): boolean;
/**
* Tests if a possibily long value equals the specified low and high bits.
* @param {number|string|Long} val Value to test

View File

@ -81,6 +81,7 @@
"tap-spec": "^4.1.1",
"tape": "^4.6.3",
"typescript": "^2.1.4",
"uglify-js": "^2.7.5",
"vinyl-buffer": "^1.0.0",
"vinyl-fs": "^2.4.4",
"vinyl-source-stream": "^1.1.0",

View File

@ -7,6 +7,7 @@ protobuf.Writer = require("../src/writer");
protobuf.BufferWriter = require("../src/writer_buffer");
protobuf.Reader = require("../src/reader");
protobuf.BufferReader = require("../src/reader_buffer");
protobuf.converters = require("../src/converters");
protobuf.util = require("../src/util/runtime");
protobuf.roots = {};
protobuf.configure = configure;

View File

@ -59,7 +59,7 @@ function create(type, ctor) {
prototype.$type = type;
// Messages have non-enumerable default values on their prototype
type.getFieldsArray().forEach(function(field) {
type.fieldsArray.forEach(function(field) {
// objects on the prototype must be immmutable. users must assign a new object instance and
// cannot use Array#push on empty arrays on the prototype for example, as this would modify
// the value on the prototype for ALL messages of this type. Hence, these objects are frozen.
@ -71,26 +71,25 @@ function create(type, ctor) {
});
// Messages have non-enumerable getters and setters for each virtual oneof field
type.getOneofsArray().forEach(function(oneof) {
util.prop(prototype, oneof.resolve().name, {
get: function getVirtual() {
type.oneofsArray.forEach(function(oneof) {
Object.defineProperty(prototype, oneof.resolve().name, {
get: function() {
// > If the parser encounters multiple members of the same oneof on the wire, only the last member seen is used in the parsed message.
for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
if (oneof.oneof.indexOf(keys[i]) > -1)
return keys[i];
return undefined;
},
set: function setVirtual(value) {
set: function(value) {
for (var keys = oneof.oneof, i = 0; i < keys.length; ++i)
if (keys[i] !== value)
delete this[keys[i]];
}
// see util.prop for IE8 support
});
});
// Register
type.setCtor(ctor);
type.ctor = ctor;
return prototype;
}

View File

@ -1,167 +0,0 @@
"use strict";
module.exports = convert;
var Enum = require("./enum"),
util = require("./util");
var Type, // cyclic
Message;
/**
* A converter as used by {@link convert}.
* @typedef Converter
* @type {function}
* @param {Field} field Reflected field
* @param {*} value Value to convert
* @param {Object.<string,*>} options Conversion options
* @returns {*} Converted value
*/
/**
* Converts between JSON objects and messages, based on reflection information.
* @param {Type} type Type
* @param {*} source Source object
* @param {*} destination Destination object
* @param {Object.<string,*>} options Conversion options
* @param {Converter} converter Conversion function
* @returns {*} `destination`
* @property {Converter} toJson To JSON converter using {@link JSONConversionOptions}
* @property {Converter} toMessage To message converter using {@link MessageConversionOptions}
*/
function convert(type, source, destination, options, converter) {
if (!Type) { // require this here already so it is available within the converters below
Type = require("./type");
Message = require("./message");
}
if (!options)
options = {};
var keys = Object.keys(options.defaults ? type.fields : source);
for (var i = 0, key; i < keys.length; ++i) {
var field = type.fields[key = keys[i]],
value = source[key];
if (field) {
if (field.repeated) {
if (value || options.defaults) {
destination[key] = [];
if (value)
for (var j = 0, l = value.length; j < l; ++j)
destination[key].push(converter(field, value[j], options));
}
} else
destination[key] = converter(field, value, options);
} else if (!options.fieldsOnly)
destination[key] = value;
}
return destination;
}
/**
* JSON conversion options as used by {@link Message#asJSON} with {@link convert}.
* @typedef JSONConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
* @property {*} [longs] Long conversion type. Only relevant with a long library.
* Valid values are `String` and `Number` (the global types).
* Defaults to a possibly unsafe number without, and a `Long` with a long library.
* @property {*} [enums=Number] Enum value conversion type.
* Valid values are `String` and `Number` (the global types).
* Defaults to the numeric ids.
* @property {*} [bytes] Bytes value conversion type.
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @property {boolean} [defaults=false] Also sets default values on the resulting object
*/
/**/
convert.toJson = function toJson(field, value, options) {
if (!options)
options = {};
// Recurse into inner messages
if (value instanceof Message)
return convert(value.$type, value, {}, options, toJson);
// Enums as strings
if (options.enums && field.resolvedType instanceof Enum)
return options.enums === String
? field.resolvedType.getValuesById()[value]
: value | 0;
// Longs as numbers or strings
if (options.longs && field.long) {
var unsigned = field.type.charAt(0) === "u";
if (options.longs === Number)
return typeof value === "number"
? value
: util.LongBits.from(value).toNumber(unsigned);
if (options.longs === String) {
if(typeof value === "number")
return util.Long.fromNumber(value, unsigned).toString();
value = util.Long.fromValue(value); // has no unsigned option
value.unsigned = unsigned;
return value.toString();
}
}
// Bytes as base64 strings, plain arrays or buffers
if (options.bytes && field.bytes) {
if (options.bytes === String)
return util.base64.encode(value, 0, value.length);
if (options.bytes === Array)
return Array.prototype.slice.call(value);
if (options.bytes === util.Buffer && !util.Buffer.isBuffer(value))
return util.Buffer.from(value); // polyfilled
}
return value;
};
/**
* Message conversion options as used by {@link Message.from} and {@link Type#from} with {@link convert}.
* @typedef MessageConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
*/
/**/
convert.toMessage = function toMessage(field, value, options) {
switch (typeof value) {
// Recurse into inner messages
case "object":
if (value) {
if (field.resolvedType instanceof Type)
return convert(field.resolvedType, value, new (field.resolvedType.getCtor())(), options, toMessage);
if (field.type === "bytes")
return util.Buffer
? util.Buffer.isBuffer(value)
? value
: util.Buffer.from(value) // polyfilled
: value instanceof util.Array
? value
: new util.Array(value);
}
break;
// Strings to proper numbers, longs or buffers
case "string":
if (field.resolvedType instanceof Enum)
return field.resolvedType.values[value] || 0;
if (field.long)
return util.Long.fromString(value, field.type.charAt(0) === "u");
if (field.bytes) {
var buf = util.newBuffer(util.base64.length(value));
util.base64.decode(value, buf, 0);
return buf;
}
break;
// Numbers to proper longs
case "number":
if (field.long)
return util.Long.fromNumber(value, field.type.charAt(0) === "u");
break;
}
return value;
};

125
src/converter.js Normal file
View File

@ -0,0 +1,125 @@
"use strict";
module.exports = converter;
var Enum = require("./enum"),
converters = require("./converters"),
util = require("./util");
var sprintf = util.codegen.sprintf;
function genConvert(field, fieldIndex, prop) {
if (field.resolvedType)
return field.resolvedType instanceof Enum
? sprintf("f.enums(s%s,%d,types[%d].values,o)", prop, 0, fieldIndex)
: sprintf("types[%d].convert(s%s,f,o)", fieldIndex, prop);
switch (field.type) {
case "int64":
case "uint64":
case "sint64":
case "fixed64":
case "sfixed64":
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, 0, 0, field.type.charAt(0) === "u");
case "bytes":
return sprintf("f.bytes(s%s,%j,o)", prop, field.defaultValue);
}
return null;
}
/**
* Generates a conveter specific to the specified message type.
* @param {Type} mtype Message type
* @param {function} generateField Field generator
* @returns {Codegen} Codegen instance
* @property {ConverterImpl} json Converter implementation producing JSON
* @property {ConverterImpl} message Converter implementation producing runtime messages
*/
function converter(mtype) {
/* eslint-disable no-unexpected-multiline */
var fields = mtype.fieldsArray;
var gen = util.codegen("s", "f", "o")
("if(!o)")
("o={}")
("var d=f.create(s,this,o)");
if (fields.length) { gen
("if(d){");
var convert;
fields.forEach(function(field, i) {
var prop = util.safeProp(field.resolve().name);
if (field.repeated) { gen
("if(s%s&&s%s.length){", prop, prop)
("d%s=[]", prop)
("for(var i=0;i<s%s.length;++i)", prop);
if (convert = genConvert(field, i, prop + "[i]")) gen
("d%s.push(%s)", prop, convert);
else gen
("d%s.push(s%s[i])", prop, prop);
gen
("}else if(o.defaults||o.arrays)")
("d%s=[]", prop);
} else if (convert = genConvert(field, i, prop)) gen
("d%s=%s", prop, convert);
else gen
("if(d%s===undefined&&o.defaults)", prop)
("d%s=%j", prop, field.defaultValue);
});
gen
("}");
}
return gen
("return d");
/* eslint-enable no-unexpected-multiline */
}
util.merge(converter, converters);
/**
* A converter implementation as used by {@link Type#convert} respectively {@link Message.convert}.
* @typedef ConverterImpl
* @type {Object}
* @property {ConverterCreate} create Function for creating a new destination object
* @property {ConverterEnums} enums Function for converting enum values
* @property {ConverterLongs} longs Function for converting long values
* @property {ConverterBytes} bytes Function for converting bytes values
*/
/**
* A function for creating a new destination object.
* @typedef ConverterCreate
* @type {function}
* @param {Message|Object} value Source object or message
* @param {Function} typeOrCtor Reflected type or message constructor
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Destination object or message
*/
/**
* A function for converting enum values.
* @typedef ConverterEnums
* @type {function}
* @param {number|string} value Actual value
* @param {number} defaultValue Default value
* @param {Object.<string,number>} values Possible values
* @param {Object.<string,*>} [options] Conversion options
* @returns {number|string} Converted value
*/
/**
* A function for converting long values.
* @typedef ConverterLongs
* @type {function}
* @param {number|string|Long} value Actual value
* @param {Long} defaultValue Default value
* @param {boolean} unsigned Whether unsigned or not
* @param {Object.<string,*>} [options] Conversion options
* @returns {number|string|Long} Converted value
*/
/**
* A function for converting bytes values.
* @typedef ConverterBytes
* @type {function}
* @param {string|number[]|Uint8Array} value Actual value
* @param {number[]} defaultValue Default value
* @param {Object.<string,*>} [options] Conversion options
* @returns {string|number[]|Uint8Array} Converted value
*/

131
src/converters.js Normal file
View File

@ -0,0 +1,131 @@
"use strict";
var converters = exports;
var util = require("./util/runtime");
/**
* JSON conversion options as used by {@link Message#asJSON}.
* @typedef JSONConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
* @property {*} [longs] Long conversion type. Only relevant with a long library.
* Valid values are `String` and `Number` (the global types).
* Defaults to a possibly unsafe number without, and a `Long` with a long library.
* @property {*} [enums=Number] Enum value conversion type.
* Valid values are `String` and `Number` (the global types).
* Defaults to the numeric ids.
* @property {*} [bytes] Bytes value conversion type.
* Valid values are `Array` and `String` (the global types).
* Defaults to return the underlying buffer type.
* @property {boolean} [defaults=false] Also sets default values on the resulting object
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
*/
/**
* Converter implementation producing JSON.
* @type {ConverterImpl}
*/
converters.json = {
create: function(value, typeOrCtor, options) {
if (!value)
return null;
return options.fieldsOnly
? {}
: util.merge({}, value);
},
enums: function(value, defaultValue, values, options) {
if (!options.defaults) {
if (value === undefined || value === defaultValue)
return undefined;
} else if (value === undefined)
value = defaultValue;
return options.enums === String && typeof value === "number"
? values[value]
: value;
},
longs: function(value, defaultLow, defaultHigh, unsigned, options) {
if (!value) {
if (options.defaults)
value = { low: defaultLow, high: defaultHigh };
else
return undefined;
} else if (!util.longNe(value, defaultLow, defaultHigh) && !options.defaults)
return undefined;
if (options.longs === Number)
return typeof value === "number"
? value
: util.LongBits.from(value).toNumber(unsigned);
if (options.longs === String) {
if (typeof value === "number")
return util.Long.fromNumber(value, unsigned).toString();
value = util.Long.fromValue(value); // has no unsigned option
value.unsigned = unsigned;
return value.toString();
}
return value;
},
bytes: function(value, defaultValue, options) {
if (!value) {
if (options.defaults)
value = defaultValue;
else
return undefined;
} else if (!value.length && !options.defaults)
return undefined;
return options.bytes === String
? util.base64.encode(value, 0, value.length)
: options.bytes === Array
? Array.prototype.slice.call(value)
: options.bytes === util.Buffer && !util.Buffer.isBuffer(value)
? util.Buffer.from(value) // polyfilled
: value;
}
};
/**
* Message conversion options as used by {@link Message.from} and {@link Type#from}.
* @typedef MessageConversionOptions
* @type {Object}
* @property {boolean} [fieldsOnly=false] Keeps only properties that reference a field
*/
// Note that options.defaults and options.arrays also affect the message converter.
// As defaults are already on the prototype, usage is not recommended and thus undocumented.
/**
* Converter implementation producing runtime messages.
* @type {ConverterImpl}
*/
converters.message = {
create: function(value, typeOrCtor, options) {
if (!value)
return null;
// can't use instanceof Type here because converters are also part of the minimal runtime
return new (typeOrCtor.ctor ? typeOrCtor.ctor : typeOrCtor)(options.fieldsOnly ? undefined : value);
},
enums: function(value, defaultValue, values) {
if (typeof value === "string")
return values[value];
return value | 0;
},
longs: function(value, defaultLow, defaultHigh, unsigned) {
if (typeof value === "string")
return util.Long.fromString(value, unsigned);
if (typeof value === "number")
return util.Long.fromNumber(value, unsigned);
return value;
},
bytes: function(value/*, defaultValue*/) {
if (util.Buffer)
return util.Buffer.isBuffer(value)
? value
: util.Buffer.from(value, "base64"); // polyfilled
if (typeof value === "string") {
var buf = util.newBuffer(util.base64.length(value));
util.base64.decode(value, buf, 0);
return buf;
}
return value instanceof util.Array
? value
: new util.Array(value);
}
};

View File

@ -12,11 +12,11 @@ var Enum = require("./enum"),
*/
function decoder(mtype) {
/* eslint-disable no-unexpected-multiline */
var fields = mtype.getFieldsArray();
var fields = mtype.fieldsArray;
var gen = util.codegen("r", "l")
("r instanceof Reader||(r=Reader.create(r))")
("var c=l===undefined?r.len:r.pos+l,m=new(this.getCtor())")
("if(!(r instanceof Reader))")
("r=Reader.create(r)")
("var c=l===undefined?r.len:r.pos+l,m=new(this.ctor)")
("while(r.pos<c){")
("var t=r.uint32()");
if (mtype.group) gen
@ -52,13 +52,14 @@ function decoder(mtype) {
// Repeated fields
} else if (field.repeated) { gen
("%s&&%s.length||(%s=[])", ref, ref, ref);
("if(!(%s&&%s.length))", ref, ref)
("%s=[]", ref);
// Packed
if (field.packed && types.packed[type] !== undefined) gen
("if((t&7)===2){")
("var e=r.uint32()+r.pos")
("while(r.pos<e)")
("var c2=r.uint32()+r.pos")
("while(r.pos<c2)")
("%s.push(r.%s())", ref, type)
("}else");

View File

@ -18,10 +18,11 @@ function genEncodeType(gen, field, fieldIndex, ref) {
*/
function encoder(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.getFieldsArray();
var oneofs = mtype.getOneofsArray();
var fields = mtype.fieldsArray;
var oneofs = mtype.oneofsArray;
var gen = util.codegen("m", "w")
("w||(w=Writer.create())");
("if(!w)")
("w=Writer.create()");
var i, ref;
for (var i = 0; i < fields.length; ++i) {
@ -38,11 +39,10 @@ function encoder(mtype) {
("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
("w.uint32(%d).fork().uint32(%d).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[keyType], keyType);
if (wireType === undefined) gen
("types[%d].encode(%s[ks[i]],w.uint32(18).fork()).ldelim()", i, ref); // can't be groups
("types[%d].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", i, ref); // can't be groups
else gen
("w.uint32(%d).%s(%s[ks[i]])", 16 | wireType, type, ref);
(".uint32(%d).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
gen
("w.ldelim()")
("}")
("}");
@ -62,12 +62,14 @@ function encoder(mtype) {
// Non-packed
} else { gen
("if(%s)", ref)
("if(%s){", ref)
("for(var i=0;i<%s.length;++i)", ref);
if (wireType === undefined)
genEncodeType(gen, field, i, ref + "[i]");
else gen
("w.uint32(%d).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
gen
("}");
}
@ -93,8 +95,8 @@ function encoder(mtype) {
for (var i = 0; i < oneofs.length; ++i) {
var oneof = oneofs[i];
gen
("switch(%s){", "m.get" + oneof.ucName + "()");
var oneofFields = oneof.getFieldsArray();
("switch(%s){", "m" + util.safeProp(oneof.name));
var oneofFields = oneof.fieldsArray;
for (var j = 0; j < oneofFields.length; ++j) {
var field = oneofFields[j],
type = field.resolvedType instanceof Enum ? "uint32" : field.type,

View File

@ -23,54 +23,33 @@ var TypeError = util._TypeError;
function Enum(name, values, options) {
ReflectionObject.call(this, name, options);
/**
* Enum values by id.
* @type {Object.<number,string>}
*/
this.valuesById = {};
/**
* Enum values by name.
* @type {Object.<string,number>}
*/
this.values = values || {}; // toJSON, marker
this.values = Object.create(this.valuesById); // toJSON, marker
/**
* Cached values by id.
* @type {?Object.<number,string>}
* @private
*/
this._valuesById = null;
}
// Note that values inherit valuesById on their prototype which makes them a TypeScript-
// compatible enum. This is used by pbts to write actual enum definitions that work for
// static and reflection code alike instead of emitting generic object definitions.
util.props(EnumPrototype, {
/**
* Enum values by id.
* @name Enum#valuesById
* @type {Object.<number,string>}
* @readonly
*/
valuesById: {
get: function getValuesById() {
if (!this._valuesById) {
this._valuesById = {};
Object.keys(this.values).forEach(function(name) {
var id = this.values[name];
if (this._valuesById[id])
throw Error("duplicate id " + id + " in " + this);
this._valuesById[id] = name;
}, this);
}
return this._valuesById;
var self = this;
Object.keys(values || {}).forEach(function(key) {
var val;
if (typeof values[key] === "number")
val = values[key];
else {
val = parseInt(key, 10);
key = values[key];
}
}
/**
* Gets this enum's values by id. This is an alias of {@link Enum#valuesById|valuesById}'s getter for use within non-ES5 environments.
* @name Enum#getValuesById
* @function
* @returns {Object.<number,string>}
*/
});
function clearCache(enm) {
enm._valuesById = null;
return enm;
self.valuesById[self.values[key] = val] = key;
});
}
/**
@ -123,11 +102,11 @@ EnumPrototype.add = function(name, id) {
if (this.values[name] !== undefined)
throw Error("duplicate name '" + name + "' in " + this);
/* istanbul ignore next */
if (this.getValuesById()[id] !== undefined)
if (this.valuesById[id] !== undefined)
throw Error("duplicate id " + id + " in " + this);
this.values[name] = id;
return clearCache(this);
this.valuesById[this.values[name] = id] = name;
return this;
};
/**
@ -140,8 +119,10 @@ EnumPrototype.add = function(name, id) {
EnumPrototype.remove = function(name) {
if (!util.isString(name))
throw TypeError("name");
if (this.values[name] === undefined)
var val = this.values[name];
if (val === undefined)
throw Error("'" + name + "' is not a name of " + this);
delete this.valuesById[val];
delete this.values[name];
return clearCache(this);
return this;
};

View File

@ -155,7 +155,7 @@ function Field(name, id, type, rule, extend, options) {
this._packed = null;
}
util.props(FieldPrototype, {
Object.defineProperties(FieldPrototype, {
/**
* Determines whether this field is packed. Only relevant when repeated and working with proto2.
@ -164,20 +164,13 @@ util.props(FieldPrototype, {
* @readonly
*/
packed: {
get: FieldPrototype.isPacked = function() {
get: function() {
// defaults to packed=true if not explicity set to false
if (this._packed === null)
this._packed = this.getOption("packed") !== false;
return this._packed;
}
}
/**
* Determines whether this field is packed. This is an alias of {@link Field#packed|packed}'s getter for use within non-ES5 environments.
* @name Field#isPacked
* @function
* @returns {boolean}
*/
});
/**
@ -257,9 +250,11 @@ FieldPrototype.resolve = function resolve() {
else if (this.repeated)
this.defaultValue = [];
else {
if (this.options && this.options["default"] !== undefined)
if (this.options && this.options["default"] !== undefined) {
this.defaultValue = this.options["default"];
else
if (this.resolvedType instanceof Enum && typeof this.defaultValue === "string")
this.defaultValue = this.resolvedType.values[this.defaultValue] || 0;
} else
this.defaultValue = typeDefault;
if (this.long) {

View File

@ -90,6 +90,7 @@ protobuf.BufferReader = require("./reader_buffer");
protobuf.encoder = require("./encoder");
protobuf.decoder = require("./decoder");
protobuf.verifier = require("./verifier");
protobuf.converter = require("./converter");
// Reflection
protobuf.ReflectionObject = require("./object");

View File

@ -1,7 +1,7 @@
"use strict";
module.exports = Message;
var convert = require("./convert");
var converters = require("./converters");
/**
* Constructs a new message instance.
@ -43,7 +43,7 @@ var MessagePrototype = Message.prototype;
* @returns {Object.<string,*>} JSON object
*/
MessagePrototype.asJSON = function asJSON(options) {
return convert(this.$type, this, {}, options, convert.toJson);
return this.$type.convert(this, converters.json, options);
};
/**
@ -53,7 +53,7 @@ MessagePrototype.asJSON = function asJSON(options) {
* @returns {Message} Message instance
*/
Message.from = function from(object, options) {
return convert(this.$type, object, new this.constructor(), options, convert.toMessage);
return this.$type.convert(object, converters.message, options);
};
/**
@ -108,3 +108,14 @@ Message.decodeDelimited = function decodeDelimited(readerOrBuffer) {
Message.verify = function verify(message) {
return this.$type.verify(message);
};
/**
* Converts an object or runtime message of this type.
* @param {Message|Object} source Source object or runtime message
* @param {ConverterImpl} impl Converter implementation to use, i.e. {@link converters.json} or {@link converters.message}
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Converted object or runtime message
*/
Message.convert = function convert(source, impl, options) {
return this.$type.convert(source, impl, options);
};

View File

@ -72,7 +72,7 @@ function clearCache(namespace) {
return namespace;
}
util.props(NamespacePrototype, {
Object.defineProperties(NamespacePrototype, {
/**
* Nested objects of this namespace as an array for iteration.
@ -81,7 +81,7 @@ util.props(NamespacePrototype, {
* @readonly
*/
nestedArray: {
get: function getNestedArray() {
get: function() {
return this._nestedArray || (this._nestedArray = util.toArray(this.nested));
}
}
@ -121,7 +121,7 @@ Namespace.fromJSON = function fromJSON(name, json) {
NamespacePrototype.toJSON = function toJSON() {
return {
options : this.options,
nested : arrayToJSON(this.getNestedArray())
nested : arrayToJSON(this.nestedArray)
};
};
@ -213,7 +213,7 @@ NamespacePrototype.add = function add(object) {
// initNested above already initializes Type and Service
if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {
// replace plain namespace but keep existing nested elements and options
var nested = prev.getNestedArray();
var nested = prev.nestedArray;
for (var i = 0; i < nested.length; ++i)
object.add(nested[i]);
this.remove(prev);
@ -297,7 +297,7 @@ NamespacePrototype.resolve = function resolve() {
// Add uppercased (and thus conflict-free) nested types, services and enums as properties
// of the type just like static code does. This allows using a .d.ts generated for a static
// module with reflection-based solutions where the condition is met.
var nested = this.getNestedArray();
var nested = this.nestedArray;
for (var i = 0; i < nested.length; ++i)
if (/^[A-Z]/.test(nested[i].name)) {
if (nested[i] instanceof Type || nested[i] instanceof Service)
@ -317,7 +317,7 @@ NamespacePrototype.resolve = function resolve() {
* @returns {Namespace} `this`
*/
NamespacePrototype.resolveAll = function resolveAll() {
var nested = this.getNestedArray(), i = 0;
var nested = this.nestedArray, i = 0;
while (i < nested.length)
if (nested[i] instanceof Namespace)
nested[i++].resolveAll();
@ -344,7 +344,7 @@ NamespacePrototype.lookup = function lookup(path, filterType, parentAlreadyCheck
return null;
// Start at root if path is absolute
if (path[0] === "")
return this.getRoot().lookup(path.slice(1), filterType);
return this.root.lookup(path.slice(1), filterType);
// Test if the first part matches any nested object, and if so, traverse if path contains more
var found = this.get(path[0]);
if (found && path.length === 1 && (!filterType || found instanceof filterType) || found instanceof Namespace && (found = found.lookup(path.slice(1), filterType, true)))

View File

@ -55,7 +55,7 @@ function ReflectionObject(name, options) {
/** @alias ReflectionObject.prototype */
var ReflectionObjectPrototype = ReflectionObject.prototype;
util.props(ReflectionObjectPrototype, {
Object.defineProperties(ReflectionObjectPrototype, {
/**
* Reference to the root namespace.
@ -64,7 +64,7 @@ util.props(ReflectionObjectPrototype, {
* @readonly
*/
root: {
get: function getRoot() {
get: function() {
var ptr = this;
while (ptr.parent !== null)
ptr = ptr.parent;
@ -79,7 +79,7 @@ util.props(ReflectionObjectPrototype, {
* @readonly
*/
fullName: {
get: ReflectionObjectPrototype.getFullName = function getFullName() {
get: function() {
var path = [ this.name ],
ptr = this.parent;
while (ptr) {
@ -110,7 +110,7 @@ ReflectionObjectPrototype.onAdd = function onAdd(parent) {
this.parent.remove(this);
this.parent = parent;
this.resolved = false;
var root = parent.getRoot();
var root = parent.root;
if (!Root)
Root = require("./root");
if (root instanceof Root)
@ -123,7 +123,7 @@ ReflectionObjectPrototype.onAdd = function onAdd(parent) {
* @returns {undefined}
*/
ReflectionObjectPrototype.onRemove = function onRemove(parent) {
var root = parent.getRoot();
var root = parent.root;
if (!Root)
Root = require("./root");
if (root instanceof Root)
@ -139,10 +139,9 @@ ReflectionObjectPrototype.onRemove = function onRemove(parent) {
ReflectionObjectPrototype.resolve = function resolve() {
if (this.resolved)
return this;
var root = this.getRoot();
if (!Root)
Root = require("./root");
if (root instanceof Root)
if (this.root instanceof Root)
this.resolved = true; // only if part of a root
return this;
};
@ -190,8 +189,8 @@ ReflectionObjectPrototype.setOptions = function setOptions(options, ifNotSet) {
* @returns {string} Class name[, space, full name]
*/
ReflectionObjectPrototype.toString = function toString() {
var className = this.constructor.className;
var fullName = this.getFullName();
var className = this.constructor.className,
fullName = this.fullName;
if (fullName.length)
return className + " " + fullName;
return className;

View File

@ -58,8 +58,8 @@ function OneOf(name, fieldNames, options) {
* @type {Field[]}
* @readonly
*/
util.prop(OneOfPrototype, "fieldsArray", {
get: function getFieldsArray() {
Object.defineProperty(OneOfPrototype, "fieldsArray", {
get: function() {
return this._fieldsArray;
}
});

View File

@ -406,8 +406,7 @@ function parse(source, root, options) {
if (!isName(name))
throw illegal(name, "name");
var values = {};
var enm = new Enum(name, values);
var enm = new Enum(name);
if (skip("{", true)) {
while ((token = next()) !== "}") {
if (lower(token) === "option") {
@ -431,7 +430,7 @@ function parse(source, root, options) {
var name = token;
skip("=");
var value = parseId(next(), true);
parent.values[name] = value;
parent.add(name, value);
parseInlineOptions({}); // skips enum value options
}

View File

@ -238,7 +238,7 @@ RootPrototype.loadSync = function loadSync(filename, options) {
RootPrototype.resolveAll = function resolveAll() {
if (this.deferred.length)
throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
return "'extend " + field.extend + "' in " + field.parent.getFullName();
return "'extend " + field.extend + "' in " + field.parent.fullName;
}).join(", "));
return Namespace.prototype.resolveAll.call(this);
};
@ -253,7 +253,7 @@ RootPrototype.resolveAll = function resolveAll() {
function handleExtension(field) {
var extendedType = field.parent.lookup(field.extend);
if (extendedType) {
var sisterField = new Field(field.getFullName(), field.id, field.type, field.rule, undefined, field.options);
var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
sisterField.declaringField = field;
field.extensionField = sisterField;
extendedType.add(sisterField);
@ -283,7 +283,7 @@ RootPrototype._handleAdd = function handleAdd(object) {
if (object instanceof Field && object.extend !== undefined && !object.extensionField && !handleExtension(object) && this.deferred.indexOf(object) < 0)
this.deferred.push(object);
else if (object instanceof Namespace) {
var nested = object.getNestedArray();
var nested = object.nestedArray;
for (i = 0; i < nested.length; ++i) // recurse into the namespace
this._handleAdd(nested[i]);
}
@ -309,7 +309,7 @@ RootPrototype._handleRemove = function handleRemove(object) {
object.extensionField = null;
}
} else if (object instanceof Namespace) {
var nested = object.getNestedArray();
var nested = object.nestedArray;
for (var i = 0; i < nested.length; ++i) // recurse into the namespace
this._handleRemove(nested[i]);
}

View File

@ -39,7 +39,7 @@ function Service(name, options) {
this._methodsArray = null;
}
util.props(ServicePrototype, {
Object.defineProperties(ServicePrototype, {
/**
* Methods of this service as an array for iteration.
@ -48,7 +48,7 @@ util.props(ServicePrototype, {
* @readonly
*/
methodsArray: {
get: function getMethodsArray() {
get: function() {
return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
}
}
@ -92,7 +92,7 @@ ServicePrototype.toJSON = function toJSON() {
var inherited = NamespacePrototype.toJSON.call(this);
return {
options : inherited && inherited.options || undefined,
methods : Namespace.arrayToJSON(this.getMethodsArray()) || {},
methods : Namespace.arrayToJSON(this.methodsArray) || {},
nested : inherited && inherited.nested || undefined
};
};
@ -108,7 +108,7 @@ ServicePrototype.get = function get(name) {
* @override
*/
ServicePrototype.resolveAll = function resolveAll() {
var methods = this.getMethodsArray();
var methods = this.methodsArray;
for (var i = 0; i < methods.length; ++i)
methods[i].resolve();
return NamespacePrototype.resolve.call(this);
@ -174,7 +174,7 @@ ServicePrototype.remove = function remove(object) {
*/
ServicePrototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
var rpcService = new rpc.Service(rpcImpl);
this.getMethodsArray().forEach(function(method) {
this.methodsArray.forEach(function(method) {
rpcService[util.lcFirst(method.name)] = function callVirtual(request, /* optional */ callback) {
if (!rpcService.$rpc) // already ended?
return;

View File

@ -17,12 +17,11 @@ var Enum = require("./enum"),
Message = require("./message"),
Reader = require("./reader"),
Writer = require("./writer"),
convert = require("./convert"),
util = require("./util");
var encoder, // might become cyclic
decoder, // might become cyclic
verifier; // cyclic
util = require("./util"),
encoder = require("./encoder"),
decoder = require("./decoder"),
verifier = require("./verifier"),
converter = require("./converter");
/**
* Constructs a new reflected message type instance.
@ -101,7 +100,7 @@ function Type(name, options) {
this._ctor = null;
}
util.props(TypePrototype, {
Object.defineProperties(TypePrototype, {
/**
* Message fields by id.
@ -110,7 +109,7 @@ util.props(TypePrototype, {
* @readonly
*/
fieldsById: {
get: function getFieldsById() {
get: function() {
if (this._fieldsById)
return this._fieldsById;
this._fieldsById = {};
@ -136,7 +135,7 @@ util.props(TypePrototype, {
* @readonly
*/
fieldsArray: {
get: function getFieldsArray() {
get: function() {
return this._fieldsArray || (this._fieldsArray = util.toArray(this.fields));
}
},
@ -148,8 +147,8 @@ util.props(TypePrototype, {
* @readonly
*/
repeatedFieldsArray: {
get: function getRepeatedFieldsArray() {
return this._repeatedFieldsArray || (this._repeatedFieldsArray = this.getFieldsArray().filter(function(field) { return field.repeated; }));
get: function() {
return this._repeatedFieldsArray || (this._repeatedFieldsArray = this.fieldsArray.filter(function(field) { return field.repeated; }));
}
},
@ -160,7 +159,7 @@ util.props(TypePrototype, {
* @readonly
*/
oneofsArray: {
get: function getOneofsArray() {
get: function() {
return this._oneofsArray || (this._oneofsArray = util.toArray(this.oneofs));
}
},
@ -171,10 +170,10 @@ util.props(TypePrototype, {
* @type {Class}
*/
ctor: {
get: function getCtor() {
get: function() {
return this._ctor || (this._ctor = Class.create(this).constructor);
},
set: function setCtor(ctor) {
set: function(ctor) {
if (ctor && !(ctor.prototype instanceof Message))
throw util._TypeError("ctor", "a Message constructor");
if (!ctor.from)
@ -248,8 +247,8 @@ TypePrototype.toJSON = function toJSON() {
var inherited = NamespacePrototype.toJSON.call(this);
return {
options : inherited && inherited.options || undefined,
oneofs : Namespace.arrayToJSON(this.getOneofsArray()),
fields : Namespace.arrayToJSON(this.getFieldsArray().filter(function(obj) { return !obj.declaringField; })) || {},
oneofs : Namespace.arrayToJSON(this.oneofsArray),
fields : Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; })) || {},
extensions : this.extensions && this.extensions.length ? this.extensions : undefined,
reserved : this.reserved && this.reserved.length ? this.reserved : undefined,
group : this.group || undefined,
@ -261,10 +260,10 @@ TypePrototype.toJSON = function toJSON() {
* @override
*/
TypePrototype.resolveAll = function resolveAll() {
var fields = this.getFieldsArray(), i = 0;
var fields = this.fieldsArray, i = 0;
while (i < fields.length)
fields[i++].resolve();
var oneofs = this.getOneofsArray(); i = 0;
var oneofs = this.oneofsArray; i = 0;
while (i < oneofs.length)
oneofs[i++].resolve();
return NamespacePrototype.resolve.call(this);
@ -291,7 +290,7 @@ TypePrototype.add = function add(object) {
// NOTE: Extension fields aren't actual fields on the declaring type, but nested objects.
// The root object takes care of adding distinct sister-fields to the respective extended
// type instead.
if (this.getFieldsById()[object.id])
if (this.fieldsById[object.id])
throw Error("duplicate id " + object.id + " in " + this);
if (object.parent)
object.parent.remove(object);
@ -335,7 +334,7 @@ TypePrototype.remove = function remove(object) {
* @returns {Message} Runtime message
*/
TypePrototype.create = function create(properties) {
return new (this.getCtor())(properties);
return new this.ctor(properties);
};
/**
@ -345,7 +344,7 @@ TypePrototype.create = function create(properties) {
* @returns {Message} Runtime message
*/
TypePrototype.from = function from(object, options) {
return convert(this, object, new (this.getCtor())(), options, convert.toMessage);
return this.convert(object, converter.message, options);
};
/**
@ -355,23 +354,24 @@ TypePrototype.from = function from(object, options) {
TypePrototype.setup = function setup() {
// Sets up everything at once so that the prototype chain does not have to be re-evaluated
// multiple times (V8, soft-deopt prototype-check).
if (!encoder) {
encoder = require("./encoder");
decoder = require("./decoder");
verifier = require("./verifier");
}
this.encode = encoder(this).eof(this.getFullName() + "$encode", {
var fullName = this.fullName,
types = this.fieldsArray.map(function(fld) { return fld.resolve().resolvedType; });
this.encode = encoder(this).eof(fullName + "$encode", {
Writer : Writer,
types : this.getFieldsArray().map(function(fld) { return fld.resolvedType; }),
types : types,
util : util
});
this.decode = decoder(this).eof(this.getFullName() + "$decode", {
this.decode = decoder(this).eof(fullName + "$decode", {
Reader : Reader,
types : this.getFieldsArray().map(function(fld) { return fld.resolvedType; }),
types : types,
util : util
});
this.verify = verifier(this).eof(this.getFullName() + "$verify", {
types : this.getFieldsArray().map(function(fld) { return fld.resolvedType; }),
this.verify = verifier(this).eof(fullName + "$verify", {
types : types,
util : util
});
this.convert = converter(this).eof(fullName + "$convert", {
types : types,
util : util
});
return this;
@ -425,3 +425,14 @@ TypePrototype.decodeDelimited = function decodeDelimited(readerOrBuffer) {
TypePrototype.verify = function verify_setup(message) {
return this.setup().verify(message); // overrides this method
};
/**
* Converts an object or runtime message.
* @param {Message|Object} source Source object or runtime message
* @param {ConverterImpl} impl Converter implementation to use, i.e. {@link converters.json} or {@link converters.message}
* @param {Object.<string,*>} [options] Conversion options
* @returns {Message|Object} Converted object or runtime message
*/
TypePrototype.convert = function convert_setup(source, impl, options) {
return this.setup().convert(source, impl, options); // overrides this method
};

View File

@ -7,7 +7,7 @@
var util = module.exports = require("./util/runtime");
util.asPromise = require("@protobufjs/aspromise");
util.codegen = require("@protobufjs/codegen");
util.codegen = require("./util/codegen");
util.EventEmitter = require("@protobufjs/eventemitter");
util.extend = require("@protobufjs/extend");
util.fetch = require("@protobufjs/fetch");

View File

@ -21,5 +21,6 @@ type Codegen = (format: string, ...args: any[]) => Codegen;
* @returns {Codegen} Codegen instance
* @property {boolean} supported Whether code generation is supported by the environment.
* @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging.
* @property {function(string, ...*):string} sprintf Underlying sprintf implementation
*/
declare function codegen(...params: string[]): Codegen;

View File

@ -4,7 +4,7 @@ module.exports = codegen;
var blockOpenRe = /[{[]$/,
blockCloseRe = /^[}\]]/,
casingRe = /:$/,
branchRe = /^\s*(?:if|else if|while|for)\b|\b(?:else)\s*$/,
branchRe = /^\s*(?:if|}?else if|while|for)\b|\b(?:else)\s*$/,
breakRe = /\b(?:break|continue);?$|^\s*return\b/;
/**
@ -16,6 +16,7 @@ var blockOpenRe = /[{[]$/,
* @returns {Codegen} Codegen instance
* @property {boolean} supported Whether code generation is supported by the environment.
* @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging.
* @property {function(string, ...*):string} sprintf Underlying sprintf implementation
*/
function codegen() {
var params = [],
@ -131,5 +132,6 @@ function sprintf(format) {
});
}
codegen.sprintf = sprintf;
codegen.supported = false; try { codegen.supported = codegen("a","b")("return a-b").eof()(2,1) === 1; } catch (e) {} // eslint-disable-line no-empty
codegen.verbose = false;

View File

@ -137,43 +137,6 @@ util.ucFirst = function ucFirst(str) { // lcFirst counterpart is in core util
return str.charAt(0).toUpperCase() + str.substring(1);
};
/**
* Defines the specified properties on the specified target. Also adds getters and setters for non-ES5 environments.
* @param {Object} target Target object
* @param {Object.<string,*>} descriptors Property descriptors
* @returns {undefined}
*/
util.props = function props(target, descriptors) {
Object.keys(descriptors).forEach(function(key) {
util.prop(target, key, descriptors[key]);
});
};
/**
* Defines the specified property on the specified target. Also adds getters and setters for non-ES5 environments.
* @param {Object} target Target object
* @param {string} key Property name
* @param {Object.<string,*>} descriptor Property descriptor
* @returns {undefined}
*/
util.prop = function prop(target, key, descriptor) {
var ucKey = util.ucFirst(key);
if (descriptor.get)
target["get" + ucKey] = descriptor.get;
if (descriptor.set)
target["set" + ucKey] = util.isIE8
? function(value) {
descriptor.set.call(this, value);
this[key] = value;
}
: descriptor.set;
if (util.isIE8) {
if (descriptor.value !== undefined)
target[key] = descriptor.value;
} else
Object.defineProperty(target, key, descriptor);
};
/**
* An immuable empty array.
* @memberof util

View File

@ -2,11 +2,10 @@
module.exports = verifier;
var Enum = require("./enum"),
Type = require("./type"),
util = require("./util");
function invalid(field, expected) {
return "invalid value for field " + field.getFullName() + " (" + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected)";
return field.fullName.substring(1) + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
}
function genVerifyValue(gen, field, fieldIndex, ref) {
@ -22,10 +21,10 @@ function genVerifyValue(gen, field, fieldIndex, ref) {
gen
("break")
("}");
} else if (field.resolvedType instanceof Type) gen
("var s;")
("if(s=types[%d].verify(%s))", fieldIndex, ref)
("return s");
} else gen
("var e;")
("if(e=types[%d].verify(%s))", fieldIndex, ref)
("return e");
} else {
switch (field.type) {
case "int32":
@ -100,7 +99,9 @@ function genVerifyKey(gen, field, ref) {
*/
function verifier(mtype) {
/* eslint-disable no-unexpected-multiline */
var fields = mtype.getFieldsArray();
var fields = mtype.fieldsArray;
if (!fields.length)
return util.codegen()("return null");
var gen = util.codegen("m");
for (var i = 0; i < fields.length; ++i) {
@ -133,7 +134,7 @@ function verifier(mtype) {
// required or present fields
} else {
if (!field.required) {
if (field.resolvedType instanceof Type) gen
if (field.resolvedType && !(field.resolvedType instanceof Enum)) gen
("if(%s!==undefined&&%s!==null){", ref, ref);
else gen
("if(%s!==undefined){", ref);

View File

@ -1,4 +1,5 @@
var tape = require("tape");
var protobuf = require("..");
tape.test("convert", function(test) {

View File

@ -1,4 +1,5 @@
"use strict"; // eslint-disable-line strict
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
"use strict";
var $protobuf = require("../../runtime");
@ -43,22 +44,25 @@ $root.A = (function() {
};
/**
* Encodes the specified A.
* Encodes the specified A message.
* @function
* @param {A|Object} message A or plain object to encode
* @param {A|Object} message A message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
A.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.whatever !== undefined && message.whatever !== "")
writer.uint32(10/*= id 1, wireType 2 */).string(message.whatever)
return writer
}})($protobuf.Writer, $protobuf.util, [null]); /* eslint-enable */
A.encode = (function(Writer) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.whatever !== undefined && message.whatever !== "") {
writer.uint32(10).string(message.whatever);
}
return writer;
};})($protobuf.Writer);
/**
* Encodes the specified A, length delimited.
* @param {A|Object} message A or plain object to encode
* Encodes the specified A message, length delimited.
* @param {A|Object} message A message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -67,31 +71,34 @@ $root.A = (function() {
};
/**
* Decodes a A from the specified reader or buffer.
* Decodes a A message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {A} A
*/
A.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.A
A.decode = (function(Reader) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.A();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.whatever = reader.string()
break
default:
reader.skipType(tag & 7)
break
case 1:
message.whatever = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, [null]); /* eslint-enable */
return message;
};})($protobuf.Reader);
/**
* Decodes a A from the specified reader or buffer, length delimited.
* Decodes a A message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {A} A
*/
@ -101,18 +108,59 @@ $root.A = (function() {
};
/**
* Verifies a A.
* Verifies a A message.
* @function
* @param {A|Object} message A or plain object to verify
* @param {A|Object} message A message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
A.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
A.verify = (function(util) { return function verify(message) {
if (message.whatever !== undefined) {
if (!util.isString(message.whatever))
return "invalid value for field .A.whatever (string expected)"
if (!util.isString(message.whatever)) {
return "A.whatever: string expected";
}
}
return null
}})($protobuf.util, [null]); /* eslint-enable */
return null;
};})($protobuf.util);
/**
* Converts a A message.
* @function
* @param {A|Object} source A message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {A|Object} Converted message
*/
A.convert = (function() { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
if (dst.whatever === undefined && options.defaults) {
dst.whatever = "";
}
}
return dst;
};})();
/**
* Creates a A message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {A} A
*/
A.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this A message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
return A;
})();
@ -142,6 +190,9 @@ $root.B = (function() {
*/
$prototype.A = null;
// Referenced types
var $types = ["A"]; $lazyTypes.push($types);
/**
* Creates a new B instance using the specified properties.
* @param {Object} [properties] Properties to set
@ -152,22 +203,25 @@ $root.B = (function() {
};
/**
* Encodes the specified B.
* Encodes the specified B message.
* @function
* @param {B|Object} message B or plain object to encode
* @param {B|Object} message B message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
B.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.A !== undefined && message.A !== null)
types[0].encode(message.A, writer.uint32(10/*= id 1, wireType 2 */).fork()).ldelim()
return writer
}})($protobuf.Writer, $protobuf.util, ["A"]); /* eslint-enable */
B.encode = (function(Writer, types) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.A !== undefined && message.A !== null) {
types[0].encode(message.A, writer.uint32(10).fork()).ldelim();
}
return writer;
};})($protobuf.Writer, $types);
/**
* Encodes the specified B, length delimited.
* @param {B|Object} message B or plain object to encode
* Encodes the specified B message, length delimited.
* @param {B|Object} message B message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -176,31 +230,34 @@ $root.B = (function() {
};
/**
* Decodes a B from the specified reader or buffer.
* Decodes a B message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {B} B
*/
B.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.B
B.decode = (function(Reader, types) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.B();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.A = types[0].decode(reader, reader.uint32())
break
default:
reader.skipType(tag & 7)
break
case 1:
message.A = types[0].decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, ["A"]); /* eslint-enable */
return message;
};})($protobuf.Reader, $types);
/**
* Decodes a B from the specified reader or buffer, length delimited.
* Decodes a B message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {B} B
*/
@ -210,19 +267,58 @@ $root.B = (function() {
};
/**
* Verifies a B.
* Verifies a B message.
* @function
* @param {B|Object} message B or plain object to verify
* @param {B|Object} message B message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
B.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
B.verify = (function(types) { return function verify(message) {
if (message.A !== undefined && message.A !== null) {
var reason;
if (reason = types[0].verify(message.A))
return reason
var err;
if (err = types[0].verify(message.A)) {
return err;
}
}
return null
}})($protobuf.util, ["A"]); /* eslint-enable */
return null;
};})($types);
/**
* Converts a B message.
* @function
* @param {B|Object} source B message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {B|Object} Converted message
*/
B.convert = (function(types) { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
dst.A = types[0].convert(src.A, impl, options);
}
return dst;
};})($types);
/**
* Creates a B message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {B} B
*/
B.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this B message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
return B;
})();
@ -232,7 +328,7 @@ $lazyTypes.forEach(function(types) {
types.forEach(function(path, i) {
if (!path)
return;
path = path.split('.');
path = path.split(".");
var ptr = $root;
while (path.length)
ptr = ptr[path.shift()];

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
"use strict"; // eslint-disable-line strict
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
"use strict";
var $protobuf = require("../../runtime");
@ -123,6 +124,9 @@ $root.Package = (function() {
*/
$prototype.types = "";
// Referenced types
var $types = [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null]; $lazyTypes.push($types);
/**
* Creates a new Package instance using the specified properties.
* @param {Object} [properties] Properties to set
@ -133,78 +137,82 @@ $root.Package = (function() {
};
/**
* Encodes the specified Package.
* Encodes the specified Package message.
* @function
* @param {Package|Object} message Package or plain object to encode
* @param {Package|Object} message Package message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Package.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.name !== undefined && message.name !== "")
writer.uint32(10/*= id 1, wireType 2 */).string(message.name)
if (message.version !== undefined && message.version !== "")
writer.uint32(18/*= id 2, wireType 2 */).string(message.version)
if (message.description !== undefined && message.description !== "")
writer.uint32(26/*= id 3, wireType 2 */).string(message.description)
if (message.author !== undefined && message.author !== "")
writer.uint32(34/*= id 4, wireType 2 */).string(message.author)
if (message.license !== undefined && message.license !== "")
writer.uint32(42/*= id 5, wireType 2 */).string(message.license)
if (message.repository !== undefined && message.repository !== null)
types[5].encode(message.repository, writer.uint32(50/*= id 6, wireType 2 */).fork()).ldelim()
if (message.bugs !== undefined && message.bugs !== "")
writer.uint32(58/*= id 7, wireType 2 */).string(message.bugs)
if (message.homepage !== undefined && message.homepage !== "")
writer.uint32(66/*= id 8, wireType 2 */).string(message.homepage)
if (message.keywords)
for (var i = 0; i < message.keywords.length; ++i)
writer.uint32(74/*= id 9, wireType 2 */).string(message.keywords[i])
if (message.main !== undefined && message.main !== "")
writer.uint32(82/*= id 10, wireType 2 */).string(message.main)
Package.encode = (function(Writer, util, types) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.name !== undefined && message.name !== "") {
writer.uint32(10).string(message.name);
}
if (message.version !== undefined && message.version !== "") {
writer.uint32(18).string(message.version);
}
if (message.description !== undefined && message.description !== "") {
writer.uint32(26).string(message.description);
}
if (message.author !== undefined && message.author !== "") {
writer.uint32(34).string(message.author);
}
if (message.license !== undefined && message.license !== "") {
writer.uint32(42).string(message.license);
}
if (message.repository !== undefined && message.repository !== null) {
types[5].encode(message.repository, writer.uint32(50).fork()).ldelim();
}
if (message.bugs !== undefined && message.bugs !== "") {
writer.uint32(58).string(message.bugs);
}
if (message.homepage !== undefined && message.homepage !== "") {
writer.uint32(66).string(message.homepage);
}
if (message.keywords) {
for (var i = 0; i < message.keywords.length; ++i) {
writer.uint32(74).string(message.keywords[i]);
}
}
if (message.main !== undefined && message.main !== "") {
writer.uint32(82).string(message.main);
}
if (message.bin && message.bin !== util.emptyObject) {
for (var keys = Object.keys(message.bin), i = 0; i < keys.length; ++i) {
writer.uint32(90/*= id 11, wireType 2 */).fork().uint32(10/*= id 1, wireType 2 */).string(keys[i])
writer.uint32(18/*= id 2, wireType 2 */).string(message.bin[keys[i]])
writer.ldelim()
writer.uint32(90).fork().uint32(10).string(keys[i]).uint32(18).string(message.bin[keys[i]]).ldelim();
}
}
if (message.scripts && message.scripts !== util.emptyObject) {
for (var keys = Object.keys(message.scripts), i = 0; i < keys.length; ++i) {
writer.uint32(98/*= id 12, wireType 2 */).fork().uint32(10/*= id 1, wireType 2 */).string(keys[i])
writer.uint32(18/*= id 2, wireType 2 */).string(message.scripts[keys[i]])
writer.ldelim()
writer.uint32(98).fork().uint32(10).string(keys[i]).uint32(18).string(message.scripts[keys[i]]).ldelim();
}
}
if (message.dependencies && message.dependencies !== util.emptyObject) {
for (var keys = Object.keys(message.dependencies), i = 0; i < keys.length; ++i) {
writer.uint32(106/*= id 13, wireType 2 */).fork().uint32(10/*= id 1, wireType 2 */).string(keys[i])
writer.uint32(18/*= id 2, wireType 2 */).string(message.dependencies[keys[i]])
writer.ldelim()
writer.uint32(106).fork().uint32(10).string(keys[i]).uint32(18).string(message.dependencies[keys[i]]).ldelim();
}
}
if (message.optionalDependencies && message.optionalDependencies !== util.emptyObject) {
for (var keys = Object.keys(message.optionalDependencies), i = 0; i < keys.length; ++i) {
writer.uint32(114/*= id 14, wireType 2 */).fork().uint32(10/*= id 1, wireType 2 */).string(keys[i])
writer.uint32(18/*= id 2, wireType 2 */).string(message.optionalDependencies[keys[i]])
writer.ldelim()
writer.uint32(114).fork().uint32(10).string(keys[i]).uint32(18).string(message.optionalDependencies[keys[i]]).ldelim();
}
}
if (message.devDependencies && message.devDependencies !== util.emptyObject) {
for (var keys = Object.keys(message.devDependencies), i = 0; i < keys.length; ++i) {
writer.uint32(122/*= id 15, wireType 2 */).fork().uint32(10/*= id 1, wireType 2 */).string(keys[i])
writer.uint32(18/*= id 2, wireType 2 */).string(message.devDependencies[keys[i]])
writer.ldelim()
writer.uint32(122).fork().uint32(10).string(keys[i]).uint32(18).string(message.devDependencies[keys[i]]).ldelim();
}
}
if (message.types !== undefined && message.types !== "")
writer.uint32(138/*= id 17, wireType 2 */).string(message.types)
return writer
}})($protobuf.Writer, $protobuf.util, [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null]); /* eslint-enable */
if (message.types !== undefined && message.types !== "") {
writer.uint32(138).string(message.types);
}
return writer;
};})($protobuf.Writer, $protobuf.util, $types);
/**
* Encodes the specified Package, length delimited.
* @param {Package|Object} message Package or plain object to encode
* Encodes the specified Package message, length delimited.
* @param {Package|Object} message Package message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -213,112 +221,142 @@ $root.Package = (function() {
};
/**
* Decodes a Package from the specified reader or buffer.
* Decodes a Package message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {Package} Package
*/
Package.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Package
Package.decode = (function(Reader, util, types) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.Package();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.name = reader.string()
break
case 2:
message.version = reader.string()
break
case 3:
message.description = reader.string()
break
case 4:
message.author = reader.string()
break
case 5:
message.license = reader.string()
break
case 6:
message.repository = types[5].decode(reader, reader.uint32())
break
case 7:
message.bugs = reader.string()
break
case 8:
message.homepage = reader.string()
break
case 9:
message.keywords && message.keywords.length || (message.keywords = [])
message.keywords.push(reader.string())
break
case 10:
message.main = reader.string()
break
case 11:
reader.skip().pos++
if (message.bin === util.emptyObject)
message.bin = {}
var key = reader.string()
if (typeof key === "object")
key = util.longToHash(key)
reader.pos++
message.bin[key] = reader.string()
break
case 12:
reader.skip().pos++
if (message.scripts === util.emptyObject)
message.scripts = {}
var key = reader.string()
if (typeof key === "object")
key = util.longToHash(key)
reader.pos++
message.scripts[key] = reader.string()
break
case 13:
reader.skip().pos++
if (message.dependencies === util.emptyObject)
message.dependencies = {}
var key = reader.string()
if (typeof key === "object")
key = util.longToHash(key)
reader.pos++
message.dependencies[key] = reader.string()
break
case 14:
reader.skip().pos++
if (message.optionalDependencies === util.emptyObject)
message.optionalDependencies = {}
var key = reader.string()
if (typeof key === "object")
key = util.longToHash(key)
reader.pos++
message.optionalDependencies[key] = reader.string()
break
case 15:
reader.skip().pos++
if (message.devDependencies === util.emptyObject)
message.devDependencies = {}
var key = reader.string()
if (typeof key === "object")
key = util.longToHash(key)
reader.pos++
message.devDependencies[key] = reader.string()
break
case 17:
message.types = reader.string()
break
default:
reader.skipType(tag & 7)
break
case 1:
message.name = reader.string();
break;
case 2:
message.version = reader.string();
break;
case 3:
message.description = reader.string();
break;
case 4:
message.author = reader.string();
break;
case 5:
message.license = reader.string();
break;
case 6:
message.repository = types[5].decode(reader, reader.uint32());
break;
case 7:
message.bugs = reader.string();
break;
case 8:
message.homepage = reader.string();
break;
case 9:
if (!(message.keywords && message.keywords.length)) {
message.keywords = [];
}
message.keywords.push(reader.string());
break;
case 10:
message.main = reader.string();
break;
case 11:
reader.skip().pos++;
if (message.bin === util.emptyObject) {
message.bin = {};
}
var key = reader.string();
if (typeof key === "object") {
key = util.longToHash(key);
}
reader.pos++;
message.bin[key] = reader.string();
break;
case 12:
reader.skip().pos++;
if (message.scripts === util.emptyObject) {
message.scripts = {};
}
var key = reader.string();
if (typeof key === "object") {
key = util.longToHash(key);
}
reader.pos++;
message.scripts[key] = reader.string();
break;
case 13:
reader.skip().pos++;
if (message.dependencies === util.emptyObject) {
message.dependencies = {};
}
var key = reader.string();
if (typeof key === "object") {
key = util.longToHash(key);
}
reader.pos++;
message.dependencies[key] = reader.string();
break;
case 14:
reader.skip().pos++;
if (message.optionalDependencies === util.emptyObject) {
message.optionalDependencies = {};
}
var key = reader.string();
if (typeof key === "object") {
key = util.longToHash(key);
}
reader.pos++;
message.optionalDependencies[key] = reader.string();
break;
case 15:
reader.skip().pos++;
if (message.devDependencies === util.emptyObject) {
message.devDependencies = {};
}
var key = reader.string();
if (typeof key === "object") {
key = util.longToHash(key);
}
reader.pos++;
message.devDependencies[key] = reader.string();
break;
case 17:
message.types = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null]); /* eslint-enable */
return message;
};})($protobuf.Reader, $protobuf.util, $types);
/**
* Decodes a Package from the specified reader or buffer, length delimited.
* Decodes a Package message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {Package} Package
*/
@ -328,108 +366,220 @@ $root.Package = (function() {
};
/**
* Verifies a Package.
* Verifies a Package message.
* @function
* @param {Package|Object} message Package or plain object to verify
* @param {Package|Object} message Package message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Package.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
Package.verify = (function(util, types) { return function verify(message) {
if (message.name !== undefined) {
if (!util.isString(message.name))
return "invalid value for field .Package.name (string expected)"
if (!util.isString(message.name)) {
return "Package.name: string expected";
}
}
if (message.version !== undefined) {
if (!util.isString(message.version))
return "invalid value for field .Package.version (string expected)"
if (!util.isString(message.version)) {
return "Package.version: string expected";
}
}
if (message.description !== undefined) {
if (!util.isString(message.description))
return "invalid value for field .Package.description (string expected)"
if (!util.isString(message.description)) {
return "Package.description: string expected";
}
}
if (message.author !== undefined) {
if (!util.isString(message.author))
return "invalid value for field .Package.author (string expected)"
if (!util.isString(message.author)) {
return "Package.author: string expected";
}
}
if (message.license !== undefined) {
if (!util.isString(message.license))
return "invalid value for field .Package.license (string expected)"
if (!util.isString(message.license)) {
return "Package.license: string expected";
}
}
if (message.repository !== undefined && message.repository !== null) {
var reason;
if (reason = types[5].verify(message.repository))
return reason
var err;
if (err = types[5].verify(message.repository)) {
return err;
}
}
if (message.bugs !== undefined) {
if (!util.isString(message.bugs))
return "invalid value for field .Package.bugs (string expected)"
if (!util.isString(message.bugs)) {
return "Package.bugs: string expected";
}
}
if (message.homepage !== undefined) {
if (!util.isString(message.homepage))
return "invalid value for field .Package.homepage (string expected)"
if (!util.isString(message.homepage)) {
return "Package.homepage: string expected";
}
}
if (message.keywords !== undefined) {
if (!Array.isArray(message.keywords))
return "invalid value for field .Package.keywords (array expected)"
if (!Array.isArray(message.keywords)) {
return "Package.keywords: array expected";
}
for (var i = 0; i < message.keywords.length; ++i) {
if (!util.isString(message.keywords[i]))
return "invalid value for field .Package.keywords (string[] expected)"
if (!util.isString(message.keywords[i])) {
return "Package.keywords: string[] expected";
}
}
}
if (message.main !== undefined) {
if (!util.isString(message.main))
return "invalid value for field .Package.main (string expected)"
if (!util.isString(message.main)) {
return "Package.main: string expected";
}
}
if (message.bin !== undefined) {
if (!util.isObject(message.bin))
return "invalid value for field .Package.bin (object expected)"
var key = Object.keys(message.bin)
if (!util.isObject(message.bin)) {
return "Package.bin: object expected";
}
var key = Object.keys(message.bin);
for (var i = 0; i < key.length; ++i) {
if (!util.isString(message.bin[key[i]]))
return "invalid value for field .Package.bin (string{key : string} expected)"
if (!util.isString(message.bin[key[i]])) {
return "Package.bin: string{key:string} expected";
}
}
}
if (message.scripts !== undefined) {
if (!util.isObject(message.scripts))
return "invalid value for field .Package.scripts (object expected)"
var key = Object.keys(message.scripts)
if (!util.isObject(message.scripts)) {
return "Package.scripts: object expected";
}
var key = Object.keys(message.scripts);
for (var i = 0; i < key.length; ++i) {
if (!util.isString(message.scripts[key[i]]))
return "invalid value for field .Package.scripts (string{key : string} expected)"
if (!util.isString(message.scripts[key[i]])) {
return "Package.scripts: string{key:string} expected";
}
}
}
if (message.dependencies !== undefined) {
if (!util.isObject(message.dependencies))
return "invalid value for field .Package.dependencies (object expected)"
var key = Object.keys(message.dependencies)
if (!util.isObject(message.dependencies)) {
return "Package.dependencies: object expected";
}
var key = Object.keys(message.dependencies);
for (var i = 0; i < key.length; ++i) {
if (!util.isString(message.dependencies[key[i]]))
return "invalid value for field .Package.dependencies (string{key : string} expected)"
if (!util.isString(message.dependencies[key[i]])) {
return "Package.dependencies: string{key:string} expected";
}
}
}
if (message.optionalDependencies !== undefined) {
if (!util.isObject(message.optionalDependencies))
return "invalid value for field .Package.optionalDependencies (object expected)"
var key = Object.keys(message.optionalDependencies)
if (!util.isObject(message.optionalDependencies)) {
return "Package.optionalDependencies: object expected";
}
var key = Object.keys(message.optionalDependencies);
for (var i = 0; i < key.length; ++i) {
if (!util.isString(message.optionalDependencies[key[i]]))
return "invalid value for field .Package.optionalDependencies (string{key : string} expected)"
if (!util.isString(message.optionalDependencies[key[i]])) {
return "Package.optionalDependencies: string{key:string} expected";
}
}
}
if (message.devDependencies !== undefined) {
if (!util.isObject(message.devDependencies))
return "invalid value for field .Package.devDependencies (object expected)"
var key = Object.keys(message.devDependencies)
if (!util.isObject(message.devDependencies)) {
return "Package.devDependencies: object expected";
}
var key = Object.keys(message.devDependencies);
for (var i = 0; i < key.length; ++i) {
if (!util.isString(message.devDependencies[key[i]]))
return "invalid value for field .Package.devDependencies (string{key : string} expected)"
if (!util.isString(message.devDependencies[key[i]])) {
return "Package.devDependencies: string{key:string} expected";
}
}
}
if (message.types !== undefined) {
if (!util.isString(message.types))
return "invalid value for field .Package.types (string expected)"
if (!util.isString(message.types)) {
return "Package.types: string expected";
}
}
return null
}})($protobuf.util, [null, null, null, null, null, "Package.Repository", null, null, null, null, null, null, null, null, null, null]); /* eslint-enable */
return null;
};})($protobuf.util, $types);
/**
* Converts a Package message.
* @function
* @param {Package|Object} source Package message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {Package|Object} Converted message
*/
Package.convert = (function(types) { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
}
if (dst.version === undefined && options.defaults) {
dst.version = "";
}
if (dst.description === undefined && options.defaults) {
dst.description = "";
}
if (dst.author === undefined && options.defaults) {
dst.author = "";
}
if (dst.license === undefined && options.defaults) {
dst.license = "";
}
dst.repository = types[5].convert(src.repository, impl, options);
if (dst.bugs === undefined && options.defaults) {
dst.bugs = "";
}
if (dst.homepage === undefined && options.defaults) {
dst.homepage = "";
}
if (src.keywords && src.keywords.length) {
dst.keywords = [];
for (var i = 0; i < src.keywords.length; ++i) {
dst.keywords.push(src.keywords[i]);
}
} else {
if (options.defaults || options.arrays) {
dst.keywords = [];
}
}
if (dst.main === undefined && options.defaults) {
dst.main = "";
}
if (dst.bin === undefined && options.defaults) {
dst.bin = {};
}
if (dst.scripts === undefined && options.defaults) {
dst.scripts = {};
}
if (dst.dependencies === undefined && options.defaults) {
dst.dependencies = {};
}
if (dst.optionalDependencies === undefined && options.defaults) {
dst.optionalDependencies = {};
}
if (dst.devDependencies === undefined && options.defaults) {
dst.devDependencies = {};
}
if (dst.types === undefined && options.defaults) {
dst.types = "";
}
}
return dst;
};})($types);
/**
* Creates a Package message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {Package} Package
*/
Package.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this Package message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
Package.Repository = (function() {
@ -472,24 +622,28 @@ $root.Package = (function() {
};
/**
* Encodes the specified Repository.
* Encodes the specified Repository message.
* @function
* @param {Package.Repository|Object} message Repository or plain object to encode
* @param {Package.Repository|Object} message Repository message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
Repository.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.type !== undefined && message.type !== "")
writer.uint32(10/*= id 1, wireType 2 */).string(message.type)
if (message.url !== undefined && message.url !== "")
writer.uint32(18/*= id 2, wireType 2 */).string(message.url)
return writer
}})($protobuf.Writer, $protobuf.util, [null, null]); /* eslint-enable */
Repository.encode = (function(Writer) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.type !== undefined && message.type !== "") {
writer.uint32(10).string(message.type);
}
if (message.url !== undefined && message.url !== "") {
writer.uint32(18).string(message.url);
}
return writer;
};})($protobuf.Writer);
/**
* Encodes the specified Repository, length delimited.
* @param {Package.Repository|Object} message Repository or plain object to encode
* Encodes the specified Repository message, length delimited.
* @param {Package.Repository|Object} message Repository message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -498,34 +652,38 @@ $root.Package = (function() {
};
/**
* Decodes a Repository from the specified reader or buffer.
* Decodes a Repository message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {Package.Repository} Repository
*/
Repository.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Package.Repository
Repository.decode = (function(Reader) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.Package.Repository();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.type = reader.string()
break
case 2:
message.url = reader.string()
break
default:
reader.skipType(tag & 7)
break
case 1:
message.type = reader.string();
break;
case 2:
message.url = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, [null, null]); /* eslint-enable */
return message;
};})($protobuf.Reader);
/**
* Decodes a Repository from the specified reader or buffer, length delimited.
* Decodes a Repository message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {Package.Repository} Repository
*/
@ -535,22 +693,67 @@ $root.Package = (function() {
};
/**
* Verifies a Repository.
* Verifies a Repository message.
* @function
* @param {Package.Repository|Object} message Repository or plain object to verify
* @param {Package.Repository|Object} message Repository message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
Repository.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
Repository.verify = (function(util) { return function verify(message) {
if (message.type !== undefined) {
if (!util.isString(message.type))
return "invalid value for field .Package.Repository.type (string expected)"
if (!util.isString(message.type)) {
return "Package.Repository.type: string expected";
}
}
if (message.url !== undefined) {
if (!util.isString(message.url))
return "invalid value for field .Package.Repository.url (string expected)"
if (!util.isString(message.url)) {
return "Package.Repository.url: string expected";
}
}
return null
}})($protobuf.util, [null, null]); /* eslint-enable */
return null;
};})($protobuf.util);
/**
* Converts a Repository message.
* @function
* @param {Package.Repository|Object} source Repository message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {Package.Repository|Object} Converted message
*/
Repository.convert = (function() { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
if (dst.type === undefined && options.defaults) {
dst.type = "";
}
if (dst.url === undefined && options.defaults) {
dst.url = "";
}
}
return dst;
};})();
/**
* Creates a Repository message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {Package.Repository} Repository
*/
Repository.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this Repository message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
return Repository;
})();
@ -563,7 +766,7 @@ $lazyTypes.forEach(function(types) {
types.forEach(function(path, i) {
if (!path)
return;
path = path.split('.');
path = path.split(".");
var ptr = $root;
while (path.length)
ptr = ptr[path.shift()];

View File

@ -1,4 +1,5 @@
"use strict"; // eslint-disable-line strict
/* eslint-disable block-scoped-var, no-redeclare, no-control-regex, strict */
"use strict";
var $protobuf = require("../../runtime");
@ -30,7 +31,7 @@ $root.MyService = (function() {
*/
/**
* Constructs a new MyService.
* Constructs a new MyService service.
* @exports MyService
* @constructor
* @param {RPCImpl} rpc RPC implementation
@ -68,7 +69,7 @@ $root.MyService = (function() {
/**
* Calls MyMethod.
* @param {MyRequest|Object} request MyRequest or plain object
* @param {MyRequest|Object} request MyRequest message or plain object
* @param {MyService_myMethod_Callback} callback Node-style callback called with the error, if any, and MyResponse
* @returns {undefined}
*/
@ -135,22 +136,25 @@ $root.MyRequest = (function() {
};
/**
* Encodes the specified MyRequest.
* Encodes the specified MyRequest message.
* @function
* @param {MyRequest|Object} message MyRequest or plain object to encode
* @param {MyRequest|Object} message MyRequest message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
MyRequest.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.path !== undefined && message.path !== "")
writer.uint32(10/*= id 1, wireType 2 */).string(message.path)
return writer
}})($protobuf.Writer, $protobuf.util, [null]); /* eslint-enable */
MyRequest.encode = (function(Writer) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.path !== undefined && message.path !== "") {
writer.uint32(10).string(message.path);
}
return writer;
};})($protobuf.Writer);
/**
* Encodes the specified MyRequest, length delimited.
* @param {MyRequest|Object} message MyRequest or plain object to encode
* Encodes the specified MyRequest message, length delimited.
* @param {MyRequest|Object} message MyRequest message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -159,31 +163,34 @@ $root.MyRequest = (function() {
};
/**
* Decodes a MyRequest from the specified reader or buffer.
* Decodes a MyRequest message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {MyRequest} MyRequest
*/
MyRequest.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.MyRequest
MyRequest.decode = (function(Reader) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.MyRequest();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.path = reader.string()
break
default:
reader.skipType(tag & 7)
break
case 1:
message.path = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, [null]); /* eslint-enable */
return message;
};})($protobuf.Reader);
/**
* Decodes a MyRequest from the specified reader or buffer, length delimited.
* Decodes a MyRequest message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {MyRequest} MyRequest
*/
@ -193,18 +200,59 @@ $root.MyRequest = (function() {
};
/**
* Verifies a MyRequest.
* Verifies a MyRequest message.
* @function
* @param {MyRequest|Object} message MyRequest or plain object to verify
* @param {MyRequest|Object} message MyRequest message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
MyRequest.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
MyRequest.verify = (function(util) { return function verify(message) {
if (message.path !== undefined) {
if (!util.isString(message.path))
return "invalid value for field .MyRequest.path (string expected)"
if (!util.isString(message.path)) {
return "MyRequest.path: string expected";
}
}
return null
}})($protobuf.util, [null]); /* eslint-enable */
return null;
};})($protobuf.util);
/**
* Converts a MyRequest message.
* @function
* @param {MyRequest|Object} source MyRequest message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {MyRequest|Object} Converted message
*/
MyRequest.convert = (function() { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
if (dst.path === undefined && options.defaults) {
dst.path = "";
}
}
return dst;
};})();
/**
* Creates a MyRequest message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {MyRequest} MyRequest
*/
MyRequest.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this MyRequest message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
return MyRequest;
})();
@ -244,22 +292,25 @@ $root.MyResponse = (function() {
};
/**
* Encodes the specified MyResponse.
* Encodes the specified MyResponse message.
* @function
* @param {MyResponse|Object} message MyResponse or plain object to encode
* @param {MyResponse|Object} message MyResponse message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
MyResponse.encode = /* eslint-disable */ (function(Writer, util, types) { $lazyTypes.push(types); return function encode(message, writer) {
writer || (writer = Writer.create())
if (message.status !== undefined && message.status !== 0)
writer.uint32(16/*= id 2, wireType 0 */).int32(message.status)
return writer
}})($protobuf.Writer, $protobuf.util, [null]); /* eslint-enable */
MyResponse.encode = (function(Writer) { return function encode(message, writer) {
if (!writer) {
writer = Writer.create();
}
if (message.status !== undefined && message.status !== 0) {
writer.uint32(16).int32(message.status);
}
return writer;
};})($protobuf.Writer);
/**
* Encodes the specified MyResponse, length delimited.
* @param {MyResponse|Object} message MyResponse or plain object to encode
* Encodes the specified MyResponse message, length delimited.
* @param {MyResponse|Object} message MyResponse message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
@ -268,31 +319,34 @@ $root.MyResponse = (function() {
};
/**
* Decodes a MyResponse from the specified reader or buffer.
* Decodes a MyResponse message from the specified reader or buffer.
* @function
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {MyResponse} MyResponse
*/
MyResponse.decode = /* eslint-disable */ (function(Reader, util, types) { $lazyTypes.push(types); return function decode(reader, length) {
reader instanceof Reader || (reader = Reader.create(reader))
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.MyResponse
MyResponse.decode = (function(Reader) { return function decode(reader, len) {
if (!(reader instanceof Reader)) {
reader = Reader.create(reader);
}
var end = len === undefined ? reader.len : reader.pos + len, message = new $root.MyResponse();
while (reader.pos < end) {
var tag = reader.uint32()
var tag = reader.uint32();
switch (tag >>> 3) {
case 2:
message.status = reader.int32()
break
default:
reader.skipType(tag & 7)
break
case 2:
message.status = reader.int32();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message
}})($protobuf.Reader, $protobuf.util, [null]); /* eslint-enable */
return message;
};})($protobuf.Reader);
/**
* Decodes a MyResponse from the specified reader or buffer, length delimited.
* Decodes a MyResponse message from the specified reader or buffer, length delimited.
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
* @returns {MyResponse} MyResponse
*/
@ -302,18 +356,59 @@ $root.MyResponse = (function() {
};
/**
* Verifies a MyResponse.
* Verifies a MyResponse message.
* @function
* @param {MyResponse|Object} message MyResponse or plain object to verify
* @param {MyResponse|Object} message MyResponse message or plain object to verify
* @returns {?string} `null` if valid, otherwise the reason why it is not
*/
MyResponse.verify = /* eslint-disable */ (function(util, types) { $lazyTypes.push(types); return function verify(message) {
MyResponse.verify = (function(util) { return function verify(message) {
if (message.status !== undefined) {
if (!util.isInteger(message.status))
return "invalid value for field .MyResponse.status (integer expected)"
if (!util.isInteger(message.status)) {
return "MyResponse.status: integer expected";
}
}
return null
}})($protobuf.util, [null]); /* eslint-enable */
return null;
};})($protobuf.util);
/**
* Converts a MyResponse message.
* @function
* @param {MyResponse|Object} source MyResponse message or plain object to convert
* @param {*} impl Converter implementation to use
* @param {Object.<string,*>} [options] Conversion options
* @returns {MyResponse|Object} Converted message
*/
MyResponse.convert = (function() { return function convert(src, impl, options) {
if (!options) {
options = {};
}
var dst = impl.create(src, this, options);
if (dst) {
if (dst.status === undefined && options.defaults) {
dst.status = 0;
}
}
return dst;
};})();
/**
* Creates a MyResponse message from JSON.
* @param {Object.<string,*>} source Source object
* @param {Object.<string,*>} [options] Conversion options
* @returns {MyResponse} MyResponse
*/
MyResponse.from = function from(source, options) {
return this.convert(source, $protobuf.converters.message, options);
};
/**
* Converts this MyResponse message to JSON.
* @param {Object.<string,*>} [options] Conversion options
* @returns {Object.<string,*>} JSON object
*/
$prototype.asJSON = function asJSON(options) {
return this.constructor.convert(this, $protobuf.converters.json, options);
};
return MyResponse;
})();
@ -323,7 +418,7 @@ $lazyTypes.forEach(function(types) {
types.forEach(function(path, i) {
if (!path)
return;
path = path.split('.');
path = path.split(".");
var ptr = $root;
while (path.length)
ptr = ptr[path.shift()];

243
tests/data/test.d.ts vendored
View File

@ -1,5 +1,5 @@
// $> pbts --out tests/data/test.d.ts --no-comments tests/data/test.js
// Generated Sat, 31 Dec 2016 03:08:36 UTC
// Generated Mon, 02 Jan 2017 04:42:18 UTC
import * as $protobuf from "../..";
@ -15,6 +15,14 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Empty;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Empty;
static verify(message: (jspb.test.Empty|Object)): string;
static convert(source: (jspb.test.Empty|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Empty|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Empty;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
enum OuterEnum {
FOO = 1,
BAR = 2
}
class EnumContainer {
@ -26,6 +34,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.EnumContainer;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.EnumContainer;
static verify(message: (jspb.test.EnumContainer|Object)): string;
static convert(source: (jspb.test.EnumContainer|Object), impl: any, options?: { [k: string]: any }): (jspb.test.EnumContainer|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.EnumContainer;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class Simple1 {
@ -39,6 +50,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Simple1;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Simple1;
static verify(message: (jspb.test.Simple1|Object)): string;
static convert(source: (jspb.test.Simple1|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Simple1|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Simple1;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class Simple2 {
@ -51,6 +65,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Simple2;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Simple2;
static verify(message: (jspb.test.Simple2|Object)): string;
static convert(source: (jspb.test.Simple2|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Simple2|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Simple2;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class SpecialCases {
@ -65,6 +82,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.SpecialCases;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.SpecialCases;
static verify(message: (jspb.test.SpecialCases|Object)): string;
static convert(source: (jspb.test.SpecialCases|Object), impl: any, options?: { [k: string]: any }): (jspb.test.SpecialCases|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.SpecialCases;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class OptionalFields {
@ -80,6 +100,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.OptionalFields;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.OptionalFields;
static verify(message: (jspb.test.OptionalFields|Object)): string;
static convert(source: (jspb.test.OptionalFields|Object), impl: any, options?: { [k: string]: any }): (jspb.test.OptionalFields|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.OptionalFields;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace OptionalFields {
@ -93,6 +116,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.OptionalFields.Nested;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.OptionalFields.Nested;
static verify(message: (jspb.test.OptionalFields.Nested|Object)): string;
static convert(source: (jspb.test.OptionalFields.Nested|Object), impl: any, options?: { [k: string]: any }): (jspb.test.OptionalFields.Nested|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.OptionalFields.Nested;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -107,6 +133,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.HasExtensions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.HasExtensions;
static verify(message: (jspb.test.HasExtensions|Object)): string;
static convert(source: (jspb.test.HasExtensions|Object), impl: any, options?: { [k: string]: any }): (jspb.test.HasExtensions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.HasExtensions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class Complex {
@ -122,6 +151,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Complex;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Complex;
static verify(message: (jspb.test.Complex|Object)): string;
static convert(source: (jspb.test.Complex|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Complex|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Complex;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace Complex {
@ -135,6 +167,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Complex.Nested;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Complex.Nested;
static verify(message: (jspb.test.Complex.Nested|Object)): string;
static convert(source: (jspb.test.Complex.Nested|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Complex.Nested|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Complex.Nested;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -146,6 +181,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.OuterMessage;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.OuterMessage;
static verify(message: (jspb.test.OuterMessage|Object)): string;
static convert(source: (jspb.test.OuterMessage|Object), impl: any, options?: { [k: string]: any }): (jspb.test.OuterMessage|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.OuterMessage;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace OuterMessage {
@ -159,6 +197,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.OuterMessage.Complex;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.OuterMessage.Complex;
static verify(message: (jspb.test.OuterMessage.Complex|Object)): string;
static convert(source: (jspb.test.OuterMessage.Complex|Object), impl: any, options?: { [k: string]: any }): (jspb.test.OuterMessage.Complex|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.OuterMessage.Complex;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -171,6 +212,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.IsExtension;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.IsExtension;
static verify(message: (jspb.test.IsExtension|Object)): string;
static convert(source: (jspb.test.IsExtension|Object), impl: any, options?: { [k: string]: any }): (jspb.test.IsExtension|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.IsExtension;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class IndirectExtension {
@ -181,6 +225,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.IndirectExtension;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.IndirectExtension;
static verify(message: (jspb.test.IndirectExtension|Object)): string;
static convert(source: (jspb.test.IndirectExtension|Object), impl: any, options?: { [k: string]: any }): (jspb.test.IndirectExtension|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.IndirectExtension;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class DefaultValues {
@ -197,6 +244,17 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.DefaultValues;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.DefaultValues;
static verify(message: (jspb.test.DefaultValues|Object)): string;
static convert(source: (jspb.test.DefaultValues|Object), impl: any, options?: { [k: string]: any }): (jspb.test.DefaultValues|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.DefaultValues;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace DefaultValues {
enum Enum {
E1 = 13,
E2 = 77
}
}
class FloatingPointFields {
@ -215,6 +273,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.FloatingPointFields;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.FloatingPointFields;
static verify(message: (jspb.test.FloatingPointFields|Object)): string;
static convert(source: (jspb.test.FloatingPointFields|Object), impl: any, options?: { [k: string]: any }): (jspb.test.FloatingPointFields|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.FloatingPointFields;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestClone {
@ -230,6 +291,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestClone;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestClone;
static verify(message: (jspb.test.TestClone|Object)): string;
static convert(source: (jspb.test.TestClone|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestClone|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestClone;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class CloneExtension {
@ -241,6 +305,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.CloneExtension;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.CloneExtension;
static verify(message: (jspb.test.CloneExtension|Object)): string;
static convert(source: (jspb.test.CloneExtension|Object), impl: any, options?: { [k: string]: any }): (jspb.test.CloneExtension|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.CloneExtension;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestGroup {
@ -254,6 +321,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestGroup;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestGroup;
static verify(message: (jspb.test.TestGroup|Object)): string;
static convert(source: (jspb.test.TestGroup|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestGroup|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestGroup;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestReservedNames {
@ -265,6 +335,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestReservedNames;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestReservedNames;
static verify(message: (jspb.test.TestReservedNames|Object)): string;
static convert(source: (jspb.test.TestReservedNames|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestReservedNames|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestReservedNames;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestReservedNamesExtension {
@ -275,6 +348,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestReservedNamesExtension;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestReservedNamesExtension;
static verify(message: (jspb.test.TestReservedNamesExtension|Object)): string;
static convert(source: (jspb.test.TestReservedNamesExtension|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestReservedNamesExtension|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestReservedNamesExtension;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestMessageWithOneof {
@ -299,6 +375,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestMessageWithOneof;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestMessageWithOneof;
static verify(message: (jspb.test.TestMessageWithOneof|Object)): string;
static convert(source: (jspb.test.TestMessageWithOneof|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestMessageWithOneof|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestMessageWithOneof;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestEndsWithBytes {
@ -311,6 +390,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestEndsWithBytes;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestEndsWithBytes;
static verify(message: (jspb.test.TestEndsWithBytes|Object)): string;
static convert(source: (jspb.test.TestEndsWithBytes|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestEndsWithBytes|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestEndsWithBytes;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class TestMapFieldsNoBinary {
@ -333,6 +415,15 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.TestMapFieldsNoBinary;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.TestMapFieldsNoBinary;
static verify(message: (jspb.test.TestMapFieldsNoBinary|Object)): string;
static convert(source: (jspb.test.TestMapFieldsNoBinary|Object), impl: any, options?: { [k: string]: any }): (jspb.test.TestMapFieldsNoBinary|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.TestMapFieldsNoBinary;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
enum MapValueEnumNoBinary {
MAP_VALUE_FOO_NOBINARY = 0,
MAP_VALUE_BAR_NOBINARY = 1,
MAP_VALUE_BAZ_NOBINARY = 2
}
class MapValueMessageNoBinary {
@ -344,6 +435,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.MapValueMessageNoBinary;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.MapValueMessageNoBinary;
static verify(message: (jspb.test.MapValueMessageNoBinary|Object)): string;
static convert(source: (jspb.test.MapValueMessageNoBinary|Object), impl: any, options?: { [k: string]: any }): (jspb.test.MapValueMessageNoBinary|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.MapValueMessageNoBinary;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class Deeply {
@ -354,6 +448,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Deeply;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Deeply;
static verify(message: (jspb.test.Deeply|Object)): string;
static convert(source: (jspb.test.Deeply|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Deeply|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Deeply;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace Deeply {
@ -366,6 +463,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Deeply.Nested;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Deeply.Nested;
static verify(message: (jspb.test.Deeply.Nested|Object)): string;
static convert(source: (jspb.test.Deeply.Nested|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Deeply.Nested|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Deeply.Nested;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace Nested {
@ -379,6 +479,9 @@ export namespace jspb {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): jspb.test.Deeply.Nested.Message;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): jspb.test.Deeply.Nested.Message;
static verify(message: (jspb.test.Deeply.Nested.Message|Object)): string;
static convert(source: (jspb.test.Deeply.Nested.Message|Object), impl: any, options?: { [k: string]: any }): (jspb.test.Deeply.Nested.Message|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): jspb.test.Deeply.Nested.Message;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
}
@ -398,6 +501,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FileDescriptorSet;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.FileDescriptorSet;
static verify(message: (google.protobuf.FileDescriptorSet|Object)): string;
static convert(source: (google.protobuf.FileDescriptorSet|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.FileDescriptorSet|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.FileDescriptorSet;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class FileDescriptorProto {
@ -420,6 +526,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FileDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.FileDescriptorProto;
static verify(message: (google.protobuf.FileDescriptorProto|Object)): string;
static convert(source: (google.protobuf.FileDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.FileDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.FileDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class DescriptorProto {
@ -440,6 +549,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.DescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.DescriptorProto;
static verify(message: (google.protobuf.DescriptorProto|Object)): string;
static convert(source: (google.protobuf.DescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.DescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.DescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace DescriptorProto {
@ -454,6 +566,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.DescriptorProto.ExtensionRange;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.DescriptorProto.ExtensionRange;
static verify(message: (google.protobuf.DescriptorProto.ExtensionRange|Object)): string;
static convert(source: (google.protobuf.DescriptorProto.ExtensionRange|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.DescriptorProto.ExtensionRange|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.DescriptorProto.ExtensionRange;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class ReservedRange {
@ -466,6 +581,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.DescriptorProto.ReservedRange;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.DescriptorProto.ReservedRange;
static verify(message: (google.protobuf.DescriptorProto.ReservedRange|Object)): string;
static convert(source: (google.protobuf.DescriptorProto.ReservedRange|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.DescriptorProto.ReservedRange|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.DescriptorProto.ReservedRange;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -487,6 +605,39 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FieldDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.FieldDescriptorProto;
static verify(message: (google.protobuf.FieldDescriptorProto|Object)): string;
static convert(source: (google.protobuf.FieldDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.FieldDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.FieldDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace FieldDescriptorProto {
enum Type {
TYPE_DOUBLE = 1,
TYPE_FLOAT = 2,
TYPE_INT64 = 3,
TYPE_UINT64 = 4,
TYPE_INT32 = 5,
TYPE_FIXED64 = 6,
TYPE_FIXED32 = 7,
TYPE_BOOL = 8,
TYPE_STRING = 9,
TYPE_GROUP = 10,
TYPE_MESSAGE = 11,
TYPE_BYTES = 12,
TYPE_UINT32 = 13,
TYPE_ENUM = 14,
TYPE_SFIXED32 = 15,
TYPE_SFIXED64 = 16,
TYPE_SINT32 = 17,
TYPE_SINT64 = 18
}
enum Label {
LABEL_OPTIONAL = 1,
LABEL_REQUIRED = 2,
LABEL_REPEATED = 3
}
}
class OneofDescriptorProto {
@ -499,6 +650,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.OneofDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.OneofDescriptorProto;
static verify(message: (google.protobuf.OneofDescriptorProto|Object)): string;
static convert(source: (google.protobuf.OneofDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.OneofDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.OneofDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class EnumDescriptorProto {
@ -512,6 +666,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.EnumDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.EnumDescriptorProto;
static verify(message: (google.protobuf.EnumDescriptorProto|Object)): string;
static convert(source: (google.protobuf.EnumDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.EnumDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.EnumDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class EnumValueDescriptorProto {
@ -525,6 +682,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.EnumValueDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.EnumValueDescriptorProto;
static verify(message: (google.protobuf.EnumValueDescriptorProto|Object)): string;
static convert(source: (google.protobuf.EnumValueDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.EnumValueDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.EnumValueDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class ServiceDescriptorProto {
@ -538,6 +698,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.ServiceDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.ServiceDescriptorProto;
static verify(message: (google.protobuf.ServiceDescriptorProto|Object)): string;
static convert(source: (google.protobuf.ServiceDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.ServiceDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.ServiceDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class MethodDescriptorProto {
@ -554,6 +717,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.MethodDescriptorProto;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.MethodDescriptorProto;
static verify(message: (google.protobuf.MethodDescriptorProto|Object)): string;
static convert(source: (google.protobuf.MethodDescriptorProto|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.MethodDescriptorProto|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.MethodDescriptorProto;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class FileOptions {
@ -579,6 +745,18 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FileOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.FileOptions;
static verify(message: (google.protobuf.FileOptions|Object)): string;
static convert(source: (google.protobuf.FileOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.FileOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.FileOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace FileOptions {
enum OptimizeMode {
SPEED = 1,
CODE_SIZE = 2,
LITE_RUNTIME = 3
}
}
class MessageOptions {
@ -594,6 +772,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.MessageOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.MessageOptions;
static verify(message: (google.protobuf.MessageOptions|Object)): string;
static convert(source: (google.protobuf.MessageOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.MessageOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.MessageOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class FieldOptions {
@ -611,6 +792,24 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.FieldOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.FieldOptions;
static verify(message: (google.protobuf.FieldOptions|Object)): string;
static convert(source: (google.protobuf.FieldOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.FieldOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.FieldOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace FieldOptions {
enum CType {
STRING = 0,
CORD = 1,
STRING_PIECE = 2
}
enum JSType {
JS_NORMAL = 0,
JS_STRING = 1,
JS_NUMBER = 2
}
}
class OneofOptions {
@ -622,6 +821,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.OneofOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.OneofOptions;
static verify(message: (google.protobuf.OneofOptions|Object)): string;
static convert(source: (google.protobuf.OneofOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.OneofOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.OneofOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class EnumOptions {
@ -635,6 +837,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.EnumOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.EnumOptions;
static verify(message: (google.protobuf.EnumOptions|Object)): string;
static convert(source: (google.protobuf.EnumOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.EnumOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.EnumOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class EnumValueOptions {
@ -647,6 +852,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.EnumValueOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.EnumValueOptions;
static verify(message: (google.protobuf.EnumValueOptions|Object)): string;
static convert(source: (google.protobuf.EnumValueOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.EnumValueOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.EnumValueOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class ServiceOptions {
@ -659,6 +867,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.ServiceOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.ServiceOptions;
static verify(message: (google.protobuf.ServiceOptions|Object)): string;
static convert(source: (google.protobuf.ServiceOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.ServiceOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.ServiceOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
class MethodOptions {
@ -672,6 +883,18 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.MethodOptions;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.MethodOptions;
static verify(message: (google.protobuf.MethodOptions|Object)): string;
static convert(source: (google.protobuf.MethodOptions|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.MethodOptions|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.MethodOptions;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace MethodOptions {
enum IdempotencyLevel {
IDEMPOTENCY_UNKNOWN = 0,
NO_SIDE_EFFECTS = 1,
IDEMPOTENT = 2
}
}
class UninterpretedOption {
@ -689,6 +912,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.UninterpretedOption;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.UninterpretedOption;
static verify(message: (google.protobuf.UninterpretedOption|Object)): string;
static convert(source: (google.protobuf.UninterpretedOption|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.UninterpretedOption|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.UninterpretedOption;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace UninterpretedOption {
@ -703,6 +929,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.UninterpretedOption.NamePart;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.UninterpretedOption.NamePart;
static verify(message: (google.protobuf.UninterpretedOption.NamePart|Object)): string;
static convert(source: (google.protobuf.UninterpretedOption.NamePart|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.UninterpretedOption.NamePart|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.UninterpretedOption.NamePart;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -715,6 +944,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.SourceCodeInfo;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.SourceCodeInfo;
static verify(message: (google.protobuf.SourceCodeInfo|Object)): string;
static convert(source: (google.protobuf.SourceCodeInfo|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.SourceCodeInfo|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.SourceCodeInfo;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace SourceCodeInfo {
@ -732,6 +964,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.SourceCodeInfo.Location;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.SourceCodeInfo.Location;
static verify(message: (google.protobuf.SourceCodeInfo.Location|Object)): string;
static convert(source: (google.protobuf.SourceCodeInfo.Location|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.SourceCodeInfo.Location|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.SourceCodeInfo.Location;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
@ -744,6 +979,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.GeneratedCodeInfo;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.GeneratedCodeInfo;
static verify(message: (google.protobuf.GeneratedCodeInfo|Object)): string;
static convert(source: (google.protobuf.GeneratedCodeInfo|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.GeneratedCodeInfo|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.GeneratedCodeInfo;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
namespace GeneratedCodeInfo {
@ -760,6 +998,9 @@ export namespace google {
static decode(readerOrBuffer: ($protobuf.Reader|Uint8Array), length?: number): google.protobuf.GeneratedCodeInfo.Annotation;
static decodeDelimited(readerOrBuffer: ($protobuf.Reader|Uint8Array)): google.protobuf.GeneratedCodeInfo.Annotation;
static verify(message: (google.protobuf.GeneratedCodeInfo.Annotation|Object)): string;
static convert(source: (google.protobuf.GeneratedCodeInfo.Annotation|Object), impl: any, options?: { [k: string]: any }): (google.protobuf.GeneratedCodeInfo.Annotation|Object);
static from(source: { [k: string]: any }, options?: { [k: string]: any }): google.protobuf.GeneratedCodeInfo.Annotation;
asJSON(options?: { [k: string]: any }): { [k: string]: any };
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ tape.test("enums", function(test) {
a: 1,
b: 2
});
test.deepEqual(enm.getValuesById(), valsById = {
test.deepEqual(enm.valuesById, valsById = {
1: 'a',
2: 'b'
}, "should also expose their values by id");
@ -18,7 +18,7 @@ tape.test("enums", function(test) {
b: 2,
c: 3
}, "should allow adding new values");
test.deepEqual(enm.getValuesById(), {
test.deepEqual(enm.valuesById, {
1: 'a',
2: 'b',
3: 'c'
@ -29,7 +29,7 @@ tape.test("enums", function(test) {
a: 1,
c: 3
}, "should allow removing existing values");
test.deepEqual(enm.getValuesById(), {
test.deepEqual(enm.valuesById, {
1: 'a',
3: 'c'
}, "should no longer expose any removed values by id");

View File

@ -17,15 +17,15 @@ tape.test("extension fields", function(test) {
var extendedType = new Type("ExtendedType");
ns.add(extendedType);
var extensionField = extendedType.get(declaringField.getFullName());
var extensionField = extendedType.get(declaringField.fullName);
test.equal(extensionField, declaringField.extensionField, "should become available once their extended type is known");
type.remove(declaringField);
extensionField = extendedType.get(declaringField.getFullName());
extensionField = extendedType.get(declaringField.fullName);
test.equal(extensionField, null, "should become unavailable when their declaring field is removed");
type.add(declaringField);
extensionField = extendedType.get(declaringField.getFullName());
extensionField = extendedType.get(declaringField.fullName);
test.equal(extensionField, declaringField.extensionField, "should become instantly available if their extended type is knwon");
test.end();

View File

@ -16,20 +16,20 @@ tape.test("oneofs", function(test) {
});
test.equal(message.num, 1, "should initialize the last value");
test.equal(message.getKind(), "num", "should reference the last value");
test.equal(message.kind, "num", "should reference the last value");
message.setKind('num');
message.kind = 'num';
test.notOk(message.hasOwnProperty('str'), "should delete other values");
message.str = "a";
message.setKind('str'); // message.kind = 'str' if IE8 support isn't required
message.kind = 'str';
test.notOk(message.hasOwnProperty('num'), "should delete the previous value");
test.equal(message.str, "a", "should set the new value");
test.equal(message.kind, "str", "should reference the new value");
message.num = 0; // default
message.setKind('num');
message.kind = 'num';
test.notOk(message.hasOwnProperty('str'), "should delete the previous value");
test.equal(message.num, 0, "should set the new value");
test.equal(message.kind, "num", "should reference the new value");

View File

@ -44,7 +44,7 @@ tape.test("RPC", function(test) {
}), function(err, response) {
if (err)
return test.fail(err.message);
test.ok(response instanceof MyResponse.getCtor(), "should return an instance of MyResponse");
test.ok(response instanceof MyResponse.ctor, "should return an instance of MyResponse");
test.deepEqual(response, {
status: 200
}, "should return status 200");

View File

@ -43,7 +43,7 @@ tape.test("services", function(test) {
});
service.doSomething(DoSomethingRequest.create(), function(err, res) {
test.notOk(err, "should not raise an error");
test.ok(res instanceof DoSomethingResponse.getCtor(), "should return a properly typed response");
test.ok(res instanceof DoSomethingResponse.ctor, "should return a properly typed response");
test.ok(dataEmitted, "should have emitted the data event");
service.end();
});