lib/converter.js
function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
  if (field.resolvedType) {
    if (field.resolvedType instanceof Enum) {
      gen('switch(d%s){', prop);
      for (let values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
        if (field.repeated && values[keys[i]] === field.typeDefault) gen('default:');
        gen('case%j:', keys[i])('case %i:', values[keys[i]])('m%s=%j', prop, values[keys[i]])('break');
      }
      gen('}');
    } else {
      gen('if(typeof d%s!=="object")', prop)('throw TypeError(%j)', field.fullName + ': object expected')('m%s=types[%i].fromObject(d%s)', prop, fieldIndex, prop);
    }
  } else {
    let isUnsigned = false;
    switch (field.type) {
      case 'double':
      case 'float':
        gen('m%s=Number(d%s)', prop, prop); // also catches "NaN", "Infinity"
        break;
      case 'uint32':
      case 'fixed32':
        gen('m%s=d%s>>>0', prop, prop);
        break;
      case 'int32':
      case 'sint32':
      case 'sfixed32':
        gen('m%s=d%s|0', prop, prop);
        break;
      case 'uint64':
        isUnsigned = true;
        // eslint-disable-line no-fallthrough
      case 'int64':
      case 'sint64':
      case 'fixed64':
      case 'sfixed64':
        gen('if(util.Long)')('(m%s=util.Long.fromValue(d%s)).unsigned=%j', prop, prop, isUnsigned)('else if(typeof d%s==="string")', prop)('m%s=parseInt(d%s,10)', prop, prop)('else if(typeof d%s==="number")', prop)('m%s=d%s', prop, prop)('else if(typeof d%s==="object")', prop)('m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)', prop, prop, prop, isUnsigned ? 'true' : '');
        break;
      case 'bytes':
        gen('if(typeof d%s==="string")', prop)('util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)', prop, prop, prop)('else if(d%s.length)', prop)('m%s=d%s', prop, prop);
        break;
      case 'string':
        gen('m%s=String(d%s)', prop, prop);
        break;
      case 'bool':
        gen('m%s=Boolean(d%s)', prop, prop);
        break;
      default:
        break;
        /* default: gen
            ("m%s=d%s", prop, prop);
            break; */
    }
  }
  return gen;
}
function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
  if (field.resolvedType) {
    if (field.resolvedType instanceof Enum) {
      gen('switch(d%s){', prop);
      for (let values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
        if (field.repeated && values[keys[i]] === field.typeDefault) gen('default:');
        gen('case%j:', keys[i])('case %i:', values[keys[i]])('m%s=%j', prop, values[keys[i]])('break');
      }
      gen('}');
    } else {
      gen('if(typeof d%s!=="object")', prop)('throw TypeError(%j)', field.fullName + ': object expected')('m%s=types[%i].fromObject(d%s)', prop, fieldIndex, prop);
    }
  } else {
    let isUnsigned = false;
    switch (field.type) {
      case 'double':
      case 'float':
        gen('m%s=Number(d%s)', prop, prop); // also catches "NaN", "Infinity"
        break;
      case 'uint32':
      case 'fixed32':
        gen('m%s=d%s>>>0', prop, prop);
        break;
      case 'int32':
      case 'sint32':
      case 'sfixed32':
        gen('m%s=d%s|0', prop, prop);
        break;
      case 'uint64':
        isUnsigned = true;
        // eslint-disable-line no-fallthrough
      case 'int64':
      case 'sint64':
      case 'fixed64':
      case 'sfixed64':
        gen('if(util.Long)')('(m%s=util.Long.fromValue(d%s)).unsigned=%j', prop, prop, isUnsigned)('else if(typeof d%s==="string")', prop)('m%s=parseInt(d%s,10)', prop, prop)('else if(typeof d%s==="number")', prop)('m%s=d%s', prop, prop)('else if(typeof d%s==="object")', prop)('m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)', prop, prop, prop, isUnsigned ? 'true' : '');
        break;
      case 'bytes':
        gen('if(typeof d%s==="string")', prop)('util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)', prop, prop, prop)('else if(d%s.length)', prop)('m%s=d%s', prop, prop);
        break;
      case 'string':
        gen('m%s=String(d%s)', prop, prop);
        break;
      case 'bool':
        gen('m%s=Boolean(d%s)', prop, prop);
        break;
      default:
        break;
        /* default: gen
            ("m%s=d%s", prop, prop);
            break; */
    }
  }
  return gen;
}
function genValuePartial_fromObject ( gen , field , fieldIndex , prop ) { if ( field . resolvedType ) { if ( field . resolvedType instanceof Enum ) { gen ( 'switch(d%s){' , prop ) ; for ( let values = field . resolvedType . values , keys = Object . keys ( values ) , i = 0 ; i < keys . length ; ++ i ) { if ( field . repeated && values [ keys [ i ] ] === field . typeDefault ) gen ( 'default:' ) ; gen ( 'case%j:' , keys [ i ] ) ( 'case %i:' , values [ keys [ i ] ] ) ( 'm%s=%j' , prop , values [ keys [ i ] ] ) ( 'break' ) ; } gen ( '}' ) ; } else { gen ( 'if(typeof d%s!=="object")' , prop ) ( 'throw TypeError(%j)' , field . fullName + ': object expected' ) ( 'm%s=types[%i].fromObject(d%s)' , prop , fieldIndex , prop ) ; } } else { let isUnsigned = false ; switch ( field . type ) { case 'double' : case 'float' : gen ( 'm%s=Number(d%s)' , prop , prop ) ; // also catches "NaN", "Infinity" break ; case 'uint32' : case 'fixed32' : gen ( 'm%s=d%s>>>0' , prop , prop ) ; break ; case 'int32' : case 'sint32' : case 'sfixed32' : gen ( 'm%s=d%s|0' , prop , prop ) ; break ; case 'uint64' : isUnsigned = true ; // eslint-disable-line no-fallthrough case 'int64' : case 'sint64' : case 'fixed64' : case 'sfixed64' : gen ( 'if(util.Long)' ) ( '(m%s=util.Long.fromValue(d%s)).unsigned=%j' , prop , prop , isUnsigned ) ( 'else if(typeof d%s==="string")' , prop ) ( 'm%s=parseInt(d%s,10)' , prop , prop ) ( 'else if(typeof d%s==="number")' , prop ) ( 'm%s=d%s' , prop , prop ) ( 'else if(typeof d%s==="object")' , prop ) ( 'm%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)' , prop , prop , prop , isUnsigned ? 'true' : '' ) ; break ; case 'bytes' : gen ( 'if(typeof d%s==="string")' , prop ) ( 'util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)' , prop , prop , prop ) ( 'else if(d%s.length)' , prop ) ( 'm%s=d%s' , prop , prop ) ; break ; case 'string' : gen ( 'm%s=String(d%s)' , prop , prop ) ; break ; case 'bool' : gen ( 'm%s=Boolean(d%s)' , prop , prop ) ; break ; default : break ; /* default: gen
            ("m%s=d%s", prop, prop);
            break; */ } } return gen ; }
Generates a partial value fromObject conveter.
@param {Codegen} gen Codegen instance
@param {Field} field Reflected field
@param {number} fieldIndex Field index
@param {string} prop Property reference
@return {Codegen} Codegen instance
@ignore
Generates a partial value fromObject conveter .