Skip to content

Commit

Permalink
New: Encoders no longer examine virtual oneof properties but encode w…
Browse files Browse the repository at this point in the history
…hatever is present, see #710
  • Loading branch information
dcodeIO committed Mar 20, 2017
1 parent 68cdb5f commit da6af81
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ function encoder(mtype) {

for (var i = 0; i < fields.length; ++i) {
var field = fields[i].resolve(),
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : /* istanbul ignore next */ i;
if (field.partOf) // see below for oneofs
continue;
var type = field.resolvedType instanceof Enum ? "uint32" : field.type,
index = encoder.compat ? mtype._fieldsArray.indexOf(field) : /* istanbul ignore next */ i,
type = field.resolvedType instanceof Enum ? "uint32" : field.type,
wireType = types.basic[type];
ref = "m" + util.safeProp(field.name);

Expand Down Expand Up @@ -124,26 +122,6 @@ function encoder(mtype) {
}
}

// oneofs
for (var i = 0; i < /* initializes */ mtype.oneofsArray.length; ++i) {
var oneof = mtype._oneofsArray[i]; gen
("switch(%s){", "m" + util.safeProp(oneof.name));
for (var j = 0; j < /* direct */ oneof.fieldsArray.length; ++j) {
var field = oneof.fieldsArray[j],
type = field.resolvedType instanceof Enum ? "uint32" : field.type,
wireType = types.basic[type];
ref = "m" + util.safeProp(field.name); gen
("case%j:", field.name);
if (wireType === undefined)
genTypePartial(gen, field, mtype._fieldsArray.indexOf(field), ref);
else gen
("w.uint32(%d).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
gen
("break");
} gen
("}");
}

return gen
("return w");
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
Expand Down

0 comments on commit da6af81

Please sign in to comment.