Skip to content

Commit

Permalink
Fixed: Fixed invalid definition of Field#packed property, also introd…
Browse files Browse the repository at this point in the history
…uced decoder.compat mode (packed fields, on by default)
  • Loading branch information
dcodeIO committed Jan 6, 2017
1 parent 11fb1a6 commit c2c39fc
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 24 deletions.
9 changes: 6 additions & 3 deletions dist/noparse/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/noparse/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/noparse/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/noparse/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/noparse/protobuf.min.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ interface MessageConversionOptions {
* Generates a decoder specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
* @property {boolean} compat=true Generates backward/forward compatible decoders (packed fields)
*/
export function decoder(mtype: Type): Codegen;

Expand Down
5 changes: 4 additions & 1 deletion src/decoder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
module.exports = decoder;

decoder.compat = true;

var Enum = require("./enum"),
types = require("./types"),
util = require("./util");
Expand All @@ -9,6 +11,7 @@ var Enum = require("./enum"),
* Generates a decoder specific to the specified message type.
* @param {Type} mtype Message type
* @returns {Codegen} Codegen instance
* @property {boolean} compat=true Generates backward/forward compatible decoders (packed fields)
*/
function decoder(mtype) {
/* eslint-disable no-unexpected-multiline */
Expand Down Expand Up @@ -56,7 +59,7 @@ function decoder(mtype) {
("%s=[]", ref);

// Packable (always check for forward and backward compatiblity)
if (/* field.packed && */types.packed[type] !== undefined) gen
if ((decoder.compat || field.packed) && types.packed[type] !== undefined) gen
("if((t&7)===2){")
("var c2=r.uint32()+r.pos")
("while(r.pos<c2)")
Expand Down
2 changes: 1 addition & 1 deletion src/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function Field(name, id, type, rule, extend, options) {
* @type {boolean}
* @readonly
*/
Object.defineProperties(FieldPrototype, {
Object.defineProperty(FieldPrototype, "packed", {
get: function() {
// defaults to packed=true if not explicity set to false
if (this._packed === null)
Expand Down
36 changes: 32 additions & 4 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3189,7 +3189,14 @@ $root.jspb = (function() {
if (!(message.repeatedFloatField && message.repeatedFloatField.length)) {
message.repeatedFloatField = [];
}
message.repeatedFloatField.push(reader.float());
if ((tag & 7) === 2) {
var end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.repeatedFloatField.push(reader.float());
}
} else {
message.repeatedFloatField.push(reader.float());
}
break;

case 4:
Expand All @@ -3208,7 +3215,14 @@ $root.jspb = (function() {
if (!(message.repeatedDoubleField && message.repeatedDoubleField.length)) {
message.repeatedDoubleField = [];
}
message.repeatedDoubleField.push(reader.double());
if ((tag & 7) === 2) {
var end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.repeatedDoubleField.push(reader.double());
}
} else {
message.repeatedDoubleField.push(reader.double());
}
break;

case 8:
Expand Down Expand Up @@ -6563,14 +6577,28 @@ $root.google = (function() {
if (!(message.publicDependency && message.publicDependency.length)) {
message.publicDependency = [];
}
message.publicDependency.push(reader.int32());
if ((tag & 7) === 2) {
var end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.publicDependency.push(reader.int32());
}
} else {
message.publicDependency.push(reader.int32());
}
break;

case 11:
if (!(message.weakDependency && message.weakDependency.length)) {
message.weakDependency = [];
}
message.weakDependency.push(reader.int32());
if ((tag & 7) === 2) {
var end2 = reader.uint32() + reader.pos;
while (reader.pos < end2) {
message.weakDependency.push(reader.int32());
}
} else {
message.weakDependency.push(reader.int32());
}
break;

case 4:
Expand Down

0 comments on commit c2c39fc

Please sign in to comment.