From da6af8138afa5343a47c12a8beedb99889c0dd51 Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Mon, 20 Mar 2017 20:26:47 +0100 Subject: [PATCH] New: Encoders no longer examine virtual oneof properties but encode whatever is present, see #710 --- src/encoder.js | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/encoder.js b/src/encoder.js index 260029e72..266152bb0 100644 --- a/src/encoder.js +++ b/src/encoder.js @@ -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); @@ -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 */