mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
Breaking: Initial upgrade of converters to real generated functions, see #620
This commit is contained in:
parent
f230d985ab
commit
3946e0fefe
@ -175,13 +175,13 @@ While only useful for the adventurous cherishing an aversion to [generated stati
|
||||
```js
|
||||
var writer = protobuf.Writer.create();
|
||||
var buffer = writer
|
||||
.int32(/* id */ 1 << 3 | /* wireType */ 2)
|
||||
.uint32(/* id */ 1 << 3 | /* wireType */ 2)
|
||||
.string("hello world!")
|
||||
.finish();
|
||||
|
||||
var reader = protobuf.Reader.create(buffer);
|
||||
while (reader.pos < reader.len) {
|
||||
var tag = reader.int32();
|
||||
var tag = reader.uint32();
|
||||
switch (/* id */ tag >>> 3) {
|
||||
case 1:
|
||||
console.log(reader.string());
|
||||
|
||||
@ -94,17 +94,17 @@ setTimeout(function() {
|
||||
.run();
|
||||
|
||||
var dataMessage = Test.from(data);
|
||||
var dataJson = dataMessage.asJSON();
|
||||
var dataObject = dataMessage.toObject();
|
||||
|
||||
newSuite("converting from JSON")
|
||||
.add("Message.from", function() {
|
||||
Test.from(dataJson);
|
||||
newSuite("message from object")
|
||||
.add("Type.fromObject", function() {
|
||||
Test.fromObject(dataObject);
|
||||
})
|
||||
.run();
|
||||
|
||||
newSuite("converting to JSON")
|
||||
.add("Message#asJSON", function() {
|
||||
dataMessage.asJSON();
|
||||
newSuite("message to object")
|
||||
.add("Type.toObject", function() {
|
||||
Test.toObject(dataMessage);
|
||||
})
|
||||
.run();
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ exports.main = function(args, callback) {
|
||||
"",
|
||||
chalk.bold.gray(" Static targets only:"),
|
||||
"",
|
||||
" --no-create Does not generate create functions used for runtime compatibility.",
|
||||
" --no-create Does not generate create functions used for reflection compatibility.",
|
||||
" --no-encode Does not generate encode functions.",
|
||||
" --no-decode Does not generate decode functions.",
|
||||
" --no-verify Does not generate verify functions.",
|
||||
|
||||
@ -154,11 +154,12 @@ function beautify(code) {
|
||||
.replace(/\bc2\b/g, "end2")
|
||||
.replace(/\bk\b/g, "key")
|
||||
.replace(/\bks\b/g, "keys")
|
||||
.replace(/\bks2\b/g, "keys2")
|
||||
.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"),
|
||||
.replace(/\bd\b/g, "object")
|
||||
.replace(/\bn\b/g, "long"),
|
||||
{
|
||||
fromString: true,
|
||||
compress: false,
|
||||
@ -443,40 +444,63 @@ function buildType(ref, type) {
|
||||
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"
|
||||
"Creates " + aOrAn(type.name) + " message from a plain object. Also converts values to their respective internal types.",
|
||||
"@param {Object.<string,*>} object Plain object",
|
||||
"@returns {" + fullName + "} " + type.name
|
||||
]);
|
||||
buildFunction(type, "convert", protobuf.converter(type), {
|
||||
buildFunction(type, "fromObject", protobuf.converter.fromObject(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",
|
||||
"Creates " + aOrAn(type.name) + " message from a plain object. Also converts values to their respective internal types.",
|
||||
"This is an alias of {@link " + fullName + ".fromObject}.",
|
||||
"@function",
|
||||
"@param {Object.<string,*>} object Plain object",
|
||||
"@returns {" + fullName + "} " + type.name
|
||||
]);
|
||||
push(name(type.name) + ".from = function from(source, options) {");
|
||||
push(name(type.name) + ".from = " + name(type.name) + ".fromObject;");
|
||||
|
||||
push("");
|
||||
pushComment([
|
||||
"Creates a plain object from " + aOrAn(type.name) + " message. Also converts values to other types if specified.",
|
||||
"@param {" + fullName + "} message " + type.name,
|
||||
"@param {$protobuf.ConversionOptions} [options] Conversion options",
|
||||
"@returns {Object.<string,*>} Plain object"
|
||||
]);
|
||||
buildFunction(type, "toObject", protobuf.converter.toObject(type), {
|
||||
util : "$protobuf.util",
|
||||
types : hasTypes ? "$types" : undefined
|
||||
});
|
||||
|
||||
push("");
|
||||
pushComment([
|
||||
"Creates a plain object from this " + type.name + " message. Also converts values to other types if specified.",
|
||||
"@param {$protobuf.ConversionOptions} [options] Conversion options",
|
||||
"@returns {Object.<string,*>} Plain object"
|
||||
]);
|
||||
push("$prototype.toObject = function toObject(options) {");
|
||||
++indent;
|
||||
push("return this.convert(source, $protobuf.converters.message, options);");
|
||||
push("return this.constructor.toObject(this, options);");
|
||||
--indent;
|
||||
push("};");
|
||||
|
||||
push("");
|
||||
pushComment([
|
||||
"Converts this " + type.name + " message to JSON.",
|
||||
"@param {Object.<string,*>} [options] Conversion options",
|
||||
"Converts this " + type.name + " to JSON.",
|
||||
"@returns {Object.<string,*>} JSON object"
|
||||
]);
|
||||
push("$prototype.asJSON = function asJSON(options) {");
|
||||
push("$prototype.toJSON = function toJSON() {");
|
||||
++indent;
|
||||
push("return this.constructor.convert(this, $protobuf.converters.json, options);");
|
||||
push("return this.constructor.toObject(this, {");
|
||||
++indent;
|
||||
push("longs: String,");
|
||||
push("enums: String,");
|
||||
push("bytes: String");
|
||||
--indent;
|
||||
push("});");
|
||||
--indent;
|
||||
push("};");
|
||||
}
|
||||
|
||||
912
dist/noparse/protobuf.js
vendored
912
dist/noparse/protobuf.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/noparse/protobuf.js.map
vendored
2
dist/noparse/protobuf.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/noparse/protobuf.min.js
vendored
8
dist/noparse/protobuf.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/noparse/protobuf.min.js.gz
vendored
BIN
dist/noparse/protobuf.min.js.gz
vendored
Binary file not shown.
2
dist/noparse/protobuf.min.js.map
vendored
2
dist/noparse/protobuf.min.js.map
vendored
File diff suppressed because one or more lines are too long
944
dist/protobuf.js
vendored
944
dist/protobuf.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/protobuf.js.map
vendored
2
dist/protobuf.js.map
vendored
File diff suppressed because one or more lines are too long
8
dist/protobuf.min.js
vendored
8
dist/protobuf.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/protobuf.min.js.gz
vendored
BIN
dist/protobuf.min.js.gz
vendored
Binary file not shown.
2
dist/protobuf.min.js.map
vendored
2
dist/protobuf.min.js.map
vendored
File diff suppressed because one or more lines are too long
184
dist/runtime/protobuf.js
vendored
184
dist/runtime/protobuf.js
vendored
@ -1,6 +1,6 @@
|
||||
/*!
|
||||
* protobuf.js v6.4.6 (c) 2016, Daniel Wirtz
|
||||
* Compiled Wed, 11 Jan 2017 01:12:50 UTC
|
||||
* protobuf.js v6.5.0 (c) 2016, Daniel Wirtz
|
||||
* Compiled Thu, 12 Jan 2017 04:06:51 UTC
|
||||
* Licensed under the BSD-3-Clause License
|
||||
* see: https://github.com/dcodeIO/protobuf.js for details
|
||||
*/
|
||||
@ -219,7 +219,7 @@ var utf8 = exports;
|
||||
* @param {string} string String
|
||||
* @returns {number} Byte length
|
||||
*/
|
||||
utf8.length = function length(string) {
|
||||
utf8.length = function utf8_length(string) {
|
||||
var len = 0,
|
||||
c = 0;
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
@ -244,7 +244,7 @@ utf8.length = function length(string) {
|
||||
* @param {number} end Source end
|
||||
* @returns {string} String read
|
||||
*/
|
||||
utf8.read = function(buffer, start, end) {
|
||||
utf8.read = function utf8_read(buffer, start, end) {
|
||||
var len = end - start;
|
||||
if (len < 1)
|
||||
return "";
|
||||
@ -284,7 +284,7 @@ utf8.read = function(buffer, start, end) {
|
||||
* @param {number} offset Destination offset
|
||||
* @returns {number} Bytes written
|
||||
*/
|
||||
utf8.write = function(string, buffer, offset) {
|
||||
utf8.write = function utf8_write(string, buffer, offset) {
|
||||
var start = offset,
|
||||
c1, // character 1
|
||||
c2; // character 2
|
||||
@ -318,12 +318,11 @@ utf8.write = function(string, buffer, offset) {
|
||||
"use strict";
|
||||
var protobuf = global.protobuf = exports;
|
||||
|
||||
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.Writer = require(10);
|
||||
protobuf.BufferWriter = require(11);
|
||||
protobuf.Reader = require(6);
|
||||
protobuf.BufferReader = require(7);
|
||||
protobuf.util = require(9);
|
||||
protobuf.roots = {};
|
||||
protobuf.configure = configure;
|
||||
|
||||
@ -343,133 +342,11 @@ if (typeof define === "function" && define.amd)
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{"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) // inner messages
|
||||
return null;
|
||||
return options.fieldsOnly
|
||||
? {}
|
||||
: util.merge({}, value);
|
||||
},
|
||||
enums: function(value, defaultValue, values, options) {
|
||||
if (value === undefined)
|
||||
value = defaultValue;
|
||||
return options.enums === String && typeof value === "number"
|
||||
? values[value]
|
||||
: value;
|
||||
},
|
||||
longs: function(value, defaultLow, defaultHigh, unsigned, options) {
|
||||
if (value === undefined || value === null)
|
||||
value = { low: defaultLow, high: defaultHigh };
|
||||
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) {
|
||||
value = defaultValue;
|
||||
} 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;
|
||||
},
|
||||
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){
|
||||
},{"10":10,"11":11,"6":6,"7":7,"9":9}],6:[function(require,module,exports){
|
||||
"use strict";
|
||||
module.exports = Reader;
|
||||
|
||||
var util = require(10);
|
||||
var util = require(9);
|
||||
|
||||
var BufferReader; // cyclic
|
||||
|
||||
@ -517,7 +394,7 @@ function Reader(buffer) {
|
||||
Reader.create = util.Buffer
|
||||
? function create_buffer_setup(buffer) {
|
||||
if (!BufferReader)
|
||||
BufferReader = require(8);
|
||||
BufferReader = require(7);
|
||||
return (Reader.create = function create_buffer(buffer) {
|
||||
return util.Buffer.isBuffer(buffer)
|
||||
? new BufferReader(buffer)
|
||||
@ -983,17 +860,17 @@ Reader._configure = configure;
|
||||
|
||||
configure();
|
||||
|
||||
},{"10":10,"8":8}],8:[function(require,module,exports){
|
||||
},{"7":7,"9":9}],7:[function(require,module,exports){
|
||||
"use strict";
|
||||
module.exports = BufferReader;
|
||||
|
||||
// extends Reader
|
||||
var Reader = require(7);
|
||||
var Reader = require(6);
|
||||
/** @alias BufferReader.prototype */
|
||||
var BufferReaderPrototype = BufferReader.prototype = Object.create(Reader.prototype);
|
||||
BufferReaderPrototype.constructor = BufferReader;
|
||||
|
||||
var util = require(10);
|
||||
var util = require(9);
|
||||
|
||||
/**
|
||||
* Constructs a new buffer reader instance.
|
||||
@ -1017,12 +894,12 @@ BufferReaderPrototype.string = function read_string_buffer() {
|
||||
return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
|
||||
};
|
||||
|
||||
},{"10":10,"7":7}],9:[function(require,module,exports){
|
||||
},{"6":6,"9":9}],8:[function(require,module,exports){
|
||||
"use strict";
|
||||
|
||||
module.exports = LongBits;
|
||||
|
||||
var util = require(10);
|
||||
var util = require(9);
|
||||
|
||||
/**
|
||||
* Any compatible Long instance.
|
||||
@ -1229,7 +1106,7 @@ LongBitsPrototype.length = function length() {
|
||||
: part2 < 128 ? 9 : 10;
|
||||
};
|
||||
|
||||
},{"10":10}],10:[function(require,module,exports){
|
||||
},{"9":9}],9:[function(require,module,exports){
|
||||
(function (global){
|
||||
"use strict";
|
||||
|
||||
@ -1353,7 +1230,7 @@ util.arrayNe = function arrayNe(a, b) {
|
||||
return false;
|
||||
};
|
||||
|
||||
util.LongBits = require(9);
|
||||
util.LongBits = require(8);
|
||||
|
||||
/**
|
||||
* Long.js's Long class if available.
|
||||
@ -1416,11 +1293,11 @@ util.merge = function merge(dst, src, ifNotSet) { // used by converters
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{"1":1,"2":2,"3":3,"4":4,"9":9}],11:[function(require,module,exports){
|
||||
},{"1":1,"2":2,"3":3,"4":4,"8":8}],10:[function(require,module,exports){
|
||||
"use strict";
|
||||
module.exports = Writer;
|
||||
|
||||
var util = require(10);
|
||||
var util = require(9);
|
||||
|
||||
var BufferWriter; // cyclic
|
||||
|
||||
@ -1551,7 +1428,7 @@ function Writer() {
|
||||
Writer.create = util.Buffer
|
||||
? function create_buffer_setup() {
|
||||
if (!BufferWriter)
|
||||
BufferWriter = require(12);
|
||||
BufferWriter = require(11);
|
||||
return (Writer.create = function create_buffer() {
|
||||
return new BufferWriter();
|
||||
})();
|
||||
@ -1864,7 +1741,7 @@ WriterPrototype.double = function write_double(value) {
|
||||
|
||||
var writeBytes = util.Array.prototype.set
|
||||
? function writeBytes_set(val, buf, pos) {
|
||||
buf.set(val, pos);
|
||||
buf.set(val, pos); // also works for plain array values
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
: function writeBytes_for(val, buf, pos) {
|
||||
@ -1964,17 +1841,17 @@ WriterPrototype.finish = function finish() {
|
||||
return buf;
|
||||
};
|
||||
|
||||
},{"10":10,"12":12}],12:[function(require,module,exports){
|
||||
},{"11":11,"9":9}],11:[function(require,module,exports){
|
||||
"use strict";
|
||||
module.exports = BufferWriter;
|
||||
|
||||
// extends Writer
|
||||
var Writer = require(11);
|
||||
var Writer = require(10);
|
||||
/** @alias BufferWriter.prototype */
|
||||
var BufferWriterPrototype = BufferWriter.prototype = Object.create(Writer.prototype);
|
||||
BufferWriterPrototype.constructor = BufferWriter;
|
||||
|
||||
var util = require(10);
|
||||
var util = require(9);
|
||||
|
||||
var Buffer = util.Buffer;
|
||||
|
||||
@ -2000,12 +1877,13 @@ BufferWriter.alloc = function alloc_buffer(size) {
|
||||
var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
|
||||
? function writeBytesBuffer_set(val, buf, pos) {
|
||||
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
||||
// also works for plain array values
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
: function writeBytesBuffer_copy(val, buf, pos) {
|
||||
if (val.copy)
|
||||
if (val.copy) // Buffer values
|
||||
val.copy(buf, pos, 0, val.length);
|
||||
else for (var i = 0; i < val.length;)
|
||||
else for (var i = 0; i < val.length;) // plain array values
|
||||
buf[pos++] = val[i++];
|
||||
};
|
||||
|
||||
@ -2040,7 +1918,7 @@ BufferWriterPrototype.string = function write_string_buffer(value) {
|
||||
return this;
|
||||
};
|
||||
|
||||
},{"10":10,"11":11}]},{},[5])
|
||||
},{"10":10,"9":9}]},{},[5])
|
||||
|
||||
|
||||
//# sourceMappingURL=protobuf.js.map
|
||||
|
||||
2
dist/runtime/protobuf.js.map
vendored
2
dist/runtime/protobuf.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/runtime/protobuf.min.js
vendored
6
dist/runtime/protobuf.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/runtime/protobuf.min.js.gz
vendored
BIN
dist/runtime/protobuf.min.js.gz
vendored
Binary file not shown.
2
dist/runtime/protobuf.min.js.map
vendored
2
dist/runtime/protobuf.min.js.map
vendored
File diff suppressed because one or more lines are too long
268
index.d.ts
vendored
268
index.d.ts
vendored
@ -26,14 +26,33 @@ export class Class {
|
||||
static create(type: Type, ctor?: any): Message;
|
||||
|
||||
/**
|
||||
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
|
||||
* @name Class#from
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @name Class#fromObject
|
||||
* @function
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Options
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
from(object: { [k: string]: any }, options?: MessageConversionOptions): Message;
|
||||
fromObject(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Class#fromObject}.
|
||||
* @name Class#from
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
from(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @name Class#toObject
|
||||
* @function
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
toObject(message: Message, options?: ConversionOptions): { [k: string]: any };
|
||||
|
||||
/**
|
||||
* Encodes a message of this type.
|
||||
@ -81,17 +100,6 @@ export class Class {
|
||||
* @returns {?string} `null` if valid, otherwise the reason why it is not
|
||||
*/
|
||||
verify(message: (Message|Object)): string;
|
||||
|
||||
/**
|
||||
* Converts an object or runtime message of this type.
|
||||
* @name Class#convert
|
||||
* @function
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,117 +117,6 @@ export class Class {
|
||||
*/
|
||||
export function common(name: string, json: { [k: string]: any }): void;
|
||||
|
||||
/**
|
||||
* 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 {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 ConverterCreate = (value: (Message|Object), typeOrCtor: () => any, options?: { [k: string]: any }) => (Message|Object);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
type ConverterEnums = (value: (number|string), defaultValue: number, values: { [k: string]: number }, options?: { [k: string]: any }) => (number|string);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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`
|
||||
*/
|
||||
|
||||
interface JSONConversionOptions {
|
||||
fieldsOnly?: boolean;
|
||||
longs?: any;
|
||||
enums?: any;
|
||||
bytes?: any;
|
||||
defaults?: boolean;
|
||||
arrays?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
interface MessageConversionOptions {
|
||||
fieldsOnly?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a decoder specific to the specified message type.
|
||||
* @param {Type} mtype Message type
|
||||
@ -629,21 +526,6 @@ export class Message {
|
||||
*/
|
||||
readonly $type: Type;
|
||||
|
||||
/**
|
||||
* Converts this message to a JSON object.
|
||||
* @param {JSONConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
asJSON(options?: JSONConversionOptions): { [k: string]: any };
|
||||
|
||||
/**
|
||||
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Options
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
static from(object: { [k: string]: any }, options?: MessageConversionOptions): Message;
|
||||
|
||||
/**
|
||||
* Encodes a message of this type.
|
||||
* @param {Message|Object} message Message to encode
|
||||
@ -688,13 +570,41 @@ export class Message {
|
||||
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
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
static convert(source: (Message|Object), impl: ConverterImpl, options?: { [k: string]: any }): (Message|Object);
|
||||
static fromObject(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Message.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
static from(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
static toObject(message: Message, options?: ConversionOptions): { [k: string]: any };
|
||||
|
||||
/**
|
||||
* Creates a plain object from this message. Also converts values to other types if specified.
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
toObject(options?: ConversionOptions): { [k: string]: any };
|
||||
|
||||
/**
|
||||
* Converts this message to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1700,14 +1610,6 @@ export class Type extends NamespaceBase {
|
||||
*/
|
||||
create(properties?: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a JSON object by converting strings and numbers to their respective field types.
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Conversion options
|
||||
* @returns {Message} Runtime message
|
||||
*/
|
||||
from(object: { [k: string]: any }, options?: MessageConversionOptions): Message;
|
||||
|
||||
/**
|
||||
* Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
|
||||
* @returns {Type} `this`
|
||||
@ -1753,13 +1655,55 @@ export class Type extends NamespaceBase {
|
||||
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
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
convert(source: (Message|Object), impl: ConverterImpl, options?: { [k: string]: any }): (Message|Object);
|
||||
fromObject(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Type#fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
from(object: { [k: string]: any }): Message;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
toObject(message: Message, options?: ConversionOptions): { [k: string]: any };
|
||||
}
|
||||
|
||||
/**
|
||||
* Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
|
||||
* @typedef ConversionOptions
|
||||
* @type {Object}
|
||||
* @property {*} [longs] Long conversion type.
|
||||
* Valid values are `String` and `Number` (the global types).
|
||||
* Defaults to copy the present value, which is a possibly unsafe number without and a Long with a long library.
|
||||
* @property {*} [enums] Enum value conversion type.
|
||||
* Only valid value is `String` (the global type).
|
||||
* Defaults to copy the present value, which is the numeric id.
|
||||
* @property {*} [bytes] Bytes value conversion type.
|
||||
* Valid values are `Array` and `String` (the global types).
|
||||
* Defaults to copy the present value, which usually is Buffer under node and an Uint8Array in the browser.
|
||||
* @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`
|
||||
* @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
|
||||
*/
|
||||
|
||||
interface ConversionOptions {
|
||||
longs?: any;
|
||||
enums?: any;
|
||||
bytes?: any;
|
||||
defaults?: boolean;
|
||||
arrays?: boolean;
|
||||
objects?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -20,20 +20,7 @@
|
||||
"outputSourceFiles" : false
|
||||
},
|
||||
"applicationName": "protobuf.js",
|
||||
"disqus": "",
|
||||
"googleAnalytics": "",
|
||||
"openGraph": {
|
||||
"title": "",
|
||||
"type": "website",
|
||||
"image": "",
|
||||
"site_name": "",
|
||||
"url": ""
|
||||
},
|
||||
"meta": {
|
||||
"title": "",
|
||||
"description": "",
|
||||
"keyword": ""
|
||||
},
|
||||
"googleAnalytics": "UA-40277577-3",
|
||||
"linenums" : true
|
||||
},
|
||||
"markdown" : {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "protobufjs",
|
||||
"version": "6.4.6",
|
||||
"version": "6.5.0",
|
||||
"description": "Protocol Buffers for JavaScript (& TypeScript).",
|
||||
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
||||
"license": "BSD-3-Clause",
|
||||
@ -44,7 +44,7 @@
|
||||
"dependencies": {
|
||||
"@protobufjs/aspromise": "^1.0.5",
|
||||
"@protobufjs/base64": "^1.0.5",
|
||||
"@protobufjs/codegen": "^1.0.5",
|
||||
"@protobufjs/codegen": "^1.0.6",
|
||||
"@protobufjs/eventemitter": "^1.0.5",
|
||||
"@protobufjs/extend": "^1.0.2",
|
||||
"@protobufjs/fetch": "^1.0.4",
|
||||
@ -63,7 +63,7 @@
|
||||
"browserify": "^13.3.0",
|
||||
"bundle-collapser": "^1.2.1",
|
||||
"chalk": "^1.1.3",
|
||||
"eslint": "^3.12.2",
|
||||
"eslint": "^3.13.1",
|
||||
"gh-pages": "^0.12.0",
|
||||
"git-raw-commits": "^1.1.2",
|
||||
"git-semver-tags": "^1.1.2",
|
||||
@ -72,7 +72,7 @@
|
||||
"gulp-gzip": "^1.4.0",
|
||||
"gulp-header": "^1.8.8",
|
||||
"gulp-if": "^2.0.1",
|
||||
"gulp-sourcemaps": "^1.6.0",
|
||||
"gulp-sourcemaps": "^2.3.1",
|
||||
"gulp-uglify": "^2.0.0",
|
||||
"jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc",
|
||||
"jsdoc": "^3.4.2",
|
||||
|
||||
@ -7,7 +7,6 @@ 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;
|
||||
|
||||
@ -8,7 +8,8 @@ var fs = require("fs"),
|
||||
"tests/data/rpc.proto",
|
||||
"tests/data/mapbox/vector_tile.proto",
|
||||
"tests/data/ambiguous-names.proto",
|
||||
"tests/data/test.proto"
|
||||
"tests/data/test.proto",
|
||||
"tests/data/convert.proto"
|
||||
]
|
||||
.forEach(function(file) {
|
||||
var out = file.replace(/\.proto$/, ".js");
|
||||
|
||||
33
src/class.js
33
src/class.js
@ -97,14 +97,31 @@ Class.create = create;
|
||||
Class.prototype = Message;
|
||||
|
||||
/**
|
||||
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @name Class#fromObject
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Class#fromObject}.
|
||||
* @name Class#from
|
||||
* @function
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Options
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @name Class#toObject
|
||||
* @function
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encodes a message of this type.
|
||||
* @name Class#encode
|
||||
@ -146,13 +163,3 @@ Class.prototype = Message;
|
||||
* @param {Message|Object} message Message or plain object to verify
|
||||
* @returns {?string} `null` if valid, otherwise the reason why it is not
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts an object or runtime message of this type.
|
||||
* @name Class#convert
|
||||
* @function
|
||||
* @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
|
||||
*/
|
||||
|
||||
353
src/converter.js
353
src/converter.js
@ -1,141 +1,242 @@
|
||||
"use strict";
|
||||
module.exports = converter;
|
||||
var converter = exports;
|
||||
|
||||
var Enum = require("./enum"),
|
||||
converters = require("./converters"),
|
||||
util = require("./util");
|
||||
var Enum = require("./enum"),
|
||||
util = require("./util");
|
||||
|
||||
var sprintf = util.codegen.sprintf;
|
||||
|
||||
function genConvert(field, fieldIndex, prop) {
|
||||
if (field.resolvedType)
|
||||
return field.resolvedType instanceof Enum
|
||||
// enums
|
||||
? sprintf("f.enums(s%s,%d,types[%d].values,o)", prop, field.typeDefault, fieldIndex)
|
||||
// recurse into messages
|
||||
: sprintf("types[%d].convert(s%s,f,o)", fieldIndex, prop);
|
||||
switch (field.type) {
|
||||
case "int64":
|
||||
case "uint64":
|
||||
case "sint64":
|
||||
case "fixed64":
|
||||
case "sfixed64":
|
||||
// longs
|
||||
return sprintf("f.longs(s%s,%d,%d,%j,o)", prop, field.typeDefault.low, field.typeDefault.high, field.type.charAt(0) === "u");
|
||||
case "bytes":
|
||||
// bytes
|
||||
return sprintf("f.bytes(s%s,%j,o)", prop, Array.prototype.slice.call(field.typeDefault));
|
||||
function genConvertValue_fromObject(gen, field, fieldIndex, prop) {
|
||||
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
if (field.resolvedType) {
|
||||
if (field.resolvedType instanceof Enum) {
|
||||
var values = field.resolvedType.values;
|
||||
gen
|
||||
("switch(d%s){", prop);
|
||||
Object.keys(values).forEach(function(key) {
|
||||
if (field.repeated && values[key] === field.typeDefault) gen
|
||||
("default:");
|
||||
gen
|
||||
("case%j:", key)
|
||||
("case %j:", values[key])
|
||||
("m%s=%j", prop, values[key])
|
||||
("break");
|
||||
});
|
||||
gen
|
||||
("}");
|
||||
} else gen
|
||||
("m%s=types[%d].fromObject(d%s)", prop, fieldIndex, prop);
|
||||
} else {
|
||||
var isUnsigned = false;
|
||||
switch (field.type) {
|
||||
case "double":
|
||||
case "float":gen
|
||||
("m%s=Number(d%s)", prop, prop);
|
||||
break;
|
||||
case "uint32":
|
||||
case "fixed32": gen
|
||||
("m%s=d%s>>>0", prop, prop);
|
||||
break;
|
||||
case "int32":
|
||||
case "sint32":
|
||||
case "sfixed32": gen
|
||||
("m%s=d%s|0", prop, prop);
|
||||
break;
|
||||
case "uint64":
|
||||
isUnsigned = true;
|
||||
// eslint-disable-line no-fallthrough
|
||||
case "int64":
|
||||
case "sint64":
|
||||
case "fixed64":
|
||||
case "sfixed64": gen
|
||||
("if(util.Long)")
|
||||
("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned)
|
||||
("else if(typeof d%s===\"string\")", prop)
|
||||
("m%s=parseInt(d%s,10)", prop, prop)
|
||||
("else if(typeof d%s===\"number\")", prop)
|
||||
("m%s=d%s", prop, prop)
|
||||
("else if(typeof d%s===\"object\")", prop)
|
||||
("m%s=new util.LongBits(d%s.low,d%s.high).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
|
||||
break;
|
||||
case "bytes": gen
|
||||
("if(typeof d%s===\"string\")", prop)
|
||||
("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop, prop)
|
||||
("else if(d%s&&d%s.length)", prop, prop)
|
||||
("m%s=d%s", prop, prop);
|
||||
break;
|
||||
case "string": gen
|
||||
("m%s=String(d%s)", prop, prop);
|
||||
break;
|
||||
case "bool": gen
|
||||
("m%s=Boolean(d%s)", prop, prop);
|
||||
break;
|
||||
default: gen /* bool, uint32, string etc. */
|
||||
("m%s=d%s", prop, prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
converter.fromObject = function fromObject(mtype) {
|
||||
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
var fields = mtype.fieldsArray;
|
||||
var gen = util.codegen("s", "f", "o")
|
||||
var gen = util.codegen("d")
|
||||
("var m=new(this.ctor)");
|
||||
for (var i = 0; i < fields.length; ++i) {
|
||||
var field = fields[i].resolve(),
|
||||
prop = field._prop;
|
||||
|
||||
// Map fields
|
||||
if (field.map) { gen
|
||||
("if(d%s){", prop, prop)
|
||||
("m%s={}", prop)
|
||||
("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
|
||||
genConvertValue_fromObject(gen, field, i, prop + "[ks[i]]");
|
||||
gen
|
||||
("}")
|
||||
("}");
|
||||
|
||||
// Repeated fields
|
||||
} else if (field.repeated) { gen
|
||||
("if(d%s){", prop)
|
||||
("m%s=[]", prop)
|
||||
("for(var i=0;i<d%s.length;++i){", prop);
|
||||
genConvertValue_fromObject(gen, field, i, prop + "[i]");
|
||||
gen
|
||||
("}")
|
||||
("}");
|
||||
|
||||
// Non-repeated fields
|
||||
} else {
|
||||
if (field.resolvedType instanceof Enum) gen // no need to test for null/undefined if an enum (uses switch)
|
||||
("if(d%s!==undefined&&d%s!==null){", prop, prop);
|
||||
genConvertValue_fromObject(gen, field, i, prop);
|
||||
if (field.resolvedType instanceof Enum) gen
|
||||
("}");
|
||||
}
|
||||
}
|
||||
return gen
|
||||
("return m");
|
||||
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
};
|
||||
|
||||
function genConvertValue_toObject(gen, field, fieldIndex, prop) {
|
||||
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
if (field.resolvedType) {
|
||||
if (field.resolvedType instanceof Enum) gen
|
||||
("d%s=o.enums===String?types[%d].values[m%s]:m%s", prop, fieldIndex, prop, prop);
|
||||
else gen
|
||||
("d%s=types[%d].ctor.prototype.toObject.call(m%s,o)", prop, fieldIndex, prop);
|
||||
} else {
|
||||
var isUnsigned = false;
|
||||
switch (field.type) {
|
||||
case "uint64":
|
||||
isUnsigned = true;
|
||||
// eslint-disable-line no-fallthrough
|
||||
case "int64":
|
||||
case "sint64":
|
||||
case "fixed64":
|
||||
case "sfixed64": gen
|
||||
("if(typeof m%s===\"number\")", prop)
|
||||
("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
|
||||
("else") // Long-like
|
||||
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low,m%s.high).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
|
||||
break;
|
||||
case "bytes": gen
|
||||
("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", prop, prop, prop, prop, prop);
|
||||
break;
|
||||
default: gen
|
||||
("d%s=m%s", prop, prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
}
|
||||
|
||||
converter.toObject = function toObject(mtype) {
|
||||
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
var fields = mtype.fieldsArray;
|
||||
var gen = util.codegen("m", "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 = field.resolve()._prop;
|
||||
|
||||
// repeated
|
||||
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);
|
||||
|
||||
// non-repeated
|
||||
} else if (convert = genConvert(field, i, prop)) {
|
||||
if (field.long) gen
|
||||
("if(o.defaults||s%s!==undefined&&s%s!==null&&util.longNe(s%s,%d,%d))", prop, prop, prop, field.typeDefault.low, field.typeDefault.high);
|
||||
else if (field.resolvedType && !(field.resolvedType instanceof Enum)) gen
|
||||
("if(o.defaults||s%s!==undefined&&s%s!==null)", prop, prop);
|
||||
else gen
|
||||
("if(o.defaults||s%s!==undefined&&s%s!==%j)", prop, prop, field.typeDefault);
|
||||
gen
|
||||
("d%s=%s", prop, convert);
|
||||
} else gen
|
||||
("if(d%s===undefined&&o.defaults)", prop)
|
||||
("d%s=%j", prop, field.typeDefault /* == field.defaultValue */);
|
||||
|
||||
("var d={}");
|
||||
var repeatedFields = fields.filter(function(field) { return field.repeated; });
|
||||
if (repeatedFields.length) { gen
|
||||
("if(o.arrays||o.defaults){");
|
||||
fields.forEach(function(field) {
|
||||
if (field.resolve().repeated) gen
|
||||
("d%s=[]", field._prop);
|
||||
});
|
||||
gen
|
||||
("}");
|
||||
}
|
||||
var mapFields = fields.filter(function(field) { return field.map; });
|
||||
if (mapFields.length) { gen
|
||||
("if(o.objects||o.defaults){");
|
||||
fields.forEach(function(field) {
|
||||
if (field.map) gen
|
||||
("d%s={}", field._prop);
|
||||
});
|
||||
gen
|
||||
("}");
|
||||
}
|
||||
var otherFields = fields.filter(function(field) { return !(field.repeated || field.map); });
|
||||
if (otherFields.length) { gen
|
||||
("if(o.defaults){");
|
||||
fields.forEach(function(field) {
|
||||
if (field.repeated || field.map)
|
||||
return;
|
||||
if (field.resolvedType instanceof Enum) gen
|
||||
("d%s=o.enums===String?%j:%j", field._prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
|
||||
else if (field.long) gen
|
||||
("if(util.Long){")
|
||||
("var n=new util.Long(%d,%d,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
|
||||
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", field._prop)
|
||||
("}else")
|
||||
("d%s=o.longs===String?%j:%d", field._prop, field.typeDefault.toString(), field.typeDefault.toNumber());
|
||||
else if (field.bytes) gen
|
||||
("d%s=o.bytes===String?%j:%s", field._prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
|
||||
else gen
|
||||
("d%s=%j", field._prop, field.typeDefault); // also messages (=null)
|
||||
});
|
||||
gen
|
||||
("}");
|
||||
}
|
||||
gen
|
||||
("for(var ks=Object.keys(m),i=0;i<ks.length;++i){")
|
||||
("switch(ks[i]){");
|
||||
for (var i = 0; i < fields.length; ++i) {
|
||||
var field = fields[i],
|
||||
prop = field._prop;
|
||||
gen
|
||||
("case%j:", field.name);
|
||||
if (field.map) { gen
|
||||
("if(m%s&&m%s!==util.emptyObject){", prop, prop)
|
||||
("d%s={}", prop)
|
||||
("for(var ks2=Object.keys(m%s),j=0;j<ks2.length;++j){", prop);
|
||||
genConvertValue_toObject(gen, field, i, prop + "[ks2[j]]");
|
||||
gen
|
||||
("}")
|
||||
("}");
|
||||
} else if (field.repeated) { gen
|
||||
("if(m%s.length){", prop)
|
||||
("d%s=[]", prop)
|
||||
("for(var j=0;j<m%s.length;++j){", prop);
|
||||
genConvertValue_toObject(gen, field, i, prop + "[j]");
|
||||
gen
|
||||
("}")
|
||||
("}");
|
||||
} else { gen
|
||||
("if(m%s!==undefined&&m%s!==null){", prop, prop);
|
||||
genConvertValue_toObject(gen, field, i, prop);
|
||||
gen
|
||||
("}");
|
||||
}
|
||||
gen
|
||||
("break");
|
||||
}
|
||||
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
|
||||
*/
|
||||
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
||||
};
|
||||
|
||||
@ -1,120 +0,0 @@
|
||||
"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) // inner messages
|
||||
return null;
|
||||
return options.fieldsOnly
|
||||
? {}
|
||||
: util.merge({}, value);
|
||||
},
|
||||
enums: function(value, defaultValue, values, options) {
|
||||
if (value === undefined)
|
||||
value = defaultValue;
|
||||
return options.enums === String && typeof value === "number"
|
||||
? values[value]
|
||||
: value;
|
||||
},
|
||||
longs: function(value, defaultLow, defaultHigh, unsigned, options) {
|
||||
if (value === undefined || value === null)
|
||||
value = { low: defaultLow, high: defaultHigh };
|
||||
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) {
|
||||
value = defaultValue;
|
||||
} 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;
|
||||
},
|
||||
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);
|
||||
}
|
||||
};
|
||||
@ -1,8 +1,6 @@
|
||||
"use strict";
|
||||
module.exports = Message;
|
||||
|
||||
var converters = require("./converters");
|
||||
|
||||
/**
|
||||
* Constructs a new message instance.
|
||||
*
|
||||
@ -27,9 +25,6 @@ function Message(properties) {
|
||||
* @readonly
|
||||
*/
|
||||
|
||||
/** @alias Message.prototype */
|
||||
var MessagePrototype = Message.prototype;
|
||||
|
||||
/**
|
||||
* Reference to the reflected type.
|
||||
* @name Message#$type
|
||||
@ -37,25 +32,6 @@ var MessagePrototype = Message.prototype;
|
||||
* @readonly
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts this message to a JSON object.
|
||||
* @param {JSONConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
MessagePrototype.asJSON = function asJSON(options) {
|
||||
return this.$type.convert(this, converters.json, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a message from a JSON object by converting strings and numbers to their respective field types.
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Options
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
Message.from = function from(object, options) {
|
||||
return this.$type.convert(object, converters.message, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes a message of this type.
|
||||
* @param {Message|Object} message Message to encode
|
||||
@ -110,12 +86,50 @@ Message.verify = function 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
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
Message.convert = function convert(source, impl, options) {
|
||||
return this.$type.convert(source, impl, options);
|
||||
Message.fromObject = function fromObject(object) {
|
||||
return this.$type.fromObject(object);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Message.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
Message.from = Message.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Message.toObject = function toObject(message, options) {
|
||||
return this.$type.toObject(message, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a plain object from this message. Also converts values to other types if specified.
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Message.prototype.toObject = function toObject(options) {
|
||||
return this.$type.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this message to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
Message.prototype.toJSON = function toJSON() {
|
||||
return this.$type.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
65
src/type.js
65
src/type.js
@ -319,16 +319,6 @@ TypePrototype.create = function create(properties) {
|
||||
return new this.ctor(properties);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a JSON object by converting strings and numbers to their respective field types.
|
||||
* @param {Object.<string,*>} object JSON object
|
||||
* @param {MessageConversionOptions} [options] Conversion options
|
||||
* @returns {Message} Runtime message
|
||||
*/
|
||||
TypePrototype.from = function from(object, options) {
|
||||
return this.convert(object, converter.message, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
|
||||
* @returns {Type} `this`
|
||||
@ -352,7 +342,11 @@ TypePrototype.setup = function setup() {
|
||||
types : types,
|
||||
util : util
|
||||
});
|
||||
this.convert = converter(this).eof(fullName + "$convert", {
|
||||
this.fromObject = this.from = converter.fromObject(this).eof(fullName + "$fromObject", {
|
||||
types : types,
|
||||
util : util
|
||||
});
|
||||
this.toObject = converter.toObject(this).eof(fullName + "$toObject", {
|
||||
types : types,
|
||||
util : util
|
||||
});
|
||||
@ -409,12 +403,47 @@ TypePrototype.verify = function verify_setup(message) {
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
TypePrototype.convert = function convert_setup(source, impl, options) {
|
||||
return this.setup().convert(source, impl, options); // overrides this method
|
||||
TypePrototype.fromObject = function fromObject(object) {
|
||||
return this.setup().fromObject(object);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Type#fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
TypePrototype.from = TypePrototype.fromObject;
|
||||
|
||||
/**
|
||||
* Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
|
||||
* @typedef ConversionOptions
|
||||
* @type {Object}
|
||||
* @property {*} [longs] Long conversion type.
|
||||
* Valid values are `String` and `Number` (the global types).
|
||||
* Defaults to copy the present value, which is a possibly unsafe number without and a Long with a long library.
|
||||
* @property {*} [enums] Enum value conversion type.
|
||||
* Only valid value is `String` (the global type).
|
||||
* Defaults to copy the present value, which is the numeric id.
|
||||
* @property {*} [bytes] Bytes value conversion type.
|
||||
* Valid values are `Array` and `String` (the global types).
|
||||
* Defaults to copy the present value, which usually is Buffer under node and an Uint8Array in the browser.
|
||||
* @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`
|
||||
* @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a plain object from a message of this type. Also converts values to other types if specified.
|
||||
* @param {Message} message Message instance
|
||||
* @param {ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
TypePrototype.toObject = function toObject(message, options) {
|
||||
return this.setup().toObject(message, options);
|
||||
};
|
||||
|
||||
@ -126,6 +126,8 @@ function sprintf(format) {
|
||||
switch ($1) {
|
||||
case "j":
|
||||
return JSON.stringify(arg);
|
||||
case "d":
|
||||
return Number(arg);
|
||||
default:
|
||||
return String(arg);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@protobufjs/codegen",
|
||||
"description": "A closure for generating functions programmatically.",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@ -445,7 +445,7 @@ WriterPrototype.double = function write_double(value) {
|
||||
|
||||
var writeBytes = util.Array.prototype.set
|
||||
? function writeBytes_set(val, buf, pos) {
|
||||
buf.set(val, pos);
|
||||
buf.set(val, pos); // also works for plain array values
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
: function writeBytes_for(val, buf, pos) {
|
||||
|
||||
@ -33,12 +33,13 @@ BufferWriter.alloc = function alloc_buffer(size) {
|
||||
var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
|
||||
? function writeBytesBuffer_set(val, buf, pos) {
|
||||
buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
|
||||
// also works for plain array values
|
||||
}
|
||||
/* istanbul ignore next */
|
||||
: function writeBytesBuffer_copy(val, buf, pos) {
|
||||
if (val.copy)
|
||||
if (val.copy) // Buffer values
|
||||
val.copy(buf, pos, 0, val.length);
|
||||
else for (var i = 0; i < val.length;)
|
||||
else for (var i = 0; i < val.length;) // plain array values
|
||||
buf[pos++] = val[i++];
|
||||
};
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ tape.test("bench.proto and bench.json", function(test) {
|
||||
var decoded = Test.decode(Test.encode(data).finish());
|
||||
test.deepEqual(decoded, data, "should reproduce the original data when encoded and decoded again");
|
||||
|
||||
test.deepEqual(decoded.asJSON(), data, "should reproduce the original data asJSON");
|
||||
test.deepEqual(decoded.toObject(), data, "should convert back to the original object");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
@ -10,10 +10,10 @@ tape.test("convert", function(test) {
|
||||
|
||||
var Message = root.lookup("Message");
|
||||
|
||||
test.test("Message#asJSON", function(test) {
|
||||
test.test("Message#toObject", function(test) {
|
||||
|
||||
test.test("called with defaults = true", function(test) {
|
||||
var obj = Message.create().asJSON({ defaults: true });
|
||||
var obj = Message.create().toObject({ defaults: true });
|
||||
|
||||
test.equal(obj.stringVal, "", "should set stringVal");
|
||||
test.same(obj.stringRepeated, [], "should set stringRepeated");
|
||||
@ -27,11 +27,13 @@ tape.test("convert", function(test) {
|
||||
test.equal(obj.enumVal, 1, "should set enumVal to the first defined value");
|
||||
test.same(obj.enumRepeated, [], "should set enumRepeated");
|
||||
|
||||
test.same(obj.int64Map, {}, "should set int64Map");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
test.test("called with defaults = undefined", function(test) {
|
||||
var obj = Message.create().asJSON();
|
||||
var obj = Message.create().toObject();
|
||||
|
||||
test.equal(obj.stringVal, undefined, "should not set stringVal");
|
||||
test.equal(obj.stringRepeated, undefined, "should not set stringRepeated");
|
||||
@ -45,11 +47,13 @@ tape.test("convert", function(test) {
|
||||
test.equal(obj.enumVal, undefined, "should not set enumVal");
|
||||
test.equal(obj.enumRepeated, undefined, "should not set enumRepeated");
|
||||
|
||||
test.equal(obj.int64Map, undefined, "should not set int64 map");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
test.test("called with arrays = true", function(test) {
|
||||
var obj = Message.create().asJSON({ arrays: true });
|
||||
var obj = Message.create().toObject({ arrays: true });
|
||||
|
||||
test.equal(obj.stringVal, undefined, "should not set stringVal");
|
||||
test.same(obj.stringRepeated, [], "should set stringRepeated");
|
||||
@ -63,6 +67,28 @@ tape.test("convert", function(test) {
|
||||
test.equal(obj.enumVal, undefined, "should not set enumVal");
|
||||
test.same(obj.enumRepeated, [], "should set enumRepeated");
|
||||
|
||||
test.equal(obj.int64Map, undefined, "should not set int64Map");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
test.test("called with objects = true", function(test) {
|
||||
var obj = Message.create().toObject({ objects: true });
|
||||
|
||||
test.equal(obj.stringVal, undefined, "should not set stringVal");
|
||||
test.equal(obj.stringRepeated, undefined, "should not set stringRepeated");
|
||||
|
||||
test.equal(obj.uint64Val, undefined, "should not set uint64Val");
|
||||
test.same(obj.uint64Repeated, undefined, "should not set uint64Repeated");
|
||||
|
||||
test.equal(obj.bytesVal, undefined, "should not set bytesVal");
|
||||
test.same(obj.bytesRepeated, undefined, "should not set bytesRepeated");
|
||||
|
||||
test.equal(obj.enumVal, undefined, "should not set enumVal");
|
||||
test.same(obj.enumRepeated, undefined, "should not set enumRepeated");
|
||||
|
||||
test.same(obj.int64Map, {}, "should set int64Map");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
@ -75,18 +101,27 @@ tape.test("convert", function(test) {
|
||||
bytesVal: buf,
|
||||
bytesRepeated: [buf, buf],
|
||||
enumVal: 2,
|
||||
enumRepeated: [1, 2]
|
||||
enumRepeated: [1, 2],
|
||||
int64Map: {
|
||||
a: protobuf.util.Long.fromNumber(2),
|
||||
b: protobuf.util.Long.fromNumber(3)
|
||||
}
|
||||
});
|
||||
|
||||
test.equal(msg.asJSON({ longs: Number }).uint64Val, 1, "longs to numbers");
|
||||
test.equal(msg.asJSON({ longs: String }).uint64Val, "1", "longs to strings");
|
||||
var msgLongsToNumber = msg.toObject({ longs: Number }),
|
||||
msgLongsToString = msg.toObject({ longs: String });
|
||||
|
||||
test.equal(Object.prototype.toString.call(msg.asJSON({ bytes: Array }).bytesVal), "[object Array]", "bytes to arrays");
|
||||
test.equal(msg.asJSON({ bytes: String }).bytesVal, "MTEx", "bytes to base64 strings");
|
||||
test.equal(msgLongsToNumber.uint64Val, 1, "longs to numbers");
|
||||
test.equal(msgLongsToString.uint64Val, "1", "longs to strings");
|
||||
test.same(msgLongsToNumber.int64Map, { a: 2, b: 3}, "long map values to numbers");
|
||||
test.same(msgLongsToString.int64Map, { a: "2", b: "3"}, "long map values to strings");
|
||||
|
||||
test.equal(Object.prototype.toString.call(msg.toObject({ bytes: Array }).bytesVal), "[object Array]", "bytes to arrays");
|
||||
test.equal(msg.toObject({ bytes: String }).bytesVal, "MTEx", "bytes to base64 strings");
|
||||
if (protobuf.util.isNode)
|
||||
test.ok(Buffer.isBuffer(msg.asJSON({ bytes: Buffer }).bytesVal), "bytes to buffers");
|
||||
test.ok(Buffer.isBuffer(msg.toObject({ bytes: Buffer }).bytesVal), "bytes to buffers");
|
||||
|
||||
test.equal(msg.asJSON({ enums: String }).enumVal, "TWO", "enums to strings");
|
||||
test.equal(msg.toObject({ enums: String }).enumVal, "TWO", "enums to strings");
|
||||
|
||||
test.end();
|
||||
});
|
||||
@ -94,15 +129,19 @@ tape.test("convert", function(test) {
|
||||
test.end();
|
||||
});
|
||||
|
||||
test.test("Message.from", function(test) {
|
||||
test.test("Message.fromObject", function(test) {
|
||||
|
||||
var msg = Message.from({
|
||||
var msg = Message.fromObject({
|
||||
uint64Val: 1,
|
||||
uint64Repeated: [1, "2"],
|
||||
bytesVal: "MTEx",
|
||||
bytesRepeated: ["MTEx", [49, 49, 49]],
|
||||
enumVal: "ONE",
|
||||
enumRepeated: [2, "TWO"]
|
||||
enumRepeated: [2, "TWO"],
|
||||
int64Map: {
|
||||
a: 2,
|
||||
b: "3"
|
||||
}
|
||||
});
|
||||
var buf = protobuf.util.newBuffer(3);
|
||||
buf[0] = buf[1] = buf[2] = 49; // "111"
|
||||
@ -113,6 +152,7 @@ tape.test("convert", function(test) {
|
||||
test.same(msg.bytesRepeated, [ buf, buf ], "should set bytesRepeated from a base64 string and a plain array");
|
||||
test.equal(msg.enumVal, 1, "should set enumVal from a string");
|
||||
test.same(msg.enumRepeated, [ 2, 2 ], "should set enumRepeated from a number and a string");
|
||||
test.same(msg.int64Map, { a: { low: 2, high: 0, unsigned: false }, b: { low: 3, high: 0, unsigned: false } }, "should set int64Map from a number and a string");
|
||||
|
||||
test.end();
|
||||
});
|
||||
|
||||
@ -123,43 +123,70 @@ $root.A = (function() {
|
||||
};})($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
|
||||
* Creates a A message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {A} A
|
||||
*/
|
||||
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;
|
||||
A.fromObject = (function() { return function fromObject(object) {
|
||||
var message = new $root.A();
|
||||
message.whatever = String(object.whatever);
|
||||
return message;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a A message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a A message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link A.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {A} A
|
||||
*/
|
||||
A.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
A.from = A.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a A message. Also converts values to other types if specified.
|
||||
* @param {A} message A
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
A.toObject = (function() { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.whatever = "";
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "whatever":
|
||||
if (message.whatever !== undefined && message.whatever !== null) {
|
||||
object.whatever = message.whatever;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a plain object from this A message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this A message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this A to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return A;
|
||||
@ -283,43 +310,70 @@ $root.B = (function() {
|
||||
};})($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
|
||||
* Creates a B message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {B} B
|
||||
*/
|
||||
B.convert = (function(types) { return function convert(src, impl, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var dst = impl.create(src, this, options);
|
||||
if (dst) {
|
||||
if (options.defaults || src.A !== undefined && src.A !== null) {
|
||||
dst.A = types[0].convert(src.A, impl, options);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
B.fromObject = (function(types) { return function fromObject(object) {
|
||||
var message = new $root.B();
|
||||
message.A = types[0].fromObject(object.A);
|
||||
return message;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a B message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a B message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link B.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {B} B
|
||||
*/
|
||||
B.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
B.from = B.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a B message. Also converts values to other types if specified.
|
||||
* @param {B} message B
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
B.toObject = (function(types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.A = null;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "A":
|
||||
if (message.A !== undefined && message.A !== null) {
|
||||
object.A = types[0].ctor.prototype.toObject.call(message.A, options);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this B message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this B message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this B to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return B;
|
||||
|
||||
657
tests/data/convert.js
Normal file
657
tests/data/convert.js
Normal file
@ -0,0 +1,657 @@
|
||||
/*eslint-disable block-scoped-var, no-redeclare, no-control-regex*/
|
||||
"use strict";
|
||||
|
||||
var $protobuf = require("../../runtime");
|
||||
|
||||
// Lazily resolved type references
|
||||
var $lazyTypes = [];
|
||||
|
||||
// Exported root namespace
|
||||
var $root = {};
|
||||
|
||||
$root.Message = (function() {
|
||||
|
||||
/**
|
||||
* Constructs a new Message.
|
||||
* @exports Message
|
||||
* @constructor
|
||||
* @param {Object} [properties] Properties to set
|
||||
*/
|
||||
function Message(properties) {
|
||||
if (properties) {
|
||||
var keys = Object.keys(properties);
|
||||
for (var i = 0; i < keys.length; ++i)
|
||||
this[keys[i]] = properties[keys[i]];
|
||||
}
|
||||
}
|
||||
|
||||
/** @alias Message.prototype */
|
||||
var $prototype = Message.prototype;
|
||||
|
||||
/**
|
||||
* Message stringVal.
|
||||
* @type {string}
|
||||
*/
|
||||
$prototype.stringVal = "";
|
||||
|
||||
/**
|
||||
* Message stringRepeated.
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
$prototype.stringRepeated = $protobuf.util.emptyArray;
|
||||
|
||||
/**
|
||||
* Message uint64Val.
|
||||
* @type {number|$protobuf.Long}
|
||||
*/
|
||||
$prototype.uint64Val = $protobuf.util.Long ? $protobuf.util.Long.fromBits(0,0,true) : 0;
|
||||
|
||||
/**
|
||||
* Message uint64Repeated.
|
||||
* @type {Array.<number|$protobuf.Long>}
|
||||
*/
|
||||
$prototype.uint64Repeated = $protobuf.util.emptyArray;
|
||||
|
||||
/**
|
||||
* Message bytesVal.
|
||||
* @type {Uint8Array}
|
||||
*/
|
||||
$prototype.bytesVal = $protobuf.util.newBuffer([]);
|
||||
|
||||
/**
|
||||
* Message bytesRepeated.
|
||||
* @type {Array.<Uint8Array>}
|
||||
*/
|
||||
$prototype.bytesRepeated = $protobuf.util.emptyArray;
|
||||
|
||||
/**
|
||||
* Message enumVal.
|
||||
* @type {number}
|
||||
*/
|
||||
$prototype.enumVal = 1;
|
||||
|
||||
/**
|
||||
* Message enumRepeated.
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
$prototype.enumRepeated = $protobuf.util.emptyArray;
|
||||
|
||||
/**
|
||||
* Message int64Map.
|
||||
* @type {Object.<string,number|$protobuf.Long>}
|
||||
*/
|
||||
$prototype.int64Map = $protobuf.util.emptyObject;
|
||||
|
||||
// Referenced types
|
||||
var $types = [null, null, null, null, null, null, "Message.SomeEnum", "Message.SomeEnum", null]; $lazyTypes.push($types);
|
||||
|
||||
/**
|
||||
* Creates a new Message instance using the specified properties.
|
||||
* @param {Object} [properties] Properties to set
|
||||
* @returns {Message} Message instance
|
||||
*/
|
||||
Message.create = function create(properties) {
|
||||
return new Message(properties);
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes the specified Message message.
|
||||
* @function
|
||||
* @param {Message|Object} message Message message or plain object to encode
|
||||
* @param {$protobuf.Writer} [writer] Writer to encode to
|
||||
* @returns {$protobuf.Writer} Writer
|
||||
*/
|
||||
Message.encode = (function(Writer, util) { return function encode(message, writer) {
|
||||
if (!writer) {
|
||||
writer = Writer.create();
|
||||
}
|
||||
if (message.stringVal !== undefined && message.stringVal !== "") {
|
||||
writer.uint32(10).string(message.stringVal);
|
||||
}
|
||||
if (message.stringRepeated) {
|
||||
for (var i = 0; i < message.stringRepeated.length; ++i) {
|
||||
writer.uint32(18).string(message.stringRepeated[i]);
|
||||
}
|
||||
}
|
||||
if (message.uint64Val !== undefined && message.uint64Val !== null && util.longNe(message.uint64Val, 0, 0)) {
|
||||
writer.uint32(24).uint64(message.uint64Val);
|
||||
}
|
||||
if (message.uint64Repeated && message.uint64Repeated.length) {
|
||||
writer.uint32(34).fork();
|
||||
for (var i = 0; i < message.uint64Repeated.length; ++i) {
|
||||
writer.uint64(message.uint64Repeated[i]);
|
||||
}
|
||||
writer.ldelim();
|
||||
}
|
||||
if (message.bytesVal && message.bytesVal.length) {
|
||||
writer.uint32(42).bytes(message.bytesVal);
|
||||
}
|
||||
if (message.bytesRepeated) {
|
||||
for (var i = 0; i < message.bytesRepeated.length; ++i) {
|
||||
writer.uint32(50).bytes(message.bytesRepeated[i]);
|
||||
}
|
||||
}
|
||||
if (message.enumVal !== undefined && message.enumVal !== 1) {
|
||||
writer.uint32(56).uint32(message.enumVal);
|
||||
}
|
||||
if (message.enumRepeated && message.enumRepeated.length) {
|
||||
writer.uint32(66).fork();
|
||||
for (var i = 0; i < message.enumRepeated.length; ++i) {
|
||||
writer.uint32(message.enumRepeated[i]);
|
||||
}
|
||||
writer.ldelim();
|
||||
}
|
||||
if (message.int64Map && message.int64Map !== util.emptyObject) {
|
||||
for (var keys = Object.keys(message.int64Map), i = 0; i < keys.length; ++i) {
|
||||
writer.uint32(74).fork().uint32(10).string(keys[i]).uint32(16).int64(message.int64Map[keys[i]]).ldelim();
|
||||
}
|
||||
}
|
||||
return writer;
|
||||
};})($protobuf.Writer, $protobuf.util);
|
||||
|
||||
/**
|
||||
* Encodes the specified Message message, length delimited.
|
||||
* @param {Message|Object} message Message message or plain object to encode
|
||||
* @param {$protobuf.Writer} [writer] Writer to encode to
|
||||
* @returns {$protobuf.Writer} Writer
|
||||
*/
|
||||
Message.encodeDelimited = function encodeDelimited(message, writer) {
|
||||
return this.encode(message, writer).ldelim();
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a Message 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 {Message} Message
|
||||
*/
|
||||
Message.decode = (function(Reader, util) { 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.Message();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
case 1:
|
||||
message.stringVal = reader.string();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (!(message.stringRepeated && message.stringRepeated.length)) {
|
||||
message.stringRepeated = [];
|
||||
}
|
||||
message.stringRepeated.push(reader.string());
|
||||
break;
|
||||
|
||||
case 3:
|
||||
message.uint64Val = reader.uint64();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (!(message.uint64Repeated && message.uint64Repeated.length)) {
|
||||
message.uint64Repeated = [];
|
||||
}
|
||||
if ((tag & 7) === 2) {
|
||||
var end2 = reader.uint32() + reader.pos;
|
||||
while (reader.pos < end2) {
|
||||
message.uint64Repeated.push(reader.uint64());
|
||||
}
|
||||
} else {
|
||||
message.uint64Repeated.push(reader.uint64());
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
message.bytesVal = reader.bytes();
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if (!(message.bytesRepeated && message.bytesRepeated.length)) {
|
||||
message.bytesRepeated = [];
|
||||
}
|
||||
message.bytesRepeated.push(reader.bytes());
|
||||
break;
|
||||
|
||||
case 7:
|
||||
message.enumVal = reader.uint32();
|
||||
break;
|
||||
|
||||
case 8:
|
||||
if (!(message.enumRepeated && message.enumRepeated.length)) {
|
||||
message.enumRepeated = [];
|
||||
}
|
||||
if ((tag & 7) === 2) {
|
||||
var end2 = reader.uint32() + reader.pos;
|
||||
while (reader.pos < end2) {
|
||||
message.enumRepeated.push(reader.uint32());
|
||||
}
|
||||
} else {
|
||||
message.enumRepeated.push(reader.uint32());
|
||||
}
|
||||
break;
|
||||
|
||||
case 9:
|
||||
reader.skip().pos++;
|
||||
if (message.int64Map === util.emptyObject) {
|
||||
message.int64Map = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
reader.pos++;
|
||||
message.int64Map[typeof key === "object" ? util.longToHash(key) : key] = reader.int64();
|
||||
break;
|
||||
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};})($protobuf.Reader, $protobuf.util);
|
||||
|
||||
/**
|
||||
* Decodes a Message message from the specified reader or buffer, length delimited.
|
||||
* @param {$protobuf.Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
|
||||
* @returns {Message} Message
|
||||
*/
|
||||
Message.decodeDelimited = function decodeDelimited(readerOrBuffer) {
|
||||
readerOrBuffer = readerOrBuffer instanceof $protobuf.Reader ? readerOrBuffer : $protobuf.Reader(readerOrBuffer);
|
||||
return this.decode(readerOrBuffer, readerOrBuffer.uint32());
|
||||
};
|
||||
|
||||
/**
|
||||
* Verifies a Message message.
|
||||
* @function
|
||||
* @param {Message|Object} message Message message or plain object to verify
|
||||
* @returns {?string} `null` if valid, otherwise the reason why it is not
|
||||
*/
|
||||
Message.verify = (function(util) { return function verify(message) {
|
||||
if (message.stringVal !== undefined) {
|
||||
if (!util.isString(message.stringVal)) {
|
||||
return "Message.stringVal: string expected";
|
||||
}
|
||||
}
|
||||
if (message.stringRepeated !== undefined) {
|
||||
if (!Array.isArray(message.stringRepeated)) {
|
||||
return "Message.stringRepeated: array expected";
|
||||
}
|
||||
for (var i = 0; i < message.stringRepeated.length; ++i) {
|
||||
if (!util.isString(message.stringRepeated[i])) {
|
||||
return "Message.stringRepeated: string[] expected";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.uint64Val !== undefined) {
|
||||
if (!util.isInteger(message.uint64Val) && !(message.uint64Val && util.isInteger(message.uint64Val.low) && util.isInteger(message.uint64Val.high))) {
|
||||
return "Message.uint64Val: integer|Long expected";
|
||||
}
|
||||
}
|
||||
if (message.uint64Repeated !== undefined) {
|
||||
if (!Array.isArray(message.uint64Repeated)) {
|
||||
return "Message.uint64Repeated: array expected";
|
||||
}
|
||||
for (var i = 0; i < message.uint64Repeated.length; ++i) {
|
||||
if (!util.isInteger(message.uint64Repeated[i]) && !(message.uint64Repeated[i] && util.isInteger(message.uint64Repeated[i].low) && util.isInteger(message.uint64Repeated[i].high))) {
|
||||
return "Message.uint64Repeated: integer|Long[] expected";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.bytesVal !== undefined) {
|
||||
if (!(message.bytesVal && typeof message.bytesVal.length === "number" || util.isString(message.bytesVal))) {
|
||||
return "Message.bytesVal: buffer expected";
|
||||
}
|
||||
}
|
||||
if (message.bytesRepeated !== undefined) {
|
||||
if (!Array.isArray(message.bytesRepeated)) {
|
||||
return "Message.bytesRepeated: array expected";
|
||||
}
|
||||
for (var i = 0; i < message.bytesRepeated.length; ++i) {
|
||||
if (!(message.bytesRepeated[i] && typeof message.bytesRepeated[i].length === "number" || util.isString(message.bytesRepeated[i]))) {
|
||||
return "Message.bytesRepeated: buffer[] expected";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.enumVal !== undefined) {
|
||||
switch (message.enumVal) {
|
||||
default:
|
||||
return "Message.enumVal: enum value expected";
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (message.enumRepeated !== undefined) {
|
||||
if (!Array.isArray(message.enumRepeated)) {
|
||||
return "Message.enumRepeated: array expected";
|
||||
}
|
||||
for (var i = 0; i < message.enumRepeated.length; ++i) {
|
||||
switch (message.enumRepeated[i]) {
|
||||
default:
|
||||
return "Message.enumRepeated: enum value[] expected";
|
||||
|
||||
case 1:
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.int64Map !== undefined) {
|
||||
if (!util.isObject(message.int64Map)) {
|
||||
return "Message.int64Map: object expected";
|
||||
}
|
||||
var key = Object.keys(message.int64Map);
|
||||
for (var i = 0; i < key.length; ++i) {
|
||||
if (!util.isInteger(message.int64Map[key[i]]) && !(message.int64Map[key[i]] && util.isInteger(message.int64Map[key[i]].low) && util.isInteger(message.int64Map[key[i]].high))) {
|
||||
return "Message.int64Map: integer|Long{key:string} expected";
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Creates a Message message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message
|
||||
*/
|
||||
Message.fromObject = (function(util) { return function fromObject(object) {
|
||||
var message = new $root.Message();
|
||||
message.stringVal = String(object.stringVal);
|
||||
if (object.stringRepeated) {
|
||||
message.stringRepeated = [];
|
||||
for (var i = 0; i < object.stringRepeated.length; ++i) {
|
||||
message.stringRepeated[i] = String(object.stringRepeated[i]);
|
||||
}
|
||||
}
|
||||
if (util.Long) {
|
||||
(message.uint64Val = util.Long.fromValue(object.uint64Val)).unsigned = true;
|
||||
} else {
|
||||
if (typeof object.uint64Val === "string") {
|
||||
message.uint64Val = parseInt(object.uint64Val, 10);
|
||||
} else {
|
||||
if (typeof object.uint64Val === "number") {
|
||||
message.uint64Val = object.uint64Val;
|
||||
} else {
|
||||
if (typeof object.uint64Val === "object") {
|
||||
message.uint64Val = new util.LongBits(object.uint64Val.low, object.uint64Val.high).toNumber(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (object.uint64Repeated) {
|
||||
message.uint64Repeated = [];
|
||||
for (var i = 0; i < object.uint64Repeated.length; ++i) {
|
||||
if (util.Long) {
|
||||
(message.uint64Repeated[i] = util.Long.fromValue(object.uint64Repeated[i])).unsigned = true;
|
||||
} else {
|
||||
if (typeof object.uint64Repeated[i] === "string") {
|
||||
message.uint64Repeated[i] = parseInt(object.uint64Repeated[i], 10);
|
||||
} else {
|
||||
if (typeof object.uint64Repeated[i] === "number") {
|
||||
message.uint64Repeated[i] = object.uint64Repeated[i];
|
||||
} else {
|
||||
if (typeof object.uint64Repeated[i] === "object") {
|
||||
message.uint64Repeated[i] = new util.LongBits(object.uint64Repeated[i].low, object.uint64Repeated[i].high).toNumber(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof object.bytesVal === "string") {
|
||||
util.base64.decode(object.bytesVal, message.bytesVal = util.newBuffer(util.base64.length(object.bytesVal)), 0);
|
||||
} else {
|
||||
if (object.bytesVal && object.bytesVal.length) {
|
||||
message.bytesVal = object.bytesVal;
|
||||
}
|
||||
}
|
||||
if (object.bytesRepeated) {
|
||||
message.bytesRepeated = [];
|
||||
for (var i = 0; i < object.bytesRepeated.length; ++i) {
|
||||
if (typeof object.bytesRepeated[i] === "string") {
|
||||
util.base64.decode(object.bytesRepeated[i], message.bytesRepeated[i] = util.newBuffer(util.base64.length(object.bytesRepeated[i])), 0);
|
||||
} else {
|
||||
if (object.bytesRepeated[i] && object.bytesRepeated[i].length) {
|
||||
message.bytesRepeated[i] = object.bytesRepeated[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (object.enumVal !== undefined && object.enumVal !== null) {
|
||||
switch (object.enumVal) {
|
||||
case "ONE":
|
||||
case 1:
|
||||
message.enumVal = 1;
|
||||
break;
|
||||
|
||||
case "TWO":
|
||||
case 2:
|
||||
message.enumVal = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (object.enumRepeated) {
|
||||
message.enumRepeated = [];
|
||||
for (var i = 0; i < object.enumRepeated.length; ++i) {
|
||||
switch (object.enumRepeated[i]) {
|
||||
default:
|
||||
case "ONE":
|
||||
case 1:
|
||||
message.enumRepeated[i] = 1;
|
||||
break;
|
||||
|
||||
case "TWO":
|
||||
case 2:
|
||||
message.enumRepeated[i] = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (object.int64Map) {
|
||||
message.int64Map = {};
|
||||
for (var keys = Object.keys(object.int64Map), i = 0; i < keys.length; ++i) {
|
||||
if (util.Long) {
|
||||
(message.int64Map[keys[i]] = util.Long.fromValue(object.int64Map[keys[i]])).unsigned = false;
|
||||
} else {
|
||||
if (typeof object.int64Map[keys[i]] === "string") {
|
||||
message.int64Map[keys[i]] = parseInt(object.int64Map[keys[i]], 10);
|
||||
} else {
|
||||
if (typeof object.int64Map[keys[i]] === "number") {
|
||||
message.int64Map[keys[i]] = object.int64Map[keys[i]];
|
||||
} else {
|
||||
if (typeof object.int64Map[keys[i]] === "object") {
|
||||
message.int64Map[keys[i]] = new util.LongBits(object.int64Map[keys[i]].low, object.int64Map[keys[i]].high).toNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Creates a Message message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Message.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Message} Message
|
||||
*/
|
||||
Message.from = Message.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Message message. Also converts values to other types if specified.
|
||||
* @param {Message} message Message
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Message.toObject = (function(util, types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.arrays || options.defaults) {
|
||||
object.stringRepeated = [];
|
||||
object.uint64Repeated = [];
|
||||
object.bytesRepeated = [];
|
||||
object.enumRepeated = [];
|
||||
}
|
||||
if (options.objects || options.defaults) {
|
||||
object.int64Map = {};
|
||||
}
|
||||
if (options.defaults) {
|
||||
object.stringVal = "";
|
||||
if (util.Long) {
|
||||
var long = new util.Long(0, 0, true);
|
||||
object.uint64Val = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
||||
} else {
|
||||
object.uint64Val = options.longs === String ? "0" : 0;
|
||||
}
|
||||
object.bytesVal = options.bytes === String ? "" : [];
|
||||
object.enumVal = options.enums === String ? "ONE" : 1;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "stringVal":
|
||||
if (message.stringVal !== undefined && message.stringVal !== null) {
|
||||
object.stringVal = message.stringVal;
|
||||
}
|
||||
break;
|
||||
|
||||
case "stringRepeated":
|
||||
if (message.stringRepeated.length) {
|
||||
object.stringRepeated = [];
|
||||
for (var j = 0; j < message.stringRepeated.length; ++j) {
|
||||
object.stringRepeated[j] = message.stringRepeated[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "uint64Val":
|
||||
if (message.uint64Val !== undefined && message.uint64Val !== null) {
|
||||
if (typeof message.uint64Val === "number") {
|
||||
object.uint64Val = options.longs === String ? String(message.uint64Val) : message.uint64Val;
|
||||
} else {
|
||||
object.uint64Val = options.longs === String ? util.Long.prototype.toString.call(message.uint64Val) : options.longs === Number ? new util.LongBits(message.uint64Val.low, message.uint64Val.high).toNumber(true) : message.uint64Val;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "uint64Repeated":
|
||||
if (message.uint64Repeated.length) {
|
||||
object.uint64Repeated = [];
|
||||
for (var j = 0; j < message.uint64Repeated.length; ++j) {
|
||||
if (typeof message.uint64Repeated[j] === "number") {
|
||||
object.uint64Repeated[j] = options.longs === String ? String(message.uint64Repeated[j]) : message.uint64Repeated[j];
|
||||
} else {
|
||||
object.uint64Repeated[j] = options.longs === String ? util.Long.prototype.toString.call(message.uint64Repeated[j]) : options.longs === Number ? new util.LongBits(message.uint64Repeated[j].low, message.uint64Repeated[j].high).toNumber(true) : message.uint64Repeated[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "bytesVal":
|
||||
if (message.bytesVal !== undefined && message.bytesVal !== null) {
|
||||
object.bytesVal = options.bytes === String ? util.base64.encode(message.bytesVal, 0, message.bytesVal.length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesVal) : message.bytesVal;
|
||||
}
|
||||
break;
|
||||
|
||||
case "bytesRepeated":
|
||||
if (message.bytesRepeated.length) {
|
||||
object.bytesRepeated = [];
|
||||
for (var j = 0; j < message.bytesRepeated.length; ++j) {
|
||||
object.bytesRepeated[j] = options.bytes === String ? util.base64.encode(message.bytesRepeated[j], 0, message.bytesRepeated[j].length) : options.bytes === Array ? Array.prototype.slice.call(message.bytesRepeated[j]) : message.bytesRepeated[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "enumVal":
|
||||
if (message.enumVal !== undefined && message.enumVal !== null) {
|
||||
object.enumVal = options.enums === String ? types[6][message.enumVal] : message.enumVal;
|
||||
}
|
||||
break;
|
||||
|
||||
case "enumRepeated":
|
||||
if (message.enumRepeated.length) {
|
||||
object.enumRepeated = [];
|
||||
for (var j = 0; j < message.enumRepeated.length; ++j) {
|
||||
object.enumRepeated[j] = options.enums === String ? types[7].values[message.enumRepeated[j]] : message.enumRepeated[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "int64Map":
|
||||
if (message.int64Map && message.int64Map !== util.emptyObject) {
|
||||
object.int64Map = {};
|
||||
for (var keys2 = Object.keys(message.int64Map), j = 0; j < keys2.length; ++j) {
|
||||
if (typeof message.int64Map[keys2[j]] === "number") {
|
||||
object.int64Map[keys2[j]] = options.longs === String ? String(message.int64Map[keys2[j]]) : message.int64Map[keys2[j]];
|
||||
} else {
|
||||
object.int64Map[keys2[j]] = options.longs === String ? util.Long.prototype.toString.call(message.int64Map[keys2[j]]) : options.longs === Number ? new util.LongBits(message.int64Map[keys2[j]].low, message.int64Map[keys2[j]].high).toNumber() : message.int64Map[keys2[j]];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($protobuf.util, $types);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Message message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Message to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* SomeEnum enum.
|
||||
* @name SomeEnum
|
||||
* @memberof Message
|
||||
* @enum {number}
|
||||
* @property {number} ONE=1 ONE value
|
||||
* @property {number} TWO=2 TWO value
|
||||
*/
|
||||
Message.SomeEnum = (function() {
|
||||
var valuesById = {},
|
||||
values = Object.create(valuesById);
|
||||
values[valuesById[1] = "ONE"] = 1;
|
||||
values[valuesById[2] = "TWO"] = 2;
|
||||
return values;
|
||||
})();
|
||||
|
||||
return Message;
|
||||
})();
|
||||
|
||||
// Resolve lazy types
|
||||
$lazyTypes.forEach(function(types) {
|
||||
types.forEach(function(path, i) {
|
||||
if (!path)
|
||||
return;
|
||||
path = path.split(".");
|
||||
var ptr = $root;
|
||||
while (path.length)
|
||||
ptr = ptr[path.shift()];
|
||||
types[i] = ptr;
|
||||
});
|
||||
});
|
||||
|
||||
$protobuf.roots["test_convert"] = $root;
|
||||
|
||||
module.exports = $root;
|
||||
@ -18,4 +18,6 @@ message Message {
|
||||
ONE = 1;
|
||||
TWO = 2;
|
||||
}
|
||||
|
||||
map<string,int64> int64_map = 9;
|
||||
}
|
||||
|
||||
@ -146,50 +146,78 @@ $root.vector_tile = (function() {
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Converts a Tile message.
|
||||
* @function
|
||||
* @param {vector_tile.Tile|Object} source Tile message or plain object to convert
|
||||
* @param {*} impl Converter implementation to use
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* @returns {vector_tile.Tile|Object} Converted message
|
||||
* Creates a Tile message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile} Tile
|
||||
*/
|
||||
Tile.convert = (function(types) { return function convert(src, impl, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var dst = impl.create(src, this, options);
|
||||
if (dst) {
|
||||
if (src.layers && src.layers.length) {
|
||||
dst.layers = [];
|
||||
for (var i = 0; i < src.layers.length; ++i) {
|
||||
dst.layers.push(types[0].convert(src.layers[i], impl, options));
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.layers = [];
|
||||
}
|
||||
Tile.fromObject = (function(types) { return function fromObject(object) {
|
||||
var message = new $root.vector_tile.Tile();
|
||||
if (object.layers) {
|
||||
message.layers = [];
|
||||
for (var i = 0; i < object.layers.length; ++i) {
|
||||
message.layers[i] = types[0].fromObject(object.layers[i]);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
return message;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a Tile message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a Tile message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link vector_tile.Tile.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile} Tile
|
||||
*/
|
||||
Tile.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
Tile.from = Tile.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Tile message. Also converts values to other types if specified.
|
||||
* @param {vector_tile.Tile} message Tile
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Tile.toObject = (function(types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.arrays || options.defaults) {
|
||||
object.layers = [];
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "layers":
|
||||
if (message.layers.length) {
|
||||
object.layers = [];
|
||||
for (var j = 0; j < message.layers.length; ++j) {
|
||||
object.layers[j] = types[0].ctor.prototype.toObject.call(message.layers[j], options);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Tile message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Tile message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Tile to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -434,61 +462,187 @@ $root.vector_tile = (function() {
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Converts a Value message.
|
||||
* @function
|
||||
* @param {vector_tile.Tile.Value|Object} source Value message or plain object to convert
|
||||
* @param {*} impl Converter implementation to use
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* @returns {vector_tile.Tile.Value|Object} Converted message
|
||||
* Creates a Value message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Value} Value
|
||||
*/
|
||||
Value.convert = (function(util) { return function convert(src, impl, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var dst = impl.create(src, this, options);
|
||||
if (dst) {
|
||||
if (dst.stringValue === undefined && options.defaults) {
|
||||
dst.stringValue = "";
|
||||
}
|
||||
if (dst.floatValue === undefined && options.defaults) {
|
||||
dst.floatValue = 0;
|
||||
}
|
||||
if (dst.doubleValue === undefined && options.defaults) {
|
||||
dst.doubleValue = 0;
|
||||
}
|
||||
if (options.defaults || src.intValue !== undefined && src.intValue !== null && util.longNe(src.intValue, 0, 0)) {
|
||||
dst.intValue = impl.longs(src.intValue, 0, 0, false, options);
|
||||
}
|
||||
if (options.defaults || src.uintValue !== undefined && src.uintValue !== null && util.longNe(src.uintValue, 0, 0)) {
|
||||
dst.uintValue = impl.longs(src.uintValue, 0, 0, true, options);
|
||||
}
|
||||
if (options.defaults || src.sintValue !== undefined && src.sintValue !== null && util.longNe(src.sintValue, 0, 0)) {
|
||||
dst.sintValue = impl.longs(src.sintValue, 0, 0, false, options);
|
||||
}
|
||||
if (dst.boolValue === undefined && options.defaults) {
|
||||
dst.boolValue = false;
|
||||
Value.fromObject = (function(util) { return function fromObject(object) {
|
||||
var message = new $root.vector_tile.Tile.Value();
|
||||
message.stringValue = String(object.stringValue);
|
||||
message.floatValue = Number(object.floatValue);
|
||||
message.doubleValue = Number(object.doubleValue);
|
||||
if (util.Long) {
|
||||
(message.intValue = util.Long.fromValue(object.intValue)).unsigned = false;
|
||||
} else {
|
||||
if (typeof object.intValue === "string") {
|
||||
message.intValue = parseInt(object.intValue, 10);
|
||||
} else {
|
||||
if (typeof object.intValue === "number") {
|
||||
message.intValue = object.intValue;
|
||||
} else {
|
||||
if (typeof object.intValue === "object") {
|
||||
message.intValue = new util.LongBits(object.intValue.low, object.intValue.high).toNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
if (util.Long) {
|
||||
(message.uintValue = util.Long.fromValue(object.uintValue)).unsigned = true;
|
||||
} else {
|
||||
if (typeof object.uintValue === "string") {
|
||||
message.uintValue = parseInt(object.uintValue, 10);
|
||||
} else {
|
||||
if (typeof object.uintValue === "number") {
|
||||
message.uintValue = object.uintValue;
|
||||
} else {
|
||||
if (typeof object.uintValue === "object") {
|
||||
message.uintValue = new util.LongBits(object.uintValue.low, object.uintValue.high).toNumber(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (util.Long) {
|
||||
(message.sintValue = util.Long.fromValue(object.sintValue)).unsigned = false;
|
||||
} else {
|
||||
if (typeof object.sintValue === "string") {
|
||||
message.sintValue = parseInt(object.sintValue, 10);
|
||||
} else {
|
||||
if (typeof object.sintValue === "number") {
|
||||
message.sintValue = object.sintValue;
|
||||
} else {
|
||||
if (typeof object.sintValue === "object") {
|
||||
message.sintValue = new util.LongBits(object.sintValue.low, object.sintValue.high).toNumber();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
message.boolValue = Boolean(object.boolValue);
|
||||
return message;
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Creates a Value message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a Value message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link vector_tile.Tile.Value.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Value} Value
|
||||
*/
|
||||
Value.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
Value.from = Value.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Value message. Also converts values to other types if specified.
|
||||
* @param {vector_tile.Tile.Value} message Value
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Value.toObject = (function(util) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.stringValue = "";
|
||||
object.floatValue = 0;
|
||||
object.doubleValue = 0;
|
||||
if (util.Long) {
|
||||
var long = new util.Long(0, 0, false);
|
||||
object.intValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
||||
} else {
|
||||
object.intValue = options.longs === String ? "0" : 0;
|
||||
}
|
||||
if (util.Long) {
|
||||
var long = new util.Long(0, 0, true);
|
||||
object.uintValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
||||
} else {
|
||||
object.uintValue = options.longs === String ? "0" : 0;
|
||||
}
|
||||
if (util.Long) {
|
||||
var long = new util.Long(0, 0, false);
|
||||
object.sintValue = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
||||
} else {
|
||||
object.sintValue = options.longs === String ? "0" : 0;
|
||||
}
|
||||
object.boolValue = false;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "stringValue":
|
||||
if (message.stringValue !== undefined && message.stringValue !== null) {
|
||||
object.stringValue = message.stringValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case "floatValue":
|
||||
if (message.floatValue !== undefined && message.floatValue !== null) {
|
||||
object.floatValue = message.floatValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case "doubleValue":
|
||||
if (message.doubleValue !== undefined && message.doubleValue !== null) {
|
||||
object.doubleValue = message.doubleValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case "intValue":
|
||||
if (message.intValue !== undefined && message.intValue !== null) {
|
||||
if (typeof message.intValue === "number") {
|
||||
object.intValue = options.longs === String ? String(message.intValue) : message.intValue;
|
||||
} else {
|
||||
object.intValue = options.longs === String ? util.Long.prototype.toString.call(message.intValue) : options.longs === Number ? new util.LongBits(message.intValue.low, message.intValue.high).toNumber() : message.intValue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "uintValue":
|
||||
if (message.uintValue !== undefined && message.uintValue !== null) {
|
||||
if (typeof message.uintValue === "number") {
|
||||
object.uintValue = options.longs === String ? String(message.uintValue) : message.uintValue;
|
||||
} else {
|
||||
object.uintValue = options.longs === String ? util.Long.prototype.toString.call(message.uintValue) : options.longs === Number ? new util.LongBits(message.uintValue.low, message.uintValue.high).toNumber(true) : message.uintValue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "sintValue":
|
||||
if (message.sintValue !== undefined && message.sintValue !== null) {
|
||||
if (typeof message.sintValue === "number") {
|
||||
object.sintValue = options.longs === String ? String(message.sintValue) : message.sintValue;
|
||||
} else {
|
||||
object.sintValue = options.longs === String ? util.Long.prototype.toString.call(message.sintValue) : options.longs === Number ? new util.LongBits(message.sintValue.low, message.sintValue.high).toNumber() : message.sintValue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "boolValue":
|
||||
if (message.boolValue !== undefined && message.boolValue !== null) {
|
||||
object.boolValue = message.boolValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Value message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Value message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Value to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return Value;
|
||||
@ -710,66 +864,157 @@ $root.vector_tile = (function() {
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Converts a Feature message.
|
||||
* @function
|
||||
* @param {vector_tile.Tile.Feature|Object} source Feature message or plain object to convert
|
||||
* @param {*} impl Converter implementation to use
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* @returns {vector_tile.Tile.Feature|Object} Converted message
|
||||
* Creates a Feature message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Feature} Feature
|
||||
*/
|
||||
Feature.convert = (function(util, types) { return function convert(src, impl, options) {
|
||||
Feature.fromObject = (function(util) { return function fromObject(object) {
|
||||
var message = new $root.vector_tile.Tile.Feature();
|
||||
if (util.Long) {
|
||||
(message.id = util.Long.fromValue(object.id)).unsigned = true;
|
||||
} else {
|
||||
if (typeof object.id === "string") {
|
||||
message.id = parseInt(object.id, 10);
|
||||
} else {
|
||||
if (typeof object.id === "number") {
|
||||
message.id = object.id;
|
||||
} else {
|
||||
if (typeof object.id === "object") {
|
||||
message.id = new util.LongBits(object.id.low, object.id.high).toNumber(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (object.tags) {
|
||||
message.tags = [];
|
||||
for (var i = 0; i < object.tags.length; ++i) {
|
||||
message.tags[i] = object.tags[i] >>> 0;
|
||||
}
|
||||
}
|
||||
if (object.type !== undefined && object.type !== null) {
|
||||
switch (object.type) {
|
||||
case "UNKNOWN":
|
||||
case 0:
|
||||
message.type = 0;
|
||||
break;
|
||||
|
||||
case "POINT":
|
||||
case 1:
|
||||
message.type = 1;
|
||||
break;
|
||||
|
||||
case "LINESTRING":
|
||||
case 2:
|
||||
message.type = 2;
|
||||
break;
|
||||
|
||||
case "POLYGON":
|
||||
case 3:
|
||||
message.type = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (object.geometry) {
|
||||
message.geometry = [];
|
||||
for (var i = 0; i < object.geometry.length; ++i) {
|
||||
message.geometry[i] = object.geometry[i] >>> 0;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};})($protobuf.util);
|
||||
|
||||
/**
|
||||
* Creates a Feature message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link vector_tile.Tile.Feature.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Feature} Feature
|
||||
*/
|
||||
Feature.from = Feature.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Feature message. Also converts values to other types if specified.
|
||||
* @param {vector_tile.Tile.Feature} message Feature
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Feature.toObject = (function(util, types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var dst = impl.create(src, this, options);
|
||||
if (dst) {
|
||||
if (options.defaults || src.id !== undefined && src.id !== null && util.longNe(src.id, 0, 0)) {
|
||||
dst.id = impl.longs(src.id, 0, 0, true, options);
|
||||
}
|
||||
if (src.tags && src.tags.length) {
|
||||
dst.tags = [];
|
||||
for (var i = 0; i < src.tags.length; ++i) {
|
||||
dst.tags.push(src.tags[i]);
|
||||
}
|
||||
var object = {};
|
||||
if (options.arrays || options.defaults) {
|
||||
object.tags = [];
|
||||
object.geometry = [];
|
||||
}
|
||||
if (options.defaults) {
|
||||
if (util.Long) {
|
||||
var long = new util.Long(0, 0, true);
|
||||
object.id = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long;
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.tags = [];
|
||||
}
|
||||
object.id = options.longs === String ? "0" : 0;
|
||||
}
|
||||
if (options.defaults || src.type !== undefined && src.type !== undefined) {
|
||||
dst.type = impl.enums(src.type, undefined, types[2], options);
|
||||
}
|
||||
if (src.geometry && src.geometry.length) {
|
||||
dst.geometry = [];
|
||||
for (var i = 0; i < src.geometry.length; ++i) {
|
||||
dst.geometry.push(src.geometry[i]);
|
||||
object.type = options.enums === String ? undefined : undefined;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "id":
|
||||
if (message.id !== undefined && message.id !== null) {
|
||||
if (typeof message.id === "number") {
|
||||
object.id = options.longs === String ? String(message.id) : message.id;
|
||||
} else {
|
||||
object.id = options.longs === String ? util.Long.prototype.toString.call(message.id) : options.longs === Number ? new util.LongBits(message.id.low, message.id.high).toNumber(true) : message.id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.geometry = [];
|
||||
break;
|
||||
|
||||
case "tags":
|
||||
if (message.tags.length) {
|
||||
object.tags = [];
|
||||
for (var j = 0; j < message.tags.length; ++j) {
|
||||
object.tags[j] = message.tags[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "type":
|
||||
if (message.type !== undefined && message.type !== null) {
|
||||
object.type = options.enums === String ? types[2][message.type] : message.type;
|
||||
}
|
||||
break;
|
||||
|
||||
case "geometry":
|
||||
if (message.geometry.length) {
|
||||
object.geometry = [];
|
||||
for (var j = 0; j < message.geometry.length; ++j) {
|
||||
object.geometry[j] = message.geometry[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
return object;
|
||||
};})($protobuf.util, $types);
|
||||
|
||||
/**
|
||||
* Creates a Feature message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* @returns {vector_tile.Tile.Feature} Feature
|
||||
* Creates a plain object from this Feature message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Feature.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Feature message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Feature to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return Feature;
|
||||
@ -1006,79 +1251,136 @@ $root.vector_tile = (function() {
|
||||
};})($protobuf.util, $types);
|
||||
|
||||
/**
|
||||
* Converts a Layer message.
|
||||
* @function
|
||||
* @param {vector_tile.Tile.Layer|Object} source Layer message or plain object to convert
|
||||
* @param {*} impl Converter implementation to use
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* @returns {vector_tile.Tile.Layer|Object} Converted message
|
||||
* Creates a Layer message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Layer} Layer
|
||||
*/
|
||||
Layer.convert = (function(types) { return function convert(src, impl, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var dst = impl.create(src, this, options);
|
||||
if (dst) {
|
||||
if (dst.version === undefined && options.defaults) {
|
||||
dst.version = 1;
|
||||
}
|
||||
if (dst.name === undefined && options.defaults) {
|
||||
dst.name = "";
|
||||
}
|
||||
if (src.features && src.features.length) {
|
||||
dst.features = [];
|
||||
for (var i = 0; i < src.features.length; ++i) {
|
||||
dst.features.push(types[2].convert(src.features[i], impl, options));
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.features = [];
|
||||
}
|
||||
}
|
||||
if (src.keys && src.keys.length) {
|
||||
dst.keys = [];
|
||||
for (var i = 0; i < src.keys.length; ++i) {
|
||||
dst.keys.push(src.keys[i]);
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.keys = [];
|
||||
}
|
||||
}
|
||||
if (src.values && src.values.length) {
|
||||
dst.values = [];
|
||||
for (var i = 0; i < src.values.length; ++i) {
|
||||
dst.values.push(types[4].convert(src.values[i], impl, options));
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.values = [];
|
||||
}
|
||||
}
|
||||
if (dst.extent === undefined && options.defaults) {
|
||||
dst.extent = 4096;
|
||||
Layer.fromObject = (function(types) { return function fromObject(object) {
|
||||
var message = new $root.vector_tile.Tile.Layer();
|
||||
message.version = object.version >>> 0;
|
||||
message.name = String(object.name);
|
||||
if (object.features) {
|
||||
message.features = [];
|
||||
for (var i = 0; i < object.features.length; ++i) {
|
||||
message.features[i] = types[2].fromObject(object.features[i]);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
if (object.keys) {
|
||||
message.keys = [];
|
||||
for (var i = 0; i < object.keys.length; ++i) {
|
||||
message.keys[i] = String(object.keys[i]);
|
||||
}
|
||||
}
|
||||
if (object.values) {
|
||||
message.values = [];
|
||||
for (var i = 0; i < object.values.length; ++i) {
|
||||
message.values[i] = types[4].fromObject(object.values[i]);
|
||||
}
|
||||
}
|
||||
message.extent = object.extent >>> 0;
|
||||
return message;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a Layer message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a Layer message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link vector_tile.Tile.Layer.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {vector_tile.Tile.Layer} Layer
|
||||
*/
|
||||
Layer.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
Layer.from = Layer.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Layer message. Also converts values to other types if specified.
|
||||
* @param {vector_tile.Tile.Layer} message Layer
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Layer.toObject = (function(types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.arrays || options.defaults) {
|
||||
object.features = [];
|
||||
object.keys = [];
|
||||
object.values = [];
|
||||
}
|
||||
if (options.defaults) {
|
||||
object.version = 1;
|
||||
object.name = "";
|
||||
object.extent = 4096;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "version":
|
||||
if (message.version !== undefined && message.version !== null) {
|
||||
object.version = message.version;
|
||||
}
|
||||
break;
|
||||
|
||||
case "name":
|
||||
if (message.name !== undefined && message.name !== null) {
|
||||
object.name = message.name;
|
||||
}
|
||||
break;
|
||||
|
||||
case "features":
|
||||
if (message.features.length) {
|
||||
object.features = [];
|
||||
for (var j = 0; j < message.features.length; ++j) {
|
||||
object.features[j] = types[2].ctor.prototype.toObject.call(message.features[j], options);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "keys":
|
||||
if (message.keys.length) {
|
||||
object.keys = [];
|
||||
for (var j = 0; j < message.keys.length; ++j) {
|
||||
object.keys[j] = message.keys[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "values":
|
||||
if (message.values.length) {
|
||||
object.values = [];
|
||||
for (var j = 0; j < message.values.length; ++j) {
|
||||
object.values[j] = types[4].ctor.prototype.toObject.call(message.values[j], options);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "extent":
|
||||
if (message.extent !== undefined && message.extent !== null) {
|
||||
object.extent = message.extent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Layer message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Layer message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Layer to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return Layer;
|
||||
|
||||
@ -295,11 +295,8 @@ $root.Package = (function() {
|
||||
message.bin = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
if (typeof key === "object") {
|
||||
key = util.longToHash(key);
|
||||
}
|
||||
reader.pos++;
|
||||
message.bin[key] = reader.string();
|
||||
message.bin[typeof key === "object" ? util.longToHash(key) : key] = reader.string();
|
||||
break;
|
||||
|
||||
case 12:
|
||||
@ -308,11 +305,8 @@ $root.Package = (function() {
|
||||
message.scripts = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
if (typeof key === "object") {
|
||||
key = util.longToHash(key);
|
||||
}
|
||||
reader.pos++;
|
||||
message.scripts[key] = reader.string();
|
||||
message.scripts[typeof key === "object" ? util.longToHash(key) : key] = reader.string();
|
||||
break;
|
||||
|
||||
case 13:
|
||||
@ -321,11 +315,8 @@ $root.Package = (function() {
|
||||
message.dependencies = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
if (typeof key === "object") {
|
||||
key = util.longToHash(key);
|
||||
}
|
||||
reader.pos++;
|
||||
message.dependencies[key] = reader.string();
|
||||
message.dependencies[typeof key === "object" ? util.longToHash(key) : key] = reader.string();
|
||||
break;
|
||||
|
||||
case 14:
|
||||
@ -334,11 +325,8 @@ $root.Package = (function() {
|
||||
message.optionalDependencies = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
if (typeof key === "object") {
|
||||
key = util.longToHash(key);
|
||||
}
|
||||
reader.pos++;
|
||||
message.optionalDependencies[key] = reader.string();
|
||||
message.optionalDependencies[typeof key === "object" ? util.longToHash(key) : key] = reader.string();
|
||||
break;
|
||||
|
||||
case 15:
|
||||
@ -347,11 +335,8 @@ $root.Package = (function() {
|
||||
message.devDependencies = {};
|
||||
}
|
||||
var key = reader.string();
|
||||
if (typeof key === "object") {
|
||||
key = util.longToHash(key);
|
||||
}
|
||||
reader.pos++;
|
||||
message.devDependencies[key] = reader.string();
|
||||
message.devDependencies[typeof key === "object" ? util.longToHash(key) : key] = reader.string();
|
||||
break;
|
||||
|
||||
case 17:
|
||||
@ -520,105 +505,258 @@ $root.Package = (function() {
|
||||
};})($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
|
||||
* Creates a Package message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Package} Package
|
||||
*/
|
||||
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 = "";
|
||||
}
|
||||
if (options.defaults || src.repository !== undefined && src.repository !== null) {
|
||||
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 = "";
|
||||
}
|
||||
if (src.cliDependencies && src.cliDependencies.length) {
|
||||
dst.cliDependencies = [];
|
||||
for (var i = 0; i < src.cliDependencies.length; ++i) {
|
||||
dst.cliDependencies.push(src.cliDependencies[i]);
|
||||
}
|
||||
} else {
|
||||
if (options.defaults || options.arrays) {
|
||||
dst.cliDependencies = [];
|
||||
}
|
||||
Package.fromObject = (function(types) { return function fromObject(object) {
|
||||
var message = new $root.Package();
|
||||
message.name = String(object.name);
|
||||
message.version = String(object.version);
|
||||
message.description = String(object.description);
|
||||
message.author = String(object.author);
|
||||
message.license = String(object.license);
|
||||
message.repository = types[5].fromObject(object.repository);
|
||||
message.bugs = String(object.bugs);
|
||||
message.homepage = String(object.homepage);
|
||||
if (object.keywords) {
|
||||
message.keywords = [];
|
||||
for (var i = 0; i < object.keywords.length; ++i) {
|
||||
message.keywords[i] = String(object.keywords[i]);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
message.main = String(object.main);
|
||||
if (object.bin) {
|
||||
message.bin = {};
|
||||
for (var keys = Object.keys(object.bin), i = 0; i < keys.length; ++i) {
|
||||
message.bin[keys[i]] = String(object.bin[keys[i]]);
|
||||
}
|
||||
}
|
||||
if (object.scripts) {
|
||||
message.scripts = {};
|
||||
for (var keys = Object.keys(object.scripts), i = 0; i < keys.length; ++i) {
|
||||
message.scripts[keys[i]] = String(object.scripts[keys[i]]);
|
||||
}
|
||||
}
|
||||
if (object.dependencies) {
|
||||
message.dependencies = {};
|
||||
for (var keys = Object.keys(object.dependencies), i = 0; i < keys.length; ++i) {
|
||||
message.dependencies[keys[i]] = String(object.dependencies[keys[i]]);
|
||||
}
|
||||
}
|
||||
if (object.optionalDependencies) {
|
||||
message.optionalDependencies = {};
|
||||
for (var keys = Object.keys(object.optionalDependencies), i = 0; i < keys.length; ++i) {
|
||||
message.optionalDependencies[keys[i]] = String(object.optionalDependencies[keys[i]]);
|
||||
}
|
||||
}
|
||||
if (object.devDependencies) {
|
||||
message.devDependencies = {};
|
||||
for (var keys = Object.keys(object.devDependencies), i = 0; i < keys.length; ++i) {
|
||||
message.devDependencies[keys[i]] = String(object.devDependencies[keys[i]]);
|
||||
}
|
||||
}
|
||||
message.types = String(object.types);
|
||||
if (object.cliDependencies) {
|
||||
message.cliDependencies = [];
|
||||
for (var i = 0; i < object.cliDependencies.length; ++i) {
|
||||
message.cliDependencies[i] = String(object.cliDependencies[i]);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};})($types);
|
||||
|
||||
/**
|
||||
* Creates a Package message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a Package message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Package.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Package} Package
|
||||
*/
|
||||
Package.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
Package.from = Package.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Package message. Also converts values to other types if specified.
|
||||
* @param {Package} message Package
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Package.toObject = (function(util, types) { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.arrays || options.defaults) {
|
||||
object.keywords = [];
|
||||
object.cliDependencies = [];
|
||||
}
|
||||
if (options.objects || options.defaults) {
|
||||
object.bin = {};
|
||||
object.scripts = {};
|
||||
object.dependencies = {};
|
||||
object.optionalDependencies = {};
|
||||
object.devDependencies = {};
|
||||
}
|
||||
if (options.defaults) {
|
||||
object.name = "";
|
||||
object.version = "";
|
||||
object.description = "";
|
||||
object.author = "";
|
||||
object.license = "";
|
||||
object.repository = null;
|
||||
object.bugs = "";
|
||||
object.homepage = "";
|
||||
object.main = "";
|
||||
object.types = "";
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "name":
|
||||
if (message.name !== undefined && message.name !== null) {
|
||||
object.name = message.name;
|
||||
}
|
||||
break;
|
||||
|
||||
case "version":
|
||||
if (message.version !== undefined && message.version !== null) {
|
||||
object.version = message.version;
|
||||
}
|
||||
break;
|
||||
|
||||
case "description":
|
||||
if (message.description !== undefined && message.description !== null) {
|
||||
object.description = message.description;
|
||||
}
|
||||
break;
|
||||
|
||||
case "author":
|
||||
if (message.author !== undefined && message.author !== null) {
|
||||
object.author = message.author;
|
||||
}
|
||||
break;
|
||||
|
||||
case "license":
|
||||
if (message.license !== undefined && message.license !== null) {
|
||||
object.license = message.license;
|
||||
}
|
||||
break;
|
||||
|
||||
case "repository":
|
||||
if (message.repository !== undefined && message.repository !== null) {
|
||||
object.repository = types[5].ctor.prototype.toObject.call(message.repository, options);
|
||||
}
|
||||
break;
|
||||
|
||||
case "bugs":
|
||||
if (message.bugs !== undefined && message.bugs !== null) {
|
||||
object.bugs = message.bugs;
|
||||
}
|
||||
break;
|
||||
|
||||
case "homepage":
|
||||
if (message.homepage !== undefined && message.homepage !== null) {
|
||||
object.homepage = message.homepage;
|
||||
}
|
||||
break;
|
||||
|
||||
case "keywords":
|
||||
if (message.keywords.length) {
|
||||
object.keywords = [];
|
||||
for (var j = 0; j < message.keywords.length; ++j) {
|
||||
object.keywords[j] = message.keywords[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "main":
|
||||
if (message.main !== undefined && message.main !== null) {
|
||||
object.main = message.main;
|
||||
}
|
||||
break;
|
||||
|
||||
case "bin":
|
||||
if (message.bin && message.bin !== util.emptyObject) {
|
||||
object.bin = {};
|
||||
for (var keys2 = Object.keys(message.bin), j = 0; j < keys2.length; ++j) {
|
||||
object.bin[keys2[j]] = message.bin[keys2[j]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "scripts":
|
||||
if (message.scripts && message.scripts !== util.emptyObject) {
|
||||
object.scripts = {};
|
||||
for (var keys2 = Object.keys(message.scripts), j = 0; j < keys2.length; ++j) {
|
||||
object.scripts[keys2[j]] = message.scripts[keys2[j]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "dependencies":
|
||||
if (message.dependencies && message.dependencies !== util.emptyObject) {
|
||||
object.dependencies = {};
|
||||
for (var keys2 = Object.keys(message.dependencies), j = 0; j < keys2.length; ++j) {
|
||||
object.dependencies[keys2[j]] = message.dependencies[keys2[j]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "optionalDependencies":
|
||||
if (message.optionalDependencies && message.optionalDependencies !== util.emptyObject) {
|
||||
object.optionalDependencies = {};
|
||||
for (var keys2 = Object.keys(message.optionalDependencies), j = 0; j < keys2.length; ++j) {
|
||||
object.optionalDependencies[keys2[j]] = message.optionalDependencies[keys2[j]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "devDependencies":
|
||||
if (message.devDependencies && message.devDependencies !== util.emptyObject) {
|
||||
object.devDependencies = {};
|
||||
for (var keys2 = Object.keys(message.devDependencies), j = 0; j < keys2.length; ++j) {
|
||||
object.devDependencies[keys2[j]] = message.devDependencies[keys2[j]];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "types":
|
||||
if (message.types !== undefined && message.types !== null) {
|
||||
object.types = message.types;
|
||||
}
|
||||
break;
|
||||
|
||||
case "cliDependencies":
|
||||
if (message.cliDependencies.length) {
|
||||
object.cliDependencies = [];
|
||||
for (var j = 0; j < message.cliDependencies.length; ++j) {
|
||||
object.cliDependencies[j] = message.cliDependencies[j];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})($protobuf.util, $types);
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Package message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Package message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Package to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
Package.Repository = (function() {
|
||||
@ -753,46 +891,78 @@ $root.Package = (function() {
|
||||
};})($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
|
||||
* Creates a Repository message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Package.Repository} Repository
|
||||
*/
|
||||
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;
|
||||
Repository.fromObject = (function() { return function fromObject(object) {
|
||||
var message = new $root.Package.Repository();
|
||||
message.type = String(object.type);
|
||||
message.url = String(object.url);
|
||||
return message;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a Repository message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a Repository message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link Package.Repository.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {Package.Repository} Repository
|
||||
*/
|
||||
Repository.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
Repository.from = Repository.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a Repository message. Also converts values to other types if specified.
|
||||
* @param {Package.Repository} message Repository
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
Repository.toObject = (function() { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.type = "";
|
||||
object.url = "";
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "type":
|
||||
if (message.type !== undefined && message.type !== null) {
|
||||
object.type = message.type;
|
||||
}
|
||||
break;
|
||||
|
||||
case "url":
|
||||
if (message.url !== undefined && message.url !== null) {
|
||||
object.url = message.url;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a plain object from this Repository message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this Repository message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this Repository to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return Repository;
|
||||
|
||||
@ -215,43 +215,70 @@ $root.MyRequest = (function() {
|
||||
};})($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
|
||||
* Creates a MyRequest message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {MyRequest} MyRequest
|
||||
*/
|
||||
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;
|
||||
MyRequest.fromObject = (function() { return function fromObject(object) {
|
||||
var message = new $root.MyRequest();
|
||||
message.path = String(object.path);
|
||||
return message;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a MyRequest message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a MyRequest message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link MyRequest.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {MyRequest} MyRequest
|
||||
*/
|
||||
MyRequest.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
MyRequest.from = MyRequest.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a MyRequest message. Also converts values to other types if specified.
|
||||
* @param {MyRequest} message MyRequest
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
MyRequest.toObject = (function() { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.path = "";
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "path":
|
||||
if (message.path !== undefined && message.path !== null) {
|
||||
object.path = message.path;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a plain object from this MyRequest message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this MyRequest message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this MyRequest to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return MyRequest;
|
||||
@ -371,43 +398,70 @@ $root.MyResponse = (function() {
|
||||
};})($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
|
||||
* Creates a MyResponse message from a plain object. Also converts values to their respective internal types.
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {MyResponse} MyResponse
|
||||
*/
|
||||
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;
|
||||
MyResponse.fromObject = (function() { return function fromObject(object) {
|
||||
var message = new $root.MyResponse();
|
||||
message.status = object.status | 0;
|
||||
return message;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a MyResponse message from JSON.
|
||||
* @param {Object.<string,*>} source Source object
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Creates a MyResponse message from a plain object. Also converts values to their respective internal types.
|
||||
* This is an alias of {@link MyResponse.fromObject}.
|
||||
* @function
|
||||
* @param {Object.<string,*>} object Plain object
|
||||
* @returns {MyResponse} MyResponse
|
||||
*/
|
||||
MyResponse.from = function from(source, options) {
|
||||
return this.convert(source, $protobuf.converters.message, options);
|
||||
MyResponse.from = MyResponse.fromObject;
|
||||
|
||||
/**
|
||||
* Creates a plain object from a MyResponse message. Also converts values to other types if specified.
|
||||
* @param {MyResponse} message MyResponse
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
MyResponse.toObject = (function() { return function toObject(message, options) {
|
||||
if (!options) {
|
||||
options = {};
|
||||
}
|
||||
var object = {};
|
||||
if (options.defaults) {
|
||||
object.status = 0;
|
||||
}
|
||||
for (var keys = Object.keys(message), i = 0; i < keys.length; ++i) {
|
||||
switch (keys[i]) {
|
||||
case "status":
|
||||
if (message.status !== undefined && message.status !== null) {
|
||||
object.status = message.status;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return object;
|
||||
};})();
|
||||
|
||||
/**
|
||||
* Creates a plain object from this MyResponse message. Also converts values to other types if specified.
|
||||
* @param {$protobuf.ConversionOptions} [options] Conversion options
|
||||
* @returns {Object.<string,*>} Plain object
|
||||
*/
|
||||
$prototype.toObject = function toObject(options) {
|
||||
return this.constructor.toObject(this, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts this MyResponse message to JSON.
|
||||
* @param {Object.<string,*>} [options] Conversion options
|
||||
* Converts this MyResponse to JSON.
|
||||
* @returns {Object.<string,*>} JSON object
|
||||
*/
|
||||
$prototype.asJSON = function asJSON(options) {
|
||||
return this.constructor.convert(this, $protobuf.converters.json, options);
|
||||
$prototype.toJSON = function toJSON() {
|
||||
return this.constructor.toObject(this, {
|
||||
longs: String,
|
||||
enums: String,
|
||||
bytes: String
|
||||
});
|
||||
};
|
||||
|
||||
return MyResponse;
|
||||
|
||||
424
tests/data/test.d.ts
vendored
424
tests/data/test.d.ts
vendored
@ -12,9 +12,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Empty;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
enum OuterEnum {
|
||||
@ -31,9 +33,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.EnumContainer;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class Simple1 {
|
||||
@ -47,9 +51,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Simple1;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class Simple2 {
|
||||
@ -62,9 +68,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Simple2;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class SpecialCases {
|
||||
@ -79,9 +87,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.SpecialCases;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class OptionalFields {
|
||||
@ -97,9 +107,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.OptionalFields;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace OptionalFields {
|
||||
@ -113,9 +125,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.OptionalFields.Nested;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,9 +144,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.HasExtensions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class Complex {
|
||||
@ -148,9 +164,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Complex;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace Complex {
|
||||
@ -164,9 +182,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Complex.Nested;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,9 +198,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.OuterMessage;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace OuterMessage {
|
||||
@ -194,9 +216,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.OuterMessage.Complex;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,9 +233,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.IsExtension;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class IndirectExtension {
|
||||
@ -222,9 +248,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.IndirectExtension;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class DefaultValues {
|
||||
@ -241,9 +269,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.DefaultValues;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace DefaultValues {
|
||||
@ -270,9 +300,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.FloatingPointFields;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestClone {
|
||||
@ -288,9 +320,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestClone;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class CloneExtension {
|
||||
@ -302,9 +336,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.CloneExtension;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestGroup {
|
||||
@ -318,9 +354,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestGroup;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestReservedNames {
|
||||
@ -332,9 +370,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestReservedNames;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestReservedNamesExtension {
|
||||
@ -345,9 +385,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestReservedNamesExtension;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestMessageWithOneof {
|
||||
@ -372,9 +414,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestMessageWithOneof;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestEndsWithBytes {
|
||||
@ -387,9 +431,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestEndsWithBytes;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class TestMapFieldsNoBinary {
|
||||
@ -412,9 +458,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.TestMapFieldsNoBinary;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
enum MapValueEnumNoBinary {
|
||||
@ -432,9 +480,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.MapValueMessageNoBinary;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class Deeply {
|
||||
@ -445,9 +495,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Deeply;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace Deeply {
|
||||
@ -460,9 +512,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Deeply.Nested;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace Nested {
|
||||
@ -476,9 +530,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): jspb.test.Deeply.Nested.Message;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -498,9 +554,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.FileDescriptorSet;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class FileDescriptorProto {
|
||||
@ -523,9 +581,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.FileDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class DescriptorProto {
|
||||
@ -546,9 +606,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.DescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace DescriptorProto {
|
||||
@ -563,9 +625,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.DescriptorProto.ExtensionRange;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class ReservedRange {
|
||||
@ -578,9 +642,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.DescriptorProto.ReservedRange;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -602,9 +668,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.FieldDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace FieldDescriptorProto {
|
||||
@ -647,9 +715,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.OneofDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class EnumDescriptorProto {
|
||||
@ -663,9 +733,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.EnumDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class EnumValueDescriptorProto {
|
||||
@ -679,9 +751,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.EnumValueDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class ServiceDescriptorProto {
|
||||
@ -695,9 +769,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.ServiceDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class MethodDescriptorProto {
|
||||
@ -714,9 +790,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.MethodDescriptorProto;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class FileOptions {
|
||||
@ -742,9 +820,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.FileOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace FileOptions {
|
||||
@ -769,9 +849,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.MessageOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class FieldOptions {
|
||||
@ -789,9 +871,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.FieldOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace FieldOptions {
|
||||
@ -818,9 +902,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.OneofOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class EnumOptions {
|
||||
@ -834,9 +920,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.EnumOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class EnumValueOptions {
|
||||
@ -849,9 +937,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.EnumValueOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class ServiceOptions {
|
||||
@ -864,9 +954,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.ServiceOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
class MethodOptions {
|
||||
@ -880,9 +972,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.MethodOptions;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace MethodOptions {
|
||||
@ -909,9 +1003,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.UninterpretedOption;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace UninterpretedOption {
|
||||
@ -926,9 +1022,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.UninterpretedOption.NamePart;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -941,9 +1039,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.SourceCodeInfo;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace SourceCodeInfo {
|
||||
@ -961,9 +1061,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.SourceCodeInfo.Location;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
|
||||
@ -976,9 +1078,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.GeneratedCodeInfo;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
|
||||
namespace GeneratedCodeInfo {
|
||||
@ -995,9 +1099,11 @@ 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 };
|
||||
static fromObject: any;
|
||||
static from(object: { [k: string]: any }): google.protobuf.GeneratedCodeInfo.Annotation;
|
||||
static toObject: any;
|
||||
toObject(options?: $protobuf.ConversionOptions): { [k: string]: any };
|
||||
toJSON(): { [k: string]: any };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
6806
tests/data/test.js
6806
tests/data/test.js
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,7 @@ tape.test("empty inner message fields", function(test) {
|
||||
}
|
||||
});
|
||||
var Outer = root.lookup("Outer");
|
||||
var msg = Outer.from({
|
||||
var msg = Outer.fromObject({
|
||||
inner: {}
|
||||
});
|
||||
var buf = Outer.encode(msg).finish();
|
||||
|
||||
@ -33,4 +33,4 @@ var hello = new Hello();
|
||||
var buf = Hello.encode(hello.foo()).finish();
|
||||
|
||||
var hello2 = Hello.decode(buf) as Hello;
|
||||
console.log(hello2.foo().asJSON());
|
||||
console.log(hello2.foo().toObject());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user