Permalink
Browse files

Other: In fromObject, check if object is already a runtime message, see

  • Loading branch information...
dcodeIO committed Jan 19, 2017
1 parent ea3f3b4 commit 799d0303bf289bb720f2b27af59e44c3197f3fb7
@@ -203,12 +203,12 @@ function beautifyCode(code) {
function buildFunction(type, functionName, gen, scope) {
var code = gen.str(functionName)
.replace(/\(this.ctor\)/g, " $root" + type.fullName) // types: construct directly instead of using reflected ctor
.replace(/(types\[\d+])(\.values)/g, "$1") // enums: use types[N] instead of reflected types[N].values
.replace(/\b(?!\.)Writer\b/g, "$Writer") // use common aliases instead of binding through an iife
.replace(/\b(?!\.)Reader\b/g, "$Reader") // "
.replace(/\b(?!\.)util\.\b/g, "$util.") // "
.replace(/\b(?!\.)types\[\b/g, "$types["); // "
.replace(/this\.ctor/g, " $root" + type.fullName) // types: construct directly instead of using reflected ctor
.replace(/(types\[\d+])(\.values)/g, "$1") // enums: use types[N] instead of reflected types[N].values
.replace(/\b(?!\.)Writer\b/g, "$Writer") // use common aliases instead of binding through an iife
.replace(/\b(?!\.)Reader\b/g, "$Reader") // "
.replace(/\b(?!\.)util\.\b/g, "$util.") // "
.replace(/\b(?!\.)types\[\b/g, "$types["); // "
if (config.beautify)
code = beautifyCode(code);

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

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Oops, something went wrong.

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

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Oops, something went wrong.

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

Oops, something went wrong.

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

Oops, something went wrong.
BIN -1 Byte (100%) dist/runtime/protobuf.min.js.gz
Binary file not shown.
@@ -1,6 +1,6 @@
{
"name": "protobufjs",
"version": "6.5.2",
"version": "6.5.3",
"versionScheme": "~",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
@@ -96,10 +96,13 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
converter.fromObject = function fromObject(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.fieldsArray;
if (!fields.length)
return util.codegen()("return new(this.ctor)");
var gen = util.codegen("d")
("var m=new(this.ctor)");
("if(d instanceof this.ctor)")
("return d");
if (!fields.length) return gen
("return new this.ctor");
gen
("var m=new this.ctor");
for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
prop = util.safeProp(field.name);
@@ -19,7 +19,7 @@ function decoder(mtype) {
var gen = util.codegen("r", "l")
("if(!(r instanceof Reader))")
("r=Reader.create(r)")
("var c=l===undefined?r.len:r.pos+l,m=new(this.ctor)")
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor")
("while(r.pos<c){")
("var t=r.uint32()");
if (mtype.group) gen
@@ -34,3 +34,5 @@ var buf = Hello.encode(hello.foo()).finish();
var hello2 = Hello.decode(buf) as Hello;
console.log(hello2.foo().toObject());
export var utf8 = protobuf.util.utf8;
@@ -154,6 +154,8 @@ $root.Test1 = (function() {
* @returns {Test1} Test1
*/
Test1.fromObject = function fromObject(object) {
if (object instanceof $root.Test1)
return object;
var message = new $root.Test1();
if (object.field1 !== undefined && object.field1 !== null)
message.field1 = String(object.field1);
@@ -309,7 +311,9 @@ $root.Test2 = (function() {
* @param {Object.<string,*>} object Plain object
* @returns {Test2} Test2
*/
Test2.fromObject = function fromObject() {
Test2.fromObject = function fromObject(object) {
if (object instanceof $root.Test2)
return object;
return new $root.Test2();
};
@@ -305,6 +305,8 @@ $root.Message = (function() {
* @returns {Message} Message
*/
Message.fromObject = function fromObject(object) {
if (object instanceof $root.Message)
return object;
var message = new $root.Message();
if (object.stringVal !== undefined && object.stringVal !== null)
message.stringVal = String(object.stringVal);
@@ -145,6 +145,8 @@ $root.vector_tile = (function() {
* @returns {vector_tile.Tile} Tile
*/
Tile.fromObject = function fromObject(object) {
if (object instanceof $root.vector_tile.Tile)
return object;
var message = new $root.vector_tile.Tile();
if (object.layers) {
message.layers = [];
@@ -411,6 +413,8 @@ $root.vector_tile = (function() {
* @returns {vector_tile.Tile.Value} Value
*/
Value.fromObject = function fromObject(object) {
if (object instanceof $root.vector_tile.Tile.Value)
return object;
var message = new $root.vector_tile.Tile.Value();
if (object.stringValue !== undefined && object.stringValue !== null)
message.stringValue = String(object.stringValue);
@@ -727,6 +731,8 @@ $root.vector_tile = (function() {
* @returns {vector_tile.Tile.Feature} Feature
*/
Feature.fromObject = function fromObject(object) {
if (object instanceof $root.vector_tile.Tile.Feature)
return object;
var message = new $root.vector_tile.Tile.Feature();
if (object.id !== undefined && object.id !== null)
if ($util.Long)
@@ -1043,6 +1049,8 @@ $root.vector_tile = (function() {
* @returns {vector_tile.Tile.Layer} Layer
*/
Layer.fromObject = function fromObject(object) {
if (object instanceof $root.vector_tile.Tile.Layer)
return object;
var message = new $root.vector_tile.Tile.Layer();
if (object.version !== undefined && object.version !== null)
message.version = object.version >>> 0;
@@ -436,6 +436,8 @@ $root.Package = (function() {
* @returns {Package} Package
*/
Package.fromObject = function fromObject(object) {
if (object instanceof $root.Package)
return object;
var message = new $root.Package();
if (object.name !== undefined && object.name !== null)
message.name = String(object.name);
@@ -738,6 +740,8 @@ $root.Package = (function() {
* @returns {Package.Repository} Repository
*/
Repository.fromObject = function fromObject(object) {
if (object instanceof $root.Package.Repository)
return object;
var message = new $root.Package.Repository();
if (object.type !== undefined && object.type !== null)
message.type = String(object.type);
@@ -214,6 +214,8 @@ $root.MyRequest = (function() {
* @returns {MyRequest} MyRequest
*/
MyRequest.fromObject = function fromObject(object) {
if (object instanceof $root.MyRequest)
return object;
var message = new $root.MyRequest();
if (object.path !== undefined && object.path !== null)
message.path = String(object.path);
@@ -373,6 +375,8 @@ $root.MyResponse = (function() {
* @returns {MyResponse} MyResponse
*/
MyResponse.fromObject = function fromObject(object) {
if (object instanceof $root.MyResponse)
return object;
var message = new $root.MyResponse();
if (object.status !== undefined && object.status !== null)
message.status = object.status | 0;
Oops, something went wrong.

0 comments on commit 799d030

Please sign in to comment.