lib/converter.js
function genValuePartial_toObject(gen, field, fieldIndex, prop, map) {
  if (field.resolvedType) {
    if (field.resolvedType instanceof Enum) {
      if (map) {
        gen('d%s.set(k, o.enums===String?types[%i].values[m%s.get(k)]:m%s.get(k));', prop, fieldIndex, prop, prop);
      } else {
        gen('d%s=o.enums===String?types[%i].values[m%s]:m%s', prop, fieldIndex, prop, prop);
      }
    } else {
      if (map) {
        gen('d%s.set(k, types[%i].toObject(m%s.get(k),o));', prop, fieldIndex, prop);
      } else {
        gen('d%s=types[%i].toObject(m%s,o)', prop, fieldIndex, prop);
      }
    }
  } else {
    let isUnsigned = false;
    switch (field.type) {
      case 'double':
      case 'float':
        if (map) {
          gen('d%s.set(k, o.json&&!isFinite(m%s.get(k))?String(m%s.get(k)):m%s.get(k));', prop, prop, prop, prop);
        } else {
          gen('d%s=o.json&&!isFinite(m%s)?String(m%s):m%s;', prop, prop, prop, prop);
        }
        break;
      case 'uint64':
        isUnsigned = true;
        // eslint-disable-line no-fallthrough
      case 'int64':
      case 'sint64':
      case 'fixed64':
      case 'sfixed64':
        if (map) {
          gen('if(typeof m%s==="number"){', prop)('d%s.set(k, o.longs===String?String(m%s.get(k)):m%s.get(k));', prop, prop, prop)('} else {')('d%s.set(k, o.longs===String?util.Long.prototype.toString.call(m%s.get(k)):o.longs===Number?new util.LongBits(m%s.get(k).low>>>0,m%s.get(k).high>>>0).toNumber(%s):m%s.get(k));', prop, prop, prop, prop, isUnsigned ? 'true' : '', prop)('}');
        } else {
          gen('if(typeof m%s==="number"){', prop)('d%s=o.longs===String?String(m%s):m%s;', prop, prop, prop)('} else {')('d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s', prop, prop, prop, prop, isUnsigned ? 'true' : '', prop)('}');
        }
        break;
      case 'bytes':
        if (map) {
          gen('d%s.set(k, o.bytes===String?util.base64.encode(m%s.get(k),0,m%s.get(k).length):o.bytes===Array?Array.prototype.slice.call(m%s.get(k)):m%s.get(k));', prop, prop, prop, prop, prop);
        } else {
          gen('d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s', prop, prop, prop, prop, prop);
        }
        break;
      default:
        if (map) {
          gen('d%s.set(k, m%s.get(k));', prop, prop);
        } else {
          gen('d%s=m%s', prop, prop);
        }
        break;
    }
  }
  return gen;
}
function genValuePartial_toObject(gen, field, fieldIndex, prop, map) {
  if (field.resolvedType) {
    if (field.resolvedType instanceof Enum) {
      if (map) {
        gen('d%s.set(k, o.enums===String?types[%i].values[m%s.get(k)]:m%s.get(k));', prop, fieldIndex, prop, prop);
      } else {
        gen('d%s=o.enums===String?types[%i].values[m%s]:m%s', prop, fieldIndex, prop, prop);
      }
    } else {
      if (map) {
        gen('d%s.set(k, types[%i].toObject(m%s.get(k),o));', prop, fieldIndex, prop);
      } else {
        gen('d%s=types[%i].toObject(m%s,o)', prop, fieldIndex, prop);
      }
    }
  } else {
    let isUnsigned = false;
    switch (field.type) {
      case 'double':
      case 'float':
        if (map) {
          gen('d%s.set(k, o.json&&!isFinite(m%s.get(k))?String(m%s.get(k)):m%s.get(k));', prop, prop, prop, prop);
        } else {
          gen('d%s=o.json&&!isFinite(m%s)?String(m%s):m%s;', prop, prop, prop, prop);
        }
        break;
      case 'uint64':
        isUnsigned = true;
        // eslint-disable-line no-fallthrough
      case 'int64':
      case 'sint64':
      case 'fixed64':
      case 'sfixed64':
        if (map) {
          gen('if(typeof m%s==="number"){', prop)('d%s.set(k, o.longs===String?String(m%s.get(k)):m%s.get(k));', prop, prop, prop)('} else {')('d%s.set(k, o.longs===String?util.Long.prototype.toString.call(m%s.get(k)):o.longs===Number?new util.LongBits(m%s.get(k).low>>>0,m%s.get(k).high>>>0).toNumber(%s):m%s.get(k));', prop, prop, prop, prop, isUnsigned ? 'true' : '', prop)('}');
        } else {
          gen('if(typeof m%s==="number"){', prop)('d%s=o.longs===String?String(m%s):m%s;', prop, prop, prop)('} else {')('d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s', prop, prop, prop, prop, isUnsigned ? 'true' : '', prop)('}');
        }
        break;
      case 'bytes':
        if (map) {
          gen('d%s.set(k, o.bytes===String?util.base64.encode(m%s.get(k),0,m%s.get(k).length):o.bytes===Array?Array.prototype.slice.call(m%s.get(k)):m%s.get(k));', prop, prop, prop, prop, prop);
        } else {
          gen('d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s', prop, prop, prop, prop, prop);
        }
        break;
      default:
        if (map) {
          gen('d%s.set(k, m%s.get(k));', prop, prop);
        } else {
          gen('d%s=m%s', prop, prop);
        }
        break;
    }
  }
  return gen;
}
function genValuePartial_toObject ( gen , field , fieldIndex , prop , map ) { if ( field . resolvedType ) { if ( field . resolvedType instanceof Enum ) { if ( map ) { gen ( 'd%s.set(k, o.enums===String?types[%i].values[m%s.get(k)]:m%s.get(k));' , prop , fieldIndex , prop , prop ) ; } else { gen ( 'd%s=o.enums===String?types[%i].values[m%s]:m%s' , prop , fieldIndex , prop , prop ) ; } } else { if ( map ) { gen ( 'd%s.set(k, types[%i].toObject(m%s.get(k),o));' , prop , fieldIndex , prop ) ; } else { gen ( 'd%s=types[%i].toObject(m%s,o)' , prop , fieldIndex , prop ) ; } } } else { let isUnsigned = false ; switch ( field . type ) { case 'double' : case 'float' : if ( map ) { gen ( 'd%s.set(k, o.json&&!isFinite(m%s.get(k))?String(m%s.get(k)):m%s.get(k));' , prop , prop , prop , prop ) ; } else { gen ( 'd%s=o.json&&!isFinite(m%s)?String(m%s):m%s;' , prop , prop , prop , prop ) ; } break ; case 'uint64' : isUnsigned = true ; // eslint-disable-line no-fallthrough case 'int64' : case 'sint64' : case 'fixed64' : case 'sfixed64' : if ( map ) { gen ( 'if(typeof m%s==="number"){' , prop ) ( 'd%s.set(k, o.longs===String?String(m%s.get(k)):m%s.get(k));' , prop , prop , prop ) ( '} else {' ) ( 'd%s.set(k, o.longs===String?util.Long.prototype.toString.call(m%s.get(k)):o.longs===Number?new util.LongBits(m%s.get(k).low>>>0,m%s.get(k).high>>>0).toNumber(%s):m%s.get(k));' , prop , prop , prop , prop , isUnsigned ? 'true' : '' , prop ) ( '}' ) ; } else { gen ( 'if(typeof m%s==="number"){' , prop ) ( 'd%s=o.longs===String?String(m%s):m%s;' , prop , prop , prop ) ( '} else {' ) ( 'd%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s' , prop , prop , prop , prop , isUnsigned ? 'true' : '' , prop ) ( '}' ) ; } break ; case 'bytes' : if ( map ) { gen ( 'd%s.set(k, o.bytes===String?util.base64.encode(m%s.get(k),0,m%s.get(k).length):o.bytes===Array?Array.prototype.slice.call(m%s.get(k)):m%s.get(k));' , prop , prop , prop , prop , prop ) ; } else { gen ( 'd%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s' , prop , prop , prop , prop , prop ) ; } break ; default : if ( map ) { gen ( 'd%s.set(k, m%s.get(k));' , prop , prop ) ; } else { gen ( 'd%s=m%s' , prop , prop ) ; } break ; } } return gen ; }
Generates a partial value toObject converter.
@param {Codegen} gen Codegen instance
@param {Field} field Reflected field
@param {number} fieldIndex Field index
@param {string} prop Property reference
@param {bool} map whether is a map
@return {Codegen} Codegen instance
@ignore
Generates a partial value toObject converter .