diff --git a/README.md b/README.md
index 329eb5081..36c98bcfb 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
-#
![](./pbjs.png)
+# ![protobuf.js](./pbjs.png)
[![travis][travis-image]][travis-url] [![david][david-image]][david-url] [![npm][npm-dl-image]][npm-url] [![npm][npm-image]][npm-url] [![donate][paypal-image]][paypal-url]
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/)).
-**protobuf.js** is a pure JavaScript implementation with TypeScript support for node and the browser. It efficiently encodes all teh codez and works out of the box with .proto files.
+**protobuf.js** is a pure JavaScript implementation with TypeScript support for node and the browser. It's super easy to use and works out of the box on .proto files!
[travis-image]: https://img.shields.io/travis/dcodeIO/protobuf.js.svg
[travis-url]: https://travis-ci.org/dcodeIO/protobuf.js
diff --git a/bench/index.js b/bench/index.js
index 35159ce64..4fdbc427c 100644
--- a/bench/index.js
+++ b/bench/index.js
@@ -29,6 +29,7 @@ var root = protobuf.loadSync(require.resolve("./bench.proto")),
var buf = Test.encode(data).finish();
// warm up
+process.stdout.write("warming up ...\n");
var i;
for (i = 0; i < 500000; ++i)
Test.encode(data).finish();
diff --git a/index.d.ts b/index.d.ts
index e2874cff8..9d408b349 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,6 +1,3 @@
-// $> pbts --main --global protobuf --out index.d.ts src
-// Generated Tue, 03 Jan 2017 23:45:16 UTC
-
export as namespace protobuf;
/**
diff --git a/src/converter.js b/src/converter.js
index 234f3eb7d..f58cd1491 100644
--- a/src/converter.js
+++ b/src/converter.js
@@ -64,9 +64,14 @@ function converter(mtype) {
("d%s=[]", prop);
// non-repeated
- } else if (convert = genConvert(field, i, prop)) gen
- ("d%s=%s", prop, convert);
- else gen
+ } else if (convert = genConvert(field, i, prop)) {
+ if (field.long || field.resolvedType && !(field.resolvedType instanceof Enum)) gen
+ ("if(s%s!==undefined&&s%s!==null||o.defaults)", prop, prop);
+ else gen
+ ("if(s%s!==undefined||o.defaults)", prop);
+ gen
+ ("d%s=%s", prop, convert);
+ } else gen
("if(d%s===undefined&&o.defaults)", prop)
("d%s=%j", prop, field.typeDefault /* == field.defaultValue */);
diff --git a/src/util.js b/src/util.js
index 4c7d8571c..39afc9284 100644
--- a/src/util.js
+++ b/src/util.js
@@ -30,23 +30,6 @@ util.toArray = function toArray(object) {
}) : [];
};
-/**
- * Merges the properties of the source object into the destination object.
- * @param {Object.} dst Destination object
- * @param {Object.} src Source object
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
- * @returns {Object.} Destination object
- */
-util.merge = function merge(dst, src, ifNotSet) {
- if (src) {
- var keys = Object.keys(src);
- for (var i = 0; i < keys.length; ++i)
- if (dst[keys[i]] === undefined || !ifNotSet)
- dst[keys[i]] = src[keys[i]];
- }
- return dst;
-};
-
/**
* Returns a safe property accessor for the specified properly name.
* @param {string} prop Property name
diff --git a/src/util/runtime.js b/src/util/runtime.js
index 97c7f858f..7dbd26302 100644
--- a/src/util/runtime.js
+++ b/src/util/runtime.js
@@ -148,3 +148,20 @@ util.arrayNe = function arrayNe(a, b) {
return true;
return false;
};
+
+/**
+ * Merges the properties of the source object into the destination object.
+ * @param {Object.} dst Destination object
+ * @param {Object.} src Source object
+ * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
+ * @returns {Object.} Destination object
+ */
+util.merge = function merge(dst, src, ifNotSet) {
+ if (src) {
+ var keys = Object.keys(src);
+ for (var i = 0; i < keys.length; ++i)
+ if (dst[keys[i]] === undefined || !ifNotSet)
+ dst[keys[i]] = src[keys[i]];
+ }
+ return dst;
+};
diff --git a/tests/data/ambiguous-names.js b/tests/data/ambiguous-names.js
index 3bf2b9659..fb4ace337 100644
--- a/tests/data/ambiguous-names.js
+++ b/tests/data/ambiguous-names.js
@@ -134,7 +134,7 @@ $root.A = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.whatever === undefined && options.defaults) {
dst.whatever = "";
@@ -294,9 +294,11 @@ $root.B = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
- dst.A = types[0].convert(src.A, impl, options);
+ if (!(src.A === undefined || src.A === null) || options.defaults) {
+ dst.A = types[0].convert(src.A, impl, options);
+ }
}
return dst;
};})($types);
diff --git a/tests/data/extend.proto b/tests/data/extend.proto
index 7bbb48fcb..c4f33d4bb 100644
--- a/tests/data/extend.proto
+++ b/tests/data/extend.proto
@@ -9,7 +9,7 @@ message A {
message C {
message Two {
extend B.One {
- Two two = 1000;
+ C.Two two = 1000;
}
}
}
diff --git a/tests/data/mapbox/vector_tile.js b/tests/data/mapbox/vector_tile.js
index 5b5f9dc63..38eac17a4 100644
--- a/tests/data/mapbox/vector_tile.js
+++ b/tests/data/mapbox/vector_tile.js
@@ -157,7 +157,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.layers && src.layers.length) {
dst.layers = [];
@@ -445,7 +445,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.stringValue === undefined && options.defaults) {
dst.stringValue = "";
@@ -456,9 +456,15 @@ $root.vector_tile = (function() {
if (dst.doubleValue === undefined && options.defaults) {
dst.doubleValue = 0;
}
- dst.intValue = impl.longs(src.intValue, 0, 0, false, options);
- dst.uintValue = impl.longs(src.uintValue, 0, 0, true, options);
- dst.sintValue = impl.longs(src.sintValue, 0, 0, false, options);
+ if (!(src.intValue === undefined || src.intValue === null) || options.defaults) {
+ dst.intValue = impl.longs(src.intValue, 0, 0, false, options);
+ }
+ if (!(src.uintValue === undefined || src.uintValue === null) || options.defaults) {
+ dst.uintValue = impl.longs(src.uintValue, 0, 0, true, options);
+ }
+ if (!(src.sintValue === undefined || src.sintValue === null) || options.defaults) {
+ dst.sintValue = impl.longs(src.sintValue, 0, 0, false, options);
+ }
if (dst.boolValue === undefined && options.defaults) {
dst.boolValue = false;
}
@@ -715,9 +721,11 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
- dst.id = impl.longs(src.id, 0, 0, true, options);
+ if (!(src.id === undefined || src.id === null) || options.defaults) {
+ 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) {
@@ -728,7 +736,9 @@ $root.vector_tile = (function() {
dst.tags = [];
}
}
- dst.type = impl.enums(src.type, undefined, types[2], options);
+ if (!(src.type === undefined || src.type === null) || options.defaults) {
+ 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) {
@@ -1007,7 +1017,7 @@ $root.vector_tile = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.version === undefined && options.defaults) {
dst.version = 1;
diff --git a/tests/data/package.js b/tests/data/package.js
index f1e1469ee..b740a68f2 100644
--- a/tests/data/package.js
+++ b/tests/data/package.js
@@ -503,7 +503,7 @@ $root.Package = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -520,7 +520,9 @@ $root.Package = (function() {
if (dst.license === undefined && options.defaults) {
dst.license = "";
}
- dst.repository = types[5].convert(src.repository, impl, options);
+ if (!(src.repository === undefined || src.repository === null) || options.defaults) {
+ dst.repository = types[5].convert(src.repository, impl, options);
+ }
if (dst.bugs === undefined && options.defaults) {
dst.bugs = "";
}
@@ -724,7 +726,7 @@ $root.Package = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.type === undefined && options.defaults) {
dst.type = "";
diff --git a/tests/data/rpc.js b/tests/data/rpc.js
index 46846fffa..66490b061 100644
--- a/tests/data/rpc.js
+++ b/tests/data/rpc.js
@@ -226,7 +226,7 @@ $root.MyRequest = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.path === undefined && options.defaults) {
dst.path = "";
@@ -382,7 +382,7 @@ $root.MyResponse = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.status === undefined && options.defaults) {
dst.status = 0;
diff --git a/tests/data/test.js b/tests/data/test.js
index bd89135ec..71cdda308 100644
--- a/tests/data/test.js
+++ b/tests/data/test.js
@@ -134,7 +134,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -309,9 +309,11 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
- dst.outerEnum = impl.enums(src.outerEnum, 1, types[0], options);
+ if (!(src.outerEnum === undefined || src.outerEnum === null) || options.defaults) {
+ dst.outerEnum = impl.enums(src.outerEnum, 1, types[0], options);
+ }
}
return dst;
};})($types);
@@ -505,7 +507,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.aString === undefined && options.defaults) {
dst.aString = "";
@@ -698,7 +700,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.aString === undefined && options.defaults) {
dst.aString = "";
@@ -905,7 +907,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.normal === undefined && options.defaults) {
dst.normal = "";
@@ -1163,7 +1165,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.aString === undefined && options.defaults) {
dst.aString = "";
@@ -1171,7 +1173,9 @@ $root.jspb = (function() {
if (dst.aBool === undefined && options.defaults) {
dst.aBool = false;
}
- dst.aNestedMessage = types[2].convert(src.aNestedMessage, impl, options);
+ if (!(src.aNestedMessage === undefined || src.aNestedMessage === null) || options.defaults) {
+ dst.aNestedMessage = types[2].convert(src.aNestedMessage, impl, options);
+ }
if (src.aRepeatedMessage && src.aRepeatedMessage.length) {
dst.aRepeatedMessage = [];
for (var i = 0; i < src.aRepeatedMessage.length; ++i) {
@@ -1340,7 +1344,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.anInt === undefined && options.defaults) {
dst.anInt = 0;
@@ -1676,7 +1680,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.str1 === undefined && options.defaults) {
dst.str1 = "";
@@ -1687,8 +1691,12 @@ $root.jspb = (function() {
if (dst.str3 === undefined && options.defaults) {
dst.str3 = "";
}
- dst[".jspb.test.IsExtension.extField"] = types[3].convert(src[".jspb.test.IsExtension.extField"], impl, options);
- dst[".jspb.test.IndirectExtension.simple"] = types[4].convert(src[".jspb.test.IndirectExtension.simple"], impl, options);
+ if (!(src[".jspb.test.IsExtension.extField"] === undefined || src[".jspb.test.IsExtension.extField"] === null) || options.defaults) {
+ dst[".jspb.test.IsExtension.extField"] = types[3].convert(src[".jspb.test.IsExtension.extField"], impl, options);
+ }
+ if (!(src[".jspb.test.IndirectExtension.simple"] === undefined || src[".jspb.test.IndirectExtension.simple"] === null) || options.defaults) {
+ dst[".jspb.test.IndirectExtension.simple"] = types[4].convert(src[".jspb.test.IndirectExtension.simple"], impl, options);
+ }
if (dst[".jspb.test.IndirectExtension.str"] === undefined && options.defaults) {
dst[".jspb.test.IndirectExtension.str"] = "";
}
@@ -1712,7 +1720,9 @@ $root.jspb = (function() {
dst[".jspb.test.IndirectExtension.repeatedSimple"] = [];
}
}
- dst[".jspb.test.simple1"] = types[8].convert(src[".jspb.test.simple1"], impl, options);
+ if (!(src[".jspb.test.simple1"] === undefined || src[".jspb.test.simple1"] === null) || options.defaults) {
+ dst[".jspb.test.simple1"] = types[8].convert(src[".jspb.test.simple1"], impl, options);
+ }
}
return dst;
};})($types);
@@ -1953,7 +1963,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.aString === undefined && options.defaults) {
dst.aString = "";
@@ -1961,7 +1971,9 @@ $root.jspb = (function() {
if (dst.anOutOfOrderBool === undefined && options.defaults) {
dst.anOutOfOrderBool = false;
}
- dst.aNestedMessage = types[2].convert(src.aNestedMessage, impl, options);
+ if (!(src.aNestedMessage === undefined || src.aNestedMessage === null) || options.defaults) {
+ dst.aNestedMessage = types[2].convert(src.aNestedMessage, impl, options);
+ }
if (src.aRepeatedMessage && src.aRepeatedMessage.length) {
dst.aRepeatedMessage = [];
for (var i = 0; i < src.aRepeatedMessage.length; ++i) {
@@ -2126,7 +2138,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.anInt === undefined && options.defaults) {
dst.anInt = 0;
@@ -2267,7 +2279,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -2415,7 +2427,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.innerComplexField === undefined && options.defaults) {
dst.innerComplexField = 0;
@@ -2574,7 +2586,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.ext1 === undefined && options.defaults) {
dst.ext1 = "";
@@ -2712,7 +2724,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -2961,7 +2973,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.stringField === undefined && options.defaults) {
dst.stringField = "default<>'\"abc";
@@ -2969,12 +2981,18 @@ $root.jspb = (function() {
if (dst.boolField === undefined && options.defaults) {
dst.boolField = true;
}
- dst.intField = impl.longs(src.intField, 0, 0, false, options);
- dst.enumField = impl.enums(src.enumField, undefined, types[3], options);
+ if (!(src.intField === undefined || src.intField === null) || options.defaults) {
+ dst.intField = impl.longs(src.intField, 0, 0, false, options);
+ }
+ if (!(src.enumField === undefined || src.enumField === null) || options.defaults) {
+ dst.enumField = impl.enums(src.enumField, undefined, types[3], options);
+ }
if (dst.emptyField === undefined && options.defaults) {
dst.emptyField = "";
}
- dst.bytesField = impl.bytes(src.bytesField, [ 109, 111, 111 ], options);
+ if (!(src.bytesField === undefined || src.bytesField === null) || options.defaults) {
+ dst.bytesField = impl.bytes(src.bytesField, [ 109, 111, 111 ], options);
+ }
}
return dst;
};})($types);
@@ -3280,7 +3298,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.optionalFloatField === undefined && options.defaults) {
dst.optionalFloatField = 0;
@@ -3578,12 +3596,14 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.str === undefined && options.defaults) {
dst.str = "";
}
- dst.simple1 = types[1].convert(src.simple1, impl, options);
+ if (!(src.simple1 === undefined || src.simple1 === null) || options.defaults) {
+ dst.simple1 = types[1].convert(src.simple1, impl, options);
+ }
if (src.simple2 && src.simple2.length) {
dst.simple2 = [];
for (var i = 0; i < src.simple2.length; ++i) {
@@ -3594,11 +3614,15 @@ $root.jspb = (function() {
dst.simple2 = [];
}
}
- dst.bytesField = impl.bytes(src.bytesField, [], options);
+ if (!(src.bytesField === undefined || src.bytesField === null) || options.defaults) {
+ dst.bytesField = impl.bytes(src.bytesField, [], options);
+ }
if (dst.unused === undefined && options.defaults) {
dst.unused = "";
}
- dst[".jspb.test.CloneExtension.extField"] = types[5].convert(src[".jspb.test.CloneExtension.extField"], impl, options);
+ if (!(src[".jspb.test.CloneExtension.extField"] === undefined || src[".jspb.test.CloneExtension.extField"] === null) || options.defaults) {
+ dst[".jspb.test.CloneExtension.extField"] = types[5].convert(src[".jspb.test.CloneExtension.extField"], impl, options);
+ }
}
return dst;
};})($types);
@@ -3750,7 +3774,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.ext === undefined && options.defaults) {
dst.ext = "";
@@ -3943,13 +3967,17 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.id === undefined && options.defaults) {
dst.id = "";
}
- dst.requiredSimple = types[1].convert(src.requiredSimple, impl, options);
- dst.optionalSimple = types[2].convert(src.optionalSimple, impl, options);
+ if (!(src.requiredSimple === undefined || src.requiredSimple === null) || options.defaults) {
+ dst.requiredSimple = types[1].convert(src.requiredSimple, impl, options);
+ }
+ if (!(src.optionalSimple === undefined || src.optionalSimple === null) || options.defaults) {
+ dst.optionalSimple = types[2].convert(src.optionalSimple, impl, options);
+ }
}
return dst;
};})($types);
@@ -4120,7 +4148,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.extension === undefined && options.defaults) {
dst.extension = 0;
@@ -4261,7 +4289,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -4684,7 +4712,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.pone === undefined && options.defaults) {
dst.pone = "";
@@ -4692,7 +4720,9 @@ $root.jspb = (function() {
if (dst.pthree === undefined && options.defaults) {
dst.pthree = "";
}
- dst.rone = types[2].convert(src.rone, impl, options);
+ if (!(src.rone === undefined || src.rone === null) || options.defaults) {
+ dst.rone = types[2].convert(src.rone, impl, options);
+ }
if (dst.rtwo === undefined && options.defaults) {
dst.rtwo = "";
}
@@ -4890,12 +4920,14 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.value === undefined && options.defaults) {
dst.value = 0;
}
- dst.data = impl.bytes(src.data, [], options);
+ if (!(src.data === undefined || src.data === null) || options.defaults) {
+ dst.data = impl.bytes(src.data, [], options);
+ }
}
return dst;
};})();
@@ -5455,7 +5487,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.mapStringString === undefined && options.defaults) {
dst.mapStringString = "";
@@ -5463,15 +5495,21 @@ $root.jspb = (function() {
if (dst.mapStringInt32 === undefined && options.defaults) {
dst.mapStringInt32 = 0;
}
- dst.mapStringInt64 = impl.longs(src.mapStringInt64, 0, 0, false, options);
+ if (!(src.mapStringInt64 === undefined || src.mapStringInt64 === null) || options.defaults) {
+ dst.mapStringInt64 = impl.longs(src.mapStringInt64, 0, 0, false, options);
+ }
if (dst.mapStringBool === undefined && options.defaults) {
dst.mapStringBool = false;
}
if (dst.mapStringDouble === undefined && options.defaults) {
dst.mapStringDouble = 0;
}
- dst.mapStringEnum = impl.enums(src.mapStringEnum, 0, types[5], options);
- dst.mapStringMsg = types[6].convert(src.mapStringMsg, impl, options);
+ if (!(src.mapStringEnum === undefined || src.mapStringEnum === null) || options.defaults) {
+ dst.mapStringEnum = impl.enums(src.mapStringEnum, 0, types[5], options);
+ }
+ if (!(src.mapStringMsg === undefined || src.mapStringMsg === null) || options.defaults) {
+ dst.mapStringMsg = types[6].convert(src.mapStringMsg, impl, options);
+ }
if (dst.mapInt32String === undefined && options.defaults) {
dst.mapInt32String = "";
}
@@ -5481,8 +5519,12 @@ $root.jspb = (function() {
if (dst.mapBoolString === undefined && options.defaults) {
dst.mapBoolString = "";
}
- dst.testMapFields = types[10].convert(src.testMapFields, impl, options);
- dst.mapStringTestmapfields = types[11].convert(src.mapStringTestmapfields, impl, options);
+ if (!(src.testMapFields === undefined || src.testMapFields === null) || options.defaults) {
+ dst.testMapFields = types[10].convert(src.testMapFields, impl, options);
+ }
+ if (!(src.mapStringTestmapfields === undefined || src.mapStringTestmapfields === null) || options.defaults) {
+ dst.mapStringTestmapfields = types[11].convert(src.mapStringTestmapfields, impl, options);
+ }
}
return dst;
};})($types);
@@ -5652,7 +5694,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.foo === undefined && options.defaults) {
dst.foo = 0;
@@ -5790,7 +5832,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -5920,7 +5962,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
return dst;
};})();
@@ -6068,7 +6110,7 @@ $root.jspb = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.count === undefined && options.defaults) {
dst.count = 0;
@@ -6268,7 +6310,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.file && src.file.length) {
dst.file = [];
@@ -6709,7 +6751,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -6787,8 +6829,12 @@ $root.google = (function() {
dst.extension = [];
}
}
- dst.options = types[9].convert(src.options, impl, options);
- dst.sourceCodeInfo = types[10].convert(src.sourceCodeInfo, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[9].convert(src.options, impl, options);
+ }
+ if (!(src.sourceCodeInfo === undefined || src.sourceCodeInfo === null) || options.defaults) {
+ dst.sourceCodeInfo = types[10].convert(src.sourceCodeInfo, impl, options);
+ }
if (dst.syntax === undefined && options.defaults) {
dst.syntax = "";
}
@@ -7196,7 +7242,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -7261,7 +7307,9 @@ $root.google = (function() {
dst.oneofDecl = [];
}
}
- dst.options = types[7].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[7].convert(src.options, impl, options);
+ }
if (src.reservedRange && src.reservedRange.length) {
dst.reservedRange = [];
for (var i = 0; i < src.reservedRange.length; ++i) {
@@ -7448,7 +7496,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.start === undefined && options.defaults) {
dst.start = 0;
@@ -7625,7 +7673,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.start === undefined && options.defaults) {
dst.start = 0;
@@ -7980,7 +8028,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -7988,8 +8036,12 @@ $root.google = (function() {
if (dst.number === undefined && options.defaults) {
dst.number = 0;
}
- dst.label = impl.enums(src.label, 1, types[2], options);
- dst.type = impl.enums(src.type, 1, types[3].values, options);
+ if (!(src.label === undefined || src.label === null) || options.defaults) {
+ dst.label = impl.enums(src.label, 1, types[2], options);
+ }
+ if (!(src.type === undefined || src.type === null) || options.defaults) {
+ dst.type = impl.enums(src.type, 1, types[3].values, options);
+ }
if (dst.typeName === undefined && options.defaults) {
dst.typeName = "";
}
@@ -8005,7 +8057,9 @@ $root.google = (function() {
if (dst.jsonName === undefined && options.defaults) {
dst.jsonName = "";
}
- dst.options = types[9].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[9].convert(src.options, impl, options);
+ }
}
return dst;
};})($types);
@@ -8245,12 +8299,14 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
}
- dst.options = types[1].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[1].convert(src.options, impl, options);
+ }
}
return dst;
};})($types);
@@ -8453,7 +8509,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -8468,7 +8524,9 @@ $root.google = (function() {
dst.value = [];
}
}
- dst.options = types[2].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[2].convert(src.options, impl, options);
+ }
}
return dst;
};})($types);
@@ -8660,7 +8718,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -8668,7 +8726,9 @@ $root.google = (function() {
if (dst.number === undefined && options.defaults) {
dst.number = 0;
}
- dst.options = types[2].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[2].convert(src.options, impl, options);
+ }
}
return dst;
};})($types);
@@ -8871,7 +8931,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -8886,7 +8946,9 @@ $root.google = (function() {
dst.method = [];
}
}
- dst.options = types[2].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[2].convert(src.options, impl, options);
+ }
}
return dst;
};})($types);
@@ -9132,7 +9194,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.name === undefined && options.defaults) {
dst.name = "";
@@ -9143,7 +9205,9 @@ $root.google = (function() {
if (dst.outputType === undefined && options.defaults) {
dst.outputType = "";
}
- dst.options = types[3].convert(src.options, impl, options);
+ if (!(src.options === undefined || src.options === null) || options.defaults) {
+ dst.options = types[3].convert(src.options, impl, options);
+ }
if (dst.clientStreaming === undefined && options.defaults) {
dst.clientStreaming = false;
}
@@ -9573,7 +9637,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.javaPackage === undefined && options.defaults) {
dst.javaPackage = "";
@@ -9590,7 +9654,9 @@ $root.google = (function() {
if (dst.javaStringCheckUtf8 === undefined && options.defaults) {
dst.javaStringCheckUtf8 = false;
}
- dst.optimizeFor = impl.enums(src.optimizeFor, undefined, types[5], options);
+ if (!(src.optimizeFor === undefined || src.optimizeFor === null) || options.defaults) {
+ dst.optimizeFor = impl.enums(src.optimizeFor, undefined, types[5], options);
+ }
if (dst.goPackage === undefined && options.defaults) {
dst.goPackage = "";
}
@@ -9880,7 +9946,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.messageSetWireFormat === undefined && options.defaults) {
dst.messageSetWireFormat = false;
@@ -10189,13 +10255,17 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
- dst.ctype = impl.enums(src.ctype, undefined, types[0], options);
+ if (!(src.ctype === undefined || src.ctype === null) || options.defaults) {
+ dst.ctype = impl.enums(src.ctype, undefined, types[0], options);
+ }
if (dst.packed === undefined && options.defaults) {
dst.packed = false;
}
- dst.jstype = impl.enums(src.jstype, undefined, types[2].values, options);
+ if (!(src.jstype === undefined || src.jstype === null) || options.defaults) {
+ dst.jstype = impl.enums(src.jstype, undefined, types[2].values, options);
+ }
if (dst.lazy === undefined && options.defaults) {
dst.lazy = false;
}
@@ -10416,7 +10486,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.uninterpretedOption && src.uninterpretedOption.length) {
dst.uninterpretedOption = [];
@@ -10648,7 +10718,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.allowAlias === undefined && options.defaults) {
dst.allowAlias = false;
@@ -10852,7 +10922,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.deprecated === undefined && options.defaults) {
dst.deprecated = false;
@@ -11050,7 +11120,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.deprecated === undefined && options.defaults) {
dst.deprecated = false;
@@ -11272,12 +11342,14 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.deprecated === undefined && options.defaults) {
dst.deprecated = false;
}
- dst.idempotencyLevel = impl.enums(src.idempotencyLevel, undefined, types[1], options);
+ if (!(src.idempotencyLevel === undefined || src.idempotencyLevel === null) || options.defaults) {
+ dst.idempotencyLevel = impl.enums(src.idempotencyLevel, undefined, types[1], options);
+ }
if (src.uninterpretedOption && src.uninterpretedOption.length) {
dst.uninterpretedOption = [];
for (var i = 0; i < src.uninterpretedOption.length; ++i) {
@@ -11579,7 +11651,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.name && src.name.length) {
dst.name = [];
@@ -11594,12 +11666,18 @@ $root.google = (function() {
if (dst.identifierValue === undefined && options.defaults) {
dst.identifierValue = "";
}
- dst.positiveIntValue = impl.longs(src.positiveIntValue, 0, 0, true, options);
- dst.negativeIntValue = impl.longs(src.negativeIntValue, 0, 0, false, options);
+ if (!(src.positiveIntValue === undefined || src.positiveIntValue === null) || options.defaults) {
+ dst.positiveIntValue = impl.longs(src.positiveIntValue, 0, 0, true, options);
+ }
+ if (!(src.negativeIntValue === undefined || src.negativeIntValue === null) || options.defaults) {
+ dst.negativeIntValue = impl.longs(src.negativeIntValue, 0, 0, false, options);
+ }
if (dst.doubleValue === undefined && options.defaults) {
dst.doubleValue = 0;
}
- dst.stringValue = impl.bytes(src.stringValue, [], options);
+ if (!(src.stringValue === undefined || src.stringValue === null) || options.defaults) {
+ dst.stringValue = impl.bytes(src.stringValue, [], options);
+ }
if (dst.aggregateValue === undefined && options.defaults) {
dst.aggregateValue = "";
}
@@ -11761,7 +11839,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (dst.namePart === undefined && options.defaults) {
dst.namePart = "";
@@ -11937,7 +12015,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.location && src.location.length) {
dst.location = [];
@@ -12217,7 +12295,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.path && src.path.length) {
dst.path = [];
@@ -12423,7 +12501,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.annotation && src.annotation.length) {
dst.annotation = [];
@@ -12656,7 +12734,7 @@ $root.google = (function() {
if (!options) {
options = {};
}
- var dst = impl.create(src, this, options);
+ var dst = impl.create(src, this, options) || null;
if (dst) {
if (src.path && src.path.length) {
dst.path = [];